Skip to content

Instantly share code, notes, and snippets.

@vesse
Last active January 24, 2017 18:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vesse/dfc7c5b132b042283aea8d60228d732f to your computer and use it in GitHub Desktop.
Save vesse/dfc7c5b132b042283aea8d60228d732f to your computer and use it in GitHub Desktop.
GeoServer test setup

US Counties on GeoServer

Just a test and a note to self.

Data

wget http://www2.census.gov/geo/tiger/GENZ2015/kml/cb_2015_us_county_500k.zip
unzip cb_2015_us_county_500k.zip

Setup DB

sudo su - postgres -c "createuser states -PE"
sudo su - postgres -c "createdb -O states states"
sudo su - postgres -c "echo CREATE extension IF NOT EXISTS postgis|psql states"

Password kissa expected from now on

Import to PostGIS

PG_USE_COPY=YES PGPASSWORD=kissa ogr2ogr \
  -f "PostgreSQL" \
  PG:"host=localhost user=states dbname=states" \
  -a_srs "EPSG:3395" \
  -append \
  -nlt MULTIPOLYGON \
  -nln counties cb_2015_us_county_500k.kml

GeoServer

wget -Ogeoserver-2.10.1-bin.zip "https://downloads.sourceforge.net/project/geoserver/GeoServer/2.10.1/geoserver-2.10.1-bin.zip?r=http%3A%2F%2Fgeoserver.org%2Frelease%2Fstable%2F&ts=1485280136&use_mirror=freefr"
unzip geoserver-2.10.1-bin.zip
GEOSERVER_HOME="$(pwd)/geoserver-2.10.1" geoserver-2.10.1/bin/startup.sh

Setup

# Create workspace
curl -v -X POST \
  -H "Content-Type: text/xml" \
  -u admin:geoserver \
  -d "<workspace><name>counties</name></workspace>" \
  http://localhost:8080/geoserver/rest/workspaces

# Add data store
curl -v -X POST \
  -H "Content-Type: text/xml" \
  -u admin:geoserver \
  -d "<dataStore><name>states</name><connectionParameters><host>localhost</host><port>5432</port><database>states</database><user>states</user><passwd>kissa</passwd><dbtype>postgis</dbtype></connectionParameters></dataStore>" \
  http://localhost:8080/geoserver/rest/workspaces/counties/datastores

# Add table from the store as feature type
curl -v -X POST \
  -H "Content-Type: text/xml" \
  -u admin:geoserver \
  -d "<featureType><name>counties</name></featureType>" \
  http://localhost:8080/geoserver/rest/workspaces/counties/datastores/states/featuretypes

Test

  • Go to http://localhost:8080/geoserver
  • Login with: admin / geoserver
  • Select Layer Preview
  • You should see layer counties. From that row, click OpenLayers link
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment