Last active
October 28, 2016 13:25
-
-
Save bmcbride/f1c652c6480ef04da60e to your computer and use it in GitHub Desktop.
Bash script that uses GDAL/OGR to convert PDF Maps exported KML or KMZ Placemarks, Tracks, and Lines to shapefiles. Modify as needed for additional formats or custom attributes.
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 | |
echo "File type (kmz or kml):" | |
read TYPE | |
echo "Enter the filename (without the .kmz or .kml extension) to process:" | |
read FILENAME | |
# Unzip KMZ file | |
if [[ $TYPE = "kmz" ]]; then | |
Unzip "$FILENAME.kmz" | |
fi | |
# Create SQLite database | |
ogr2ogr -f "SQLite" -overwrite "$FILENAME.sqlite" "$FILENAME.kml" -lco LAUNDER=NO | |
# Create Shapefiles (add custom attributes between Desc, and substr) | |
ogr2ogr -a_srs "EPSG:4326" -overwrite -sql "SELECT geometry, Name AS Name, description AS Descrip, substr(replace(replace(replace(pdfmaps_photos, '<img src=\"', ''), '\" /><br />', ''), 'images/', ', '), 3) AS Photos, datetime(timestamp) AS Timestamp FROM placemarks" "placemarks.shp" "$FILENAME.sqlite" | |
ogr2ogr -a_srs "EPSG:4326" -overwrite -sql "SELECT geometry, Name AS Name, description AS Descrip, substr(replace(replace(replace(pdfmaps_photos, '<img src=\"', ''), '\" /><br />', ''), 'images/', ', '), 3) AS Photos, datetime(timestamp) AS Timestamp FROM tracks" "tracks.shp" "$FILENAME.sqlite" | |
ogr2ogr -a_srs "EPSG:4326" -overwrite -sql "SELECT geometry, Name AS Name, description AS Descrip, substr(replace(replace(replace(pdfmaps_photos, '<img src=\"', ''), '\" /><br />', ''), 'images/', ', '), 3) AS Photos, datetime(timestamp) AS Timestamp FROM lines" "lines.shp" "$FILENAME.sqlite" | |
# Remove intermediate SQLite file | |
rm $FILENAME.sqlite |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment