Skip to content

Setting Up GeoServer for OTM

kpruhs edited this page Apr 3, 2013 · 9 revisions

#Install GeoServer for OpenTreeMap

##Install Tomcat7:

sudo apt-get install tomcat7

###Setup an external data folder for Tomcat7:

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"

###The 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.