GeoServer: Difference between revisions

From Wildsong
Jump to navigationJump to search
Brian Wilson (talk | contribs)
Brian Wilson (talk | contribs)
Line 33: Line 33:
I think WCS can return features that are related from several feature classes whereas WFS returns features from one class only??
I think WCS can return features that are related from several feature classes whereas WFS returns features from one class only??


=== Features ===
=== Feature services ===


What if you want features to overlay a map but want symbology defined by the server?
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 service based on 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.


=== Tiles ===
=== Tiles ===

Revision as of 22:31, 24 December 2012

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/

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.

"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

Sample 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 Cent OS 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.

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??

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 service based on 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.

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 installed GeoServer 2.1.2 on HuPI.org, using the WAR file and Tomcat 7. It's running on the Oracle Java JRE. I had to upgrade my virtual machine account because 512M was not enough to run it. At work I have 2.2 running.

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

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

The Apache server and raster tiles will remain at Hupi.

Setting up GeoServer

I found instructions in the PostGIS book. Page 324- As mentioned above I currently use the WAR file method.

Tomcat 7

I removed OpenJDK (which is purported to be suboptimal for use with GeoServer) and installed Oracle JDK 7. You only need JRE not JDK for Tomcat now, but I needed JDK for ESRI MDB support in GDAL.

Removing the OpenJDK also removed about 400 pounds of other packages, including Tomcat 6. This is okay really, since Tomcat 7 is the latest release anyway.

Download Tomcat 7 in binary form and unpack it where it will live.

