-
-
Save cassioeskelsen/3949361 to your computer and use it in GitHub Desktop.
Importing SHPs of Windows 1252 into UTF PostGIS using ORG's PostGIS driver (not shp2pgsql)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# loop through all of the shapefiles in the directory and act on them | |
# http://trac.osgeo.org/gdal/wiki/FAQVector#HowcanImergehundredsofShapefiles | |
# http://stackoverflow.com/questions/965053/extract-filename-and-extension-in-bash | |
# !IMPORTANT: OGR 1.9 for direct to PostGIS support, linestring-multilinestring, and character encoding support. | |
if [ $# -ne 1 ]; then | |
echo "USAGE: ./import.sh <in_dir_path>" | |
exit 1 | |
fi | |
#Capture the shell arguments | |
in_dir_of_shps=$1 | |
#Loop thru all the shps in the input dir | |
for i in $(ls ${in_dir_of_shps}/*.shp); do | |
#echo ${i} | |
#Capture each filename | |
filename=$(basename "$i") | |
filebase="${filename%%.*}" | |
#filename="${filename%.*}" | |
#note: the shp2pgsql route results in errors | |
#shp2pgsql -dID -W "Windows-1252" -s 900913 ${i} ${filebase} | psql -U smugmug | |
#note: if you haven't clipped your data yet, add this snippet below | |
#-clipsrc -180 -85.05112878 180 85.05112878 \ | |
#tip: prefix with `echo ` for testing! | |
ogr2ogr -t_srs EPSG:900913 -f PostgreSQL \ | |
-overwrite \ | |
-lco GEOMETRY_NAME=geometry -lco ENCODING="Windows 1252" \ | |
-nlt MULTILINESTRING \ | |
-nln ${filebase} \ | |
PG:"dbname='smugmug' user='smugmug'" \ | |
${i} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment