Skip to content

Setting Up GeoServer for OTM

kpruhs edited this page Apr 3, 2013 · 9 revisions

#Install GeoServer for OpenTreeMap

I'm assuming that you have followed the installation guide "Install Process on Ubuntu 12.04".

##Install Tomcat7:

sudo apt-get install tomcat7

##Install GeoServer:

Download theGeoServer WAR file (http://geoserver.org/display/GEOS/Stable). That was the easiest way to get it working.

Unzip the archive and copy the .war file to /var/lib/tomcat7/webapps/. That's it. No kiddin'. You can check out the web interface in your browser by going to 'localhost:8080/geoserver/web. The default username is "admin" and the password is "geoserver". Check out the GeoServer user manual for more configuration info (http://docs.geoserver.org/stable/en/user/).

###Setup an external data folder for GeoServer:

I chose to move the data folder out of the main GeoServer directory because I have installed, wiped and reinstalled server configurations a few times, and lost my data. Also, this is recommended on the GeoServer website, to avoid blowing away your data if you choose to install a GeoServer update. I used the WAR file installation method so the data directory is located at:

/var/lib/tomcat7/webapps/geoserver/data/

I moved it to:

/var/lib/geoserver_data/

  1. Create your new directory and give Tomcat7 ownership of it:

sudo mkdir /var/lib/geoserver_data

sudo chown tomcat7:tomcat7 /var/lib/geoserver_data

  1. Modify the web.xml file in /var/lib/tomcat7/webapps/geoserver/WEB-INF/at about line 50 look for the GEOSERVER_DATA_DIR parameter declaration. It will be commented out. Uncomment the block and enter the new directory path between the param-value tags.

    <context-param>
        <param-name>GEOSERVER_DATA_DIR</param-name>
        <param-value>/var/lib/geoserver_data</param-value>
    </context-param>
    

There are instructions and other options at the following link:

http://docs.geoserver.org/latest/en/user/datadirectory/index.html

###Change Tomcat port to 8081:

Edit the /etc/tomcat7/server.xml file. At about line 72 change:

<Connector port="8080" protocol="HTTP/1.1"

to:

<Connector port="8081" protocol="HTTP/1.1"

##Data for GeoServer and Map Overlays:

###Shape files:

GeoServer needs to have data to render the various boundaries of your geographic area as overlays for a Bing or Google map. I am working on the state of Utah so I got some students in the geography/cartography/geo-location fields here, at Utah State University to prepare a set of shape files for import into the OTM treemap_neighborhood table. They generated a municipalities file, with all the cities, a counties file, and a file with the state boundary. The real work they did was converting existing data into a format that was most common for all the parts of OTM to use. EPSG:4326 seemed to be the most commonly mentioned format on the websites I researched. The “shape files” actually consist of a set of files; .dbf, .shp, .prj, .sbx, .shx, and maybe others. You may not have all of these. My understanding is, the most important for OTM use are the .dbf files and maybe the .shp file, but not required if you upload the data to the treemap_neighborhood table (GeoServer can render layers from .shp files if you don’t put the data in the database).

###Create your database:

I’m assuming most of us have already done this as part of the basic installation instructions. The part that is most important, relating to GeoServer is the template_postgis .

    sudo -u postgres createdb -T template_postgis YOUROTMDATABASENAMEHERE

###Add shape file data to your database:

I didn’t try to get the data from the shape file(s) directly into the treemap_neighborhood table. I took it in a few steps. 1) Create the .sql files. 2) Create new tables in my OTM database with the .sql files. 3) Move columns from new tables into the treemap_neighborhood table as needed.

  1. Create your .sql files from the shape .dbf files:

    shp2pgsql -s 4326 YOURFILENAMEHERE > YOURFILENAMEHERE.sql
    
  2. Insert your .sql file data into a new table:

    sudo -u postgres psql YOUROTMDATABASENAMEHERE -f YOURFILENAMEHERE.sql
    
  3. There are a few things to keep in mind:

a) You're going to need a little SQL to move data around. Not much just basic INSERT, SELECT, SET, etc. Familiarity with Postgres and pgAdmin3 will make this go faster.

b) All fields in the treemap_neighborhood table are required and cannot have null values. The “character variable” data type (or varchar for the MySQL fans out there) fields can, however, have '' or ' ' as a value.

c) You need a region number for the treemap_neighborhood table. I found a Wikipedia page that seems to have good info. Honestly, I guessed which region to use. I just needed an integer to get started. I’ll verify it later. If you aren't geo-savy, like me, this seems like a good place to start… I think…

[http://en.wikipedia.org/wiki/List_of_regions_of_the_United_States - Official_regions_of_the_United_States](http://en.wikipedia.org/wiki/List_of_regions_of_the_United_States - Official_regions_of_the_United_States).

d) Insert the data from the new tables you just created into the treemap_neighborhood table in order from smallest geographic areas to largest--meaning, start with neighborhoods, if their boundaries are contained within cities. Next insert your cities, then counties, then state boundaries, if your area is that large. See the following link for another explanation:

[https://github.com/azavea/OpenTreeMap/wiki/External-Data - geographic-regions-neighborhoods](https://github.com/azavea/OpenTreeMap/wiki/External-Data - geographic-regions-neighborhoods).

e) The treemap_neighborhood table becomes a layer rendered by GeoServer and a reference to it gets added to your local settings file as GEOSERVER_GEO_LAYER. More about that in the next section.

##The GeoServer tree_search Layer:

###Create the tree_search view:

The first step is to create a Postgres view in your OTM database. Look for a file called create_search_views.sql in scripts/db/ directory. If you don't have it copy it from the following link: https://github.com/azavea/OpenTreeMap/blob/v1.3/scripts/db/create_search_view.sql .

The easiest way to run scripts for Postgres is in the SAL window of pgAdmin3. I highly recommend installing it and using it for this script. When you run it, you may get an error related to treemap_tree.pests. It's looking for a column called pests in the treemap_tree table and can't find it. I chose to edit the script and remove the reference to the pests column. That might not be the best solution if you want/need the pest column, but it solves the immediate problem. Next I will show how to add tree_search and other tables in your database to GeoServer as a layer.

##Add Layers to GeoServer Using Your Database:

###Create a GeoServer workspace, store, layer, and layer group:

###Create the tree_search GeoServer layer: