Created
August 20, 2016 21:10
-
-
Save kokes/6ac47adba64b12eaf740844a3ad5cbb3 to your computer and use it in GitHub Desktop.
Z map http://www.gadm.org/country udělá TopoJSON mapu Česka včetně správných kódů bývalých okresů (např. CZ0100 pro Prahu).
This file contains hidden or 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/sh | |
# ze zipu map udělá českou mapu | |
# 1) merguje prahy x do jedný prahy | |
# 2) z SHP dělá TopoJSON | |
# 3) přidá NUTS4 jména | |
# soubor z | |
# https://twitter.com/marekl/status/766997337885515776 | |
# http://www.gadm.org/country | |
unzip CZE_adm_shp.zip -d CZE_adm_shp | |
topojson --shapefile-encoding utf8 -p ID_2,NAME_2 -o cz.json CZE_adm_shp/CZE_adm2.shp | |
sed -E "s/Praha [0-9]*/Praha/g" cz.json > cz2.json | |
mapshaper cz2.json -dissolve NAME_2 -o format=topojson cz3.json | |
python nuts-korekce.py | |
rm -rf CZE_adm_shp | |
mv cz4.json cesko.json | |
rm -rf cz*.json |
This file contains hidden or 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
import json | |
import re | |
import pandas as pd | |
# tohle zavisi na nasich RES souborech | |
# vysledek (nn) je slovnik "Praha" -> 0100, "Děčín" -> "0231" (nebo kolik) | |
res = pd.read_csv('../../vstupy/ares/res.csv') | |
nn = res[['nuts4', 'nuts4k']].drop_duplicates().dropna().set_index('nuts4').to_dict()['nuts4k'] | |
with open('cz3.json') as f: | |
dt = json.load(f) | |
pp = dt['objects']['CZE_adm2']['geometries'] | |
for j, vl in enumerate(pp): | |
prop = vl['properties']['NAME_2'] | |
prop = re.sub('\s*-\s*', '-', prop) | |
prop = prop.replace('Venkov', 'venkov') | |
if prop in ['Brno' ,'Ostrava', 'Plzeň']: | |
prop = '%s-město' % prop | |
assert prop in nn | |
dt['objects']['CZE_adm2']['geometries'][j]['properties'] = { | |
'nuts': nn[prop], | |
'nazev': prop | |
} | |
with open('cz4.json', 'wt') as f: | |
json.dump(dt, f, ensure_ascii=False) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment