Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@tepepa

This comment has been minimized.

Copy link

tepepa commented Sep 15, 2014

What if the WFS service needs for an HTTP Authentication?
Is there any option to manage this case?

Thank you

@ManuelB

This comment has been minimized.

Copy link

ManuelB commented Oct 22, 2016

@tepepa you can add username and password to the wget command:

wget $BASEURL"&request=GetFeature&typeName="$LAYERNAME"&srsName=EPSG:4326&outputFormat=shape-zip" -O $FILENAME".zip" --user=username --password=password

http://www.gnu.org/software/wget/manual/wget.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.