-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathregions.py
140 lines (122 loc) · 4.26 KB
/
regions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
# -*- coding: utf-8 -*-
from generator import MapGenerator, SingleMapGenerator
import unicodedata
PROVINCES_BIG_FILE = "src/ne_10m_admin_1_states_provinces_lakes/ne_10m_admin_1_states_provinces_lakes.shp"
SOORP_FILE = "my_src/soorp_cr/soorp.shp"
SOOPU_FILE = "my_src/soorp_cr/sopou.shp"
MZCHU_FILE = "my_src/mzchu/mzchu_npp_npr_body3.shp"
RIVER_FILE = "my_src/reky_cr/reky_cr.shp"
CITY_FILE = "my_src/Obce_cz/Obce_body.shp"
CITY_FILE = "src/czech-republic-latest.shp/places.shp"
def slugrepl(text):
repl = {
'ý': 'y', 'ě': 'e', 'š': 's',
'č': 'c', 'ř': 'r', 'ž': 'z',
'á': 'a', 'í': 'i', 'é': 'e',
'ů': 'u'
}
text = text.lower()
for i in repl.keys():
text = text.replace(i, repl[i])
return text
# return unicodedata.normalize('NFD', text).encode('ascii', 'ignore')
def remove_accents(input_str):
nfkd_form = unicodedata.normalize('NFKD', input_str)
only_ascii = nfkd_form.encode('ASCII', 'ignore')
return only_ascii
def cz_cities_size_filter(record):
return record['population'] > 5 * 10 ** 3
class RegionGenerator(SingleMapGenerator):
state_id = "region"
def __init__(self, code):
self.code = code
self.config = self.get_config()
self.map_name = self.get_map_name()
def get_cities_attributes(self):
return {
"code": "name",
"name": "name",
"population": "population"
}
def get_cities_filter(self):
filter = {"and": [
["type", "in", ["city", "town"]],
["name", "not in", ["Kudowa-Zdrój", "Klingenthal", "Hejnice", "Rejdice",
"Nyergesújfalu", "Lábatlan", "Petržalka", "Nové Mesto",
"Ružinov"]],
cz_cities_size_filter
]}
return filter
def get_config(self):
config = {
"layers": [{
"id": "bg",
"src": PROVINCES_BIG_FILE,
"filter": {'iso_3166_2': self.code.upper()},
}, {
"id": 'soorp',
"src": SOORP_FILE,
"attributes": {
"code": 'nazev',
"name": 'nazev',
},
"simplify": 3,
"filter": {'kraj': self.get_filter()},
}, {
"id": 'soopu',
"src": SOOPU_FILE,
"attributes": {
"code": 'nazev',
"name": 'nazev',
},
"simplify": 3,
"filter": {'kraj': self.get_filter()},
}, {
"id": 'mzchu',
"src": MZCHU_FILE,
"attributes": {
"code": 'nazev',
"name": 'nazev',
},
"simplify": 2,
"filter": {'kod_kraje': self.code[3:].upper()},
}],
"bounds": {
"mode": "polygons",
"data": {
"layer": 'bg',
},
}
}
return config
def hacky_fixes(self, map_data):
map_data = map_data.replace(
'<g class="" id="bg">',
'<g class="" id="bg">' +
'<path d="M-10000.0,-10000.0L-10000.0,10000.0L10000.0,10000.0L10000.0,-10000.0Z "/>')
return map_data
def get_filter(self):
return RegionsGenerator.names_dict[self.code]
class RegionsGenerator(MapGenerator):
names_dict = {
"cz-us": "Ústecký kraj",
"cz-pl": "Plzeňský kraj",
"cz-jm": "Jihomoravský kraj",
"cz-zl": "Zlínský kraj",
"cz-ol": "Olomoucký kraj",
"cz-pa": "Pardubický kraj",
"cz-ka": "Karlovarský kraj",
"cz-jc": "Jihočeský kraj",
"cz-vy": "Kraj Vysočina",
"cz-st": "Středočeský kraj",
"cz-li": "Liberecký kraj",
"cz-kr": "Královéhradecký kraj",
"cz-mo": "Moravskoslezský kraj",
# "cz-pr": "Hlavní město Praha",
}
names_slugs = dict([
(i, slugrepl(n.replace(' ', '')).replace('kraj', '')) for i, n in names_dict.iteritems()])
default_codes = names_dict.keys()
def generate_one(self, state):
gen = RegionGenerator(state)
gen.generate_map()