Skip to content

Instantly share code, notes, and snippets.

@laacz
Last active January 1, 2022 18:42
Show Gist options
  • Save laacz/8dfb7b69221790eb8d88e5fb91b9b088 to your computer and use it in GitHub Desktop.
Save laacz/8dfb7b69221790eb8d88e5fb91b9b088 to your computer and use it in GitHub Desktop.
Kadastrs shapefiles import into PostGIS
#!/usr/bin/env bash
# Download all your data from https://data.gov.lv/dati/lv/dataset/kadastra-informacijas-sistemas-atverti-telpiskie-dati
# Script does the following:
# 1. Creates a single shapefile with all the layers
# 2. Imports all the layers into PostGIS
APPEND=0
LAYERS="KKCadastralGroup KKBuilding KKEngineeringStructurePoly KKParcel KKParcelBorderPoint KKParcelError KKParcelPart KKSurveyingStatus KKWayRestriction"
DB=vzd
for type in $LAYERS; do
APPEND=0
rm "kadastrs/$LAYERS*";
target_file="kadastrs/$type.shp"
target_layer=$(echo "$type" | tr '[:upper:]' '[:lower:]')
for file in kadastrs/**/"$type".shp; do
if [ "$APPEND" == 0 ]; then
echo -n "Create $target_file "
ogr2ogr -f 'ESRI Shapefile' "$target_file" "$file" -lco ENCODING=UTF-8
APPEND=1
else
echo -n "Update $target_file "
ogr2ogr -f 'ESRI Shapefile' -update -append "$target_file" "$file" -nln "$target_layer"
fi
echo "(${target_file%.shp}; $file)"
done
shp2pgsql -s 3059:4326 -I -d "$target_file" | psql -q "$DB"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment