GeoServer

From Wildsong
Jump to navigationJump to search

Overview

GeoServer is the Java based GIS web server that I am using with PostgreSQL and PostGIS for the Mapping Vietnam project

Home page: http://geoserver.org/

"GeoServer is a Java-based software server that allows users to view and edit geospatial data. Using open standards set forth by the Open Geospatial Consortium (OGC), GeoServer allows for great flexibility in map creation and data sharing."

The crucial feature is that it allows edits via WFS-T. Mapserver does not.

WFS-T comments: http://weblogs.java.net/blog/2006/01/09/geoserver-wfs-t

History

  • 2016 Sep -- updated Dart with 2.9.1 (latest stable release)
  • 2012 Sep -- 2.2 installed on Kilchis and Dart.
  • 2011 Oct -- I am working with 2.1.2 now on HuPI
  • 2009 Feb 06 -- I decided to take a crack at installing GeoServer 1.7.2 today.

Example GeoServer site

The Portland TriMet system map is on GeoServer via the OpenGeo stack.

This is from the Portland Trimet site... GeoServer, OpenLayers, TileCache, PostgreSQL, PostGIS, GDAL, Extjs, Freemarker, Solr, Antlr, Balance Ant, Http Client, Tomcat, Apache, and CentOS are the underlying technologies used on this application. We're indebted to the contributors of these (and many other: eclipse, firefox and firebug to name a few) open source projects for sharing their efforts and expertise.

Some GeoServer Capabilities

  • WCS = Web Coverage Service = queryable feature data (OGC)
  • WFS = Web Feature Service = vector data (OGC)
  • WMS = Web Map Service = delivers rasters (not tiles) (OGC)
  • TMS = Tile map service = delivers raster tiles (OSGEO)
  • WMS-C = Web Map Service - Cached = WMS with tile caching (OSGEO draft)
  • WMTS = Web Map Tile service (OGC)

I think WCS can return features that are related from several feature classes whereas WFS returns features from one class only??

Map vs feature services

What if you want features to overlay a map but want symbology defined by the server? You define styles and then pick the correct encoding.

With WFS there are several GML flavours, GeoJSON, shapefiles and CSV. None of these work for me because they only encode the geography and not the visual properties. I probably want to use a WMS encoded with KML.

Lew's approach is to convert the KML into a custom JSON format on the server for transfer. There must be a better way than that. But it has to be compatible with the Google Maps Android API too.

The official way to put markers and shapes onto a Google map is via their API. I don't want to go the route of putting shapes onto the screen ignoring the API because I hate having to do all the projection and transformation stuff on my own.

Being able to directly read GPX files would be a good thing.

Tiles

If you are implementing a tile-based client you should probably use TMS or maybe WMTS. WMS-C was a OSGEO draft. WMTS is more complex so use TMS unless you really need WMTS features.

On the server side for performance and the best cartography you'd probably be better off pre-rendering and caching all the tiles. What's the best way to do that? Tilemill or gdal2tiles ? What's the best way to serve the prerendered tiles? TileCache? Or just use a web server (Apache)?

TMS reference implementation: see http://TileCache.org/

Status

I have gotten data loaded into PostGIS and published it in GeoServer.

Then I need to add the new layer into the map.

Setting up GeoServer

The downloadable binary for Linux includes jetty; this precludes the need for Tomcat. Indeed this is great for testing on a desktop but for any server application, I find that geoserver/java will eat ram and crash after a few days.

So I install Tomcat and expand the settings to give it lots of space.

Tomcat 8

I used to install Oracle manually (direct tarball download) and then was forced to install Tomcat from source, too. Otherwise doing "apt-get install tomcat7" got me an apt packaged outdated java.

Now I first set up the Oracle repo for Java and install it first so that everything can load from apt.

Fix for Debian 8.5, to get the add-apt-repository command (which is an Ubuntu thing)

cd /tmp
wget http://blog.anantshri.info/content/uploads/2010/09/add-apt-repository.sh.txt
mv add-apt-repository.sh.txt /usr/local/sbin
chmod 755 /usr/local/sbin/add-apt-repository

Now I can install Oracle version 8 JDK as an apt package.

apt-get install python-software-properties
add-apt-repository ppa:webupd8team/java
apt-get update
apt-get install oracle-java8-installer

Now since I have Oracle java installed as a package, I can install the tomcat8 package and it won't try to install whatever open sourced java it ordinarily installs. It will be happy to use Oracle's version.

Startup of tomcat fails at this point because JAVA_HOME is not set. They still use the old /etc/init.d /etc/default startup files, so I put my custom settings at the end of /etc/default/tomcat8:

JAVA_HOME="/usr/lib/jvm/java-8-oracle"
GEOCEG_HOME="/home/geoceg"
GEOSERVER_HOME="$GEOCEG_HOME/geoserver"
JAVA_OPTS="-Djava.awt.headless=true -Xmx768m -Xrs -XX:PerfDataSamplingInterval=500 \          
 -XX:MaxPermSize=256m -Dorg.geotools.referencing.forceXY=true \                                       
 -DGEOSERVER_DATA_DIR=$GEOCEG_HOME/geoserver/data \                                                   
 -DGEOWEBCACHE_DATA_DIR=$GEOCEG_HOME/geowebcache \                                                    
 -DGEOEXPLORER_DATA=$GEOCEG_HOME/geoexplorer \                                                        
 "

Then start it up, fix any problems, try try again

systemctl start tomcat8

At this point there should be a servlet container running at http://dart.wildsong.biz:8080/

How big is my heap now?

java -XX:+PrintFlagsFinal -version 2>&1 | grep -i MaxHeapSize

Geoserver 2.9.1

Download stable release of the WAR file from http://geoserver.org/ -- Today that would be here:

cd ~/Downloads
wget http://downloads.sourceforge.net/project/geoserver/GeoServer/2.9.1/geoserver-2.9.1-war.zip?r=http%3A%2F%2Fgeoserver.org%2Frelease%2F2.9.1%2F&ts=1473614756&use_mirror=superb-sea2
unzip geoserver*

Based on the settings I used in /etc/default/tomcat8 above I need to install the WAR file at /var/lib/tomcat8/webapps/ and the rest of the files go in /home/geoceg Create the folders first, when you move the WAR file it will be deployed automatically and start searching for the folders.

mkdir /home/geoceg
chdir /home/geoceg
mkdir -p geoexplorer geowebcache geoserver/data
chown -R tomcat8.wildsong /home/geoceg/*
mv geoserver.war /var/lib/tomcat8/webapps
chown root.root /var/lib/tomcat8/webapps/geoserver.war

systemctl restart tomcat8

If deployment succeeds then some files will be created in /home/geoceg/geoserver for you, and you should be able to see an empty geoserver at http://dart.wildsong.biz:8080/geoserver/

As you work on getting everything correct, the log file /var/lib/tomcat8/logging/catalina.out will be most helpful.

Geoserver 2.2

Setting up Geoserver is very easy, download the files and put them in the webapps directory. Use the Tomcat manager page to start it.

cd /usr/local/java/tomcat/webapps
wget http://downloads.sourceforge.net/geoserver/geoserver-2.2-war.zip
unzip geoserver-2.2-war.zip

Once it is there, Tomcat will notice it and start it up. Once started you can access it here

http://bellman:8080/geoserver/

Change admin password now.

You have to look up the one that was created for you when geoserver.war ran the first time. It is in geoserver/data/security/masterpw.info Login as root in the browser and change it now.

This is new in 2.2, in 2.1 there was a default password and you had to edit a file to change it.

Next I have to set up my own workspace to serve my PostGIS data.

Need to fix

/opt/apache/tomcat/webapps/geoserver/data/gwc-layers

INFO: The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: /usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib

Connecting GeoServer to PostGIS

Some notes on using WFS-T http://blogs.law.harvard.edu/jreyes/2007/08/03/geotools-wfs-t-update-request/

GeoServer has

  • workspaces aka namespaces
  • stores aka datastores
  • layers

These are about organizing the data accessible to GeoServer.

You store data in stores and a store has to be in a workspace. A PostGIS store connects to a database, and the tables therein become accessible as layers (once you publish them)

So you can create a workspace for Oregon and then put all your state-level data into stores that are in the Oregon workspace.

To create a connection to data in your PostGIS server you have to know what's in there. You can poke around with psql if you are text kind of guy or you can use pgAdmin III, like so: