Skip to content

Instantly share code, notes, and snippets.

@maning
Forked from walkermatt/wfs2postgis.sh
Created September 27, 2012 01:28
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 maning/3791668 to your computer and use it in GitHub Desktop.
Save maning/3791668 to your computer and use it in GitHub Desktop.
WFS to PostGIS
# Example of downloading all data from a GeoServer WFS server
# and loading it into a PostGIS database. Use with caution
# as you could put a lot of load on someone's server if they
# host a lot of data which might make them sad.
# In response to: http://underdark.wordpress.com/2012/09/26/wfs-to-postgis-in-3-steps/
BASEURL="http://data.wien.gv.at/daten/geoserver/ows?service=WFS&version=1.1.0"
for LAYERNAME in `wget -qO- $BASEURL"&request=GetCapabilities" | xpath -q -e "//FeatureType/Name/text()"` ; do
PARTS=(${LAYERNAME//:/ })
FILENAME=${PARTS[1]}
wget $BASEURL"&request=GetFeature&typeName="$LAYERNAME"&srsName=EPSG:4326&outputFormat=shape-zip" -O $FILENAME".zip"
mkdir /tmp/$FILENAME
unzip -d /tmp/$FILENAME $FILENAME".zip"
shp2pgsql -s 4326 -I -S -c -W LATIN1 "/tmp/"$FILENAME"/"$FILENAME".shp" $FILENAME | psql postgis
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment