Skip to content

Instantly share code, notes, and snippets.

@joakimsk
Created March 18, 2018 14:22
Show Gist options
  • Save joakimsk/3dd9091dfe77a8dd8ac534c3fc249f03 to your computer and use it in GitHub Desktop.
Save joakimsk/3dd9091dfe77a8dd8ac534c3fc249f03 to your computer and use it in GitHub Desktop.
Upload DXF to Postgis database, and add filename to field mapfile
#!/bin/bash
# sh-upload.sh
# -i input DXF file
#
#
# To execute in batch mode:
# find . -type d \( -name "MERGE*" -o -name "Extra" -o -name "RESOLVE*" -o -name "SEPARATE*" \) -prune -o -iname "*.dxf" -print0 | xargs -0 -I {} ./sh-upload.sh -i "{}"
#
# By Joakim Skjefstad
while getopts ":i:" opt; do
case $opt in
i)
echo "-i was triggered, Parameter: $OPTARG" >&2
FILENAME=${OPTARG##*/}
PATHNAME=`dirname "$OPTARG"`
FILE=${FILENAME%.*}
echo "Working on $PATHNAME/$FILENAME"
ogr2ogr --config CPL_DEBUG ON -f "PostgreSQL" PG:"dbname=mapDatabase user=postgres" "$OPTARG" -dim XY -dialect SQLITE -sql "SELECT *, '$FILE' AS Mapfile FROM entities e WHERE ST_GeometryType(e.geometry) IN ('POINT', 'POINT Z', 'LINESTRING', 'LINESTRING Z', 'MULTILINESTRING', 'MULTILINESTRING Z', 'POLYGON', 'POLYGON Z', 'MULTIPOLYGON', 'MULTIPOLYGON Z');" -nln 'dxfworld' -append
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment