From a4bf29cda3bf6eb21300018964e140824e231d4d Mon Sep 17 00:00:00 2001 From: Stefan Baebler Date: Sat, 26 Mar 2022 21:27:38 +0100 Subject: [PATCH] Split overlapping units from some layers --- Makefile | 6 +++++- split.sh | 31 +++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 split.sh diff --git a/Makefile b/Makefile index 2e28343..dcc18f5 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ TMP = $(DATAFOLDER)temp/ TS = $$(cat $(TMP)timestamp.txt) TSYYYY = $$(cat $(TMP)timestamp.txt | cut -b 1-4) -all: download geojson +all: download geojson split .PHONY: download download: @@ -31,6 +31,10 @@ geojson: echo `wc -l data/$${BASENAME}.csv`; \ done +.PHONY: split +split: + ./split.sh $(TMP) + .PHONY: clean clean: rm -r $(TMP) diff --git a/split.sh b/split.sh new file mode 100644 index 0000000..3fb5ad3 --- /dev/null +++ b/split.sh @@ -0,0 +1,31 @@ +#!/bin/bash +set -e +export OGR_WKT_PRECISION=9 +TMP="${1}" + +function split() { + shp="$1" + enota="$2" + descriptionCollection="$3" + # descriptionSingle="$4" + + shpFile=$(find "${TMP}" -name "$shp.shp") + DIRNAME=$(dirname "$shpFile") + BASENAME=$(basename "$shpFile" .shp) + echo "Extracting ${enota} from ${shp}..." + mkdir -p "data/${shp}" + SHAPE_ENCODING=CP1250 ogr2ogr -t_srs "EPSG:4326" -f "CSV" "data/${shp}/${BASENAME}_${enota}.csv" "${DIRNAME}" -sql "SELECT * FROM ${BASENAME} WHERE ENOTA='${enota}' ORDER BY ${BASENAME}_MID" -dialect sqlite -lco WRITE_BOM=YES -lco STRING_QUOTING=IF_NEEDED + + SHAPE_ENCODING=CP1250 ogr2ogr -t_srs "EPSG:4326" -f "GeoJSON" "data/${shp}/${BASENAME}_${enota}.geojson" "${DIRNAME}" -sql "SELECT * FROM ${BASENAME} WHERE ENOTA='${enota}' ORDER BY ${BASENAME}_MID" -dialect sqlite -lco RFC7946=YES -lco WRITE_BBOX=YES -mapFieldType Date=String -nln "${BASENAME}_${enota}" -lco DESCRIPTION="${descriptionCollection}" +} + +split VDV VE "Državnozborske volilne enote" "Državnozborska volilna enota" +split VDV VO "Državnozborski volilni okraji" "Državnozborski volilni okraj" +split VDV VD "Državnozborska volišča" "Državnozborsko volišče" + +split VLV LE "Lokalne volilne enote" "Lokalna volilna enota" +split VLV LV "Lokalna volišča" "Lokalno volišče" + +split ODO CM "Mestne četrti" "Mestna četrt" +split ODO CK "Krajevne skupnosti" "Krajevna skupnost" +split ODO CV "Vaške četrti" "Vaška četrt"