Skip to content

Commit

Permalink
Split overlapping units from some layers
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanb committed Mar 26, 2022
1 parent cf633ea commit a4bf29c
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -31,6 +31,10 @@ geojson:
echo `wc -l data/$${BASENAME}.csv`; \
done

.PHONY: split
split:
./split.sh $(TMP)

.PHONY: clean
clean:
rm -r $(TMP)
Expand Down
31 changes: 31 additions & 0 deletions split.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit a4bf29c

Please sign in to comment.