cd /tmp
wget http://mirror.uoregon.edu/apache/tomcat/tomcat-7/v7.0.23/bin/apache-tomcat-7.0.23.tar.gz
sudo mkdir /usr/local/java
cd /usr/local/java
sudo tar xzvf /tmp/apache-tomcat-7.0.23.tar.gz
ln -s apache-tomcat-7.0.23 tomcat7
cd tomcat7
Note -- fix the users and passwords up in conf/tomcat-users.xml
chown -R tomcat.tomcat temp work logs webapps
chgrp -R tomcat conf
chmod 750 conf
chmod g+w conf/*
su - tomcat
sh bin/startup.sh

Now try to connect to your server on port 8080, eg http://bellman:8080/ Do bin/shutdown.sh and finish configuration. How big is my heap? I can see on Hupi it's not enough for Geoserver!

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

This shows 256M, but in the tomcat startup file it's set to 128M.

I create a /etc/default/tomcat file containing

# Brian cooked up this file from the original written for tomcat6             

TOMCAT_GROUP=tomcat
TOMCAT_USER=tomcat

# 2011-Nov-01 bwilson --Geoserver is hungry for more RAM!!!                   
JAVA_OPTS="-Djava.awt.headless=true -Xmx512m -XX:+UseConcMarkSweepGC"
JAVA_HOME="/usr/local/java/jre1.6.0_29"
JVM_TMP=/tmp/tomcat7-temp

I make a startup file in /etc/init.d based on an existing one.

#!/bin/sh
#
# /etc/init.d/tomcat7 -- startup script for the Tomcat servlet engine
#
# Brian hacked this version to run Tomcat 7
#
# Written by Miquel van Smoorenburg <[email protected]>.
# Modified for Debian GNU/Linux	by Ian Murdock <[email protected]>.
# Modified for Tomcat by Stefan Gybas <[email protected]>.
# Modified for Tomcat6 by Thierry Carrez <[email protected]>.
# Additional improvements by Jason Brittain <[email protected]>.
#
### BEGIN INIT INFO
# Provides:          tomcat7
# Required-Start:    $local_fs $remote_fs $network
# Required-Stop:     $local_fs $remote_fs $network
# Should-Start:      $named
# Should-Stop:       $named
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start Tomcat.
# Description:       Start the Tomcat servlet engine.
### END INIT INFO

set -e

PATH=/bin:/usr/bin:/sbin:/usr/sbin
NAME=tomcat
DESC="Tomcat servlet engine"
DEFAULT=/etc/default/$NAME
JVM_TMP=/tmp/tomcat-temp

if [ `id -u` -ne 0 ]; then
	echo "You need root privileges to run this script"
	exit 1
fi
 
# Make sure tomcat is started with system locale
if [ -r /etc/default/locale ]; then
	. /etc/default/locale
	export LANG
fi

. /lib/lsb/init-functions

if [ -r /etc/default/rcS ]; then
	. /etc/default/rcS
fi


# The following variables can be overwritten in $DEFAULT

# Run Tomcat as this user ID and group ID
TOMCAT_USER=tomcat
TOMCAT_GROUP=tomcat

# The first existing directory is used for JAVA_HOME (if JAVA_HOME is not
# defined in $DEFAULT or in the environment)
#JDK_DIRS="/usr/lib/jvm/java-6-openjdk /usr/lib/jvm/java-6-sun /usr/lib/jvm/java-1.5.0-sun /usr/lib/j2sdk1.5-sun /usr/lib/j2sdk1.5-ibm"

# Look for the right JVM to use
#for jdir in $JDK_DIRS; do
#    if [ -r "$jdir/bin/java" -a -z "${JAVA_HOME}" ]; then
#	JAVA_HOME="$jdir"
#    fi
#done

# Directory where the Tomcat binary distribution resides
CATALINA_HOME=/usr/local/$NAME

# Directory for per-instance configuration files and webapps
# This would be in /var/lib/tomcat6 if this were a Debian package
CATALINA_BASE=/usr/local/$NAME

# Use the Java security manager? (yes/no)
TOMCAT_SECURITY=no

# Default Java options
# Set java.awt.headless=true if JAVA_OPTS is not set so the
# Xalan XSL transformer can work without X11 display on JDK 1.4+
# It also looks like the default heap size of 64M is not enough for most cases
# so the maximum heap size is set to 128M
if [ -z "$JAVA_OPTS" ]; then
	JAVA_OPTS="-Djava.awt.headless=true -Xmx128M"
fi

# End of variables that can be overwritten in $DEFAULT

# overwrite settings from default file
if [ -f "$DEFAULT" ]; then
	. "$DEFAULT"
fi
export JAVA_HOME

if [ ! -f "$CATALINA_HOME/bin/bootstrap.jar" ]; then
	log_failure_msg "$NAME is not installed"
	exit 1
fi

POLICY_CACHE="$CATALINA_BASE/work/catalina.policy"

if [ -z "$CATALINA_TMPDIR" ]; then
	CATALINA_TMPDIR="$JVM_TMP"
fi

# Set the JSP compiler if set in the tomcat6.default file
if [ -n "$JSP_COMPILER" ]; then
	JAVA_OPTS="$JAVA_OPTS -Dbuild.compiler=\"$JSP_COMPILER\""
fi

SECURITY=""
if [ "$TOMCAT_SECURITY" = "yes" ]; then
	SECURITY="-security"
fi

# Define other required variables
CATALINA_PID="/var/run/$NAME.pid"
CATALINA_SH="$CATALINA_HOME/bin/catalina.sh"

# Look for Java Secure Sockets Extension (JSSE) JARs
if [ -z "${JSSE_HOME}" -a -r "${JAVA_HOME}/jre/lib/jsse.jar" ]; then
    JSSE_HOME="${JAVA_HOME}/jre/"
fi

catalina_sh() {
	# Escape any double quotes in the value of JAVA_OPTS
	JAVA_OPTS="$(echo $JAVA_OPTS | sed 's/\"/\\\"/g')"

	AUTHBIND_COMMAND=""
	if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
		JAVA_OPTS="$JAVA_OPTS -Djava.net.preferIPv4Stack=true"
		AUTHBIND_COMMAND="/usr/bin/authbind --deep /bin/bash -c "
	fi

	# Define the command to run Tomcat's catalina.sh as a daemon
	# set -a tells sh to export assigned variables to spawned shells.
	TOMCAT_SH="set -a; JAVA_HOME=\"$JAVA_HOME\"; source \"$DEFAULT\"; \
		CATALINA_HOME=\"$CATALINA_HOME\"; \
		CATALINA_BASE=\"$CATALINA_BASE\"; \
		JAVA_OPTS=\"$JAVA_OPTS\"; \
		CATALINA_PID=\"$CATALINA_PID\"; \
		CATALINA_TMPDIR=\"$CATALINA_TMPDIR\"; \
		LANG=\"$LANG\"; JSSE_HOME=\"$JSSE_HOME\"; \
		cd \"$CATALINA_BASE\"; \
		\"$CATALINA_SH\" $@"

	if [ "$AUTHBIND" = "yes" -a "$1" = "start" ]; then
		TOMCAT_SH="'$TOMCAT_SH'"
	fi

	# Run the catalina.sh script as a daemon
	set +e
	touch "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
	chown $TOMCAT_USER "$CATALINA_PID" "$CATALINA_BASE"/logs/catalina.out
	start-stop-daemon --start -b -u "$TOMCAT_USER" -g "$TOMCAT_GROUP" \
		-c "$TOMCAT_USER" -d "$CATALINA_TMPDIR" -p "$CATALINA_PID" \
		-x /bin/bash -- -c "$AUTHBIND_COMMAND $TOMCAT_SH"
	status="$?"
	set +a -e
	return $status
}

case "$1" in
  start)
	if [ -z "$JAVA_HOME" ]; then
		log_failure_msg "no JDK found - please set JAVA_HOME"
		exit 1
	fi

	if [ ! -d "$CATALINA_BASE/conf" ]; then
		log_failure_msg "invalid CATALINA_BASE: $CATALINA_BASE"
		exit 1
	fi

	log_daemon_msg "Starting $DESC" "$NAME"
	if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
		--user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \
		>/dev/null; then
		# Regenerate POLICY_CACHE file
		umask 022
		echo "// AUTO-GENERATED FILE from $CATALINA_BASE/conf/policy.d/" > "$POLICY_CACHE"
		echo ""  >> "$POLICY_CACHE"
		cat $CATALINA_BASE/conf/policy.d/*.policy \
			>> "$POLICY_CACHE"

		# Remove / recreate JVM_TMP directory
		rm -rf "$JVM_TMP"
		mkdir -p "$JVM_TMP" || {
			log_failure_msg "could not create JVM temporary directory"
			exit 1
		}
		chown $TOMCAT_USER "$JVM_TMP"

		catalina_sh start $SECURITY
		sleep 5
        	if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
			--user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \
			>/dev/null; then
			if [ -f "$CATALINA_PID" ]; then
				rm -f "$CATALINA_PID"
			fi
			log_end_msg 1
		else
			log_end_msg 0
		fi
	else
	        log_progress_msg "(already running)"
		log_end_msg 0
	fi
	;;
  stop)
	log_daemon_msg "Stopping $DESC" "$NAME"

	set +e
	if [ -f "$CATALINA_PID" ]; then 
		start-stop-daemon --stop --pidfile "$CATALINA_PID" \
			--user "$TOMCAT_USER" \
			--retry=TERM/20/KILL/5 >/dev/null
		if [ $? -eq 1 ]; then
			log_progress_msg "$DESC is not running but pid file exists, cleaning up"
		elif [ $? -eq 3 ]; then
			PID="`cat $CATALINA_PID`"
			log_failure_msg "Failed to stop $NAME (pid $PID)"
			exit 1
		fi
		rm -f "$CATALINA_PID"
		rm -rf "$JVM_TMP"
	else
		log_progress_msg "(not running)"
	fi
	log_end_msg 0
	set -e
	;;
   status)
	set +e
	start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
		--user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \
		>/dev/null 2>&1
	if [ "$?" = "0" ]; then

		if [ -f "$CATALINA_PID" ]; then
		    log_success_msg "$DESC is not running, but pid file exists."
			exit 1
		else
		    log_success_msg "$DESC is not running."
			exit 3
		fi
	else
		log_success_msg "$DESC is running with pid `cat $CATALINA_PID`"
	fi
	set -e
        ;;
  restart|force-reload)
	if [ -f "$CATALINA_PID" ]; then
		$0 stop
		sleep 1
	fi
	$0 start
	;;
  try-restart)
        if start-stop-daemon --test --start --pidfile "$CATALINA_PID" \
		--user $TOMCAT_USER --exec "$JAVA_HOME/bin/java" \
		>/dev/null; then
		$0 start
	fi
        ;;
  *)
	log_success_msg "Usage: $0 {start|stop|restart|try-restart|force-reload|status}"
	exit 1
	;;
esac

exit 0


Once you have Tomcat running you can move on to getting Geoserver set up.

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: