-
Notifications
You must be signed in to change notification settings - Fork 11
/
gen_huishoudelijkafvalv2.py.txt
234 lines (199 loc) · 13.8 KB
/
gen_huishoudelijkafvalv2.py.txt
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
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# Generates the huishoudelijkafval mapfile.
from generate import block, header, p, q
import re
def slugify(s: str) -> str:
# Function to slugify strings (convert to lowercase and replace non-alphanumeric characters with underscores)
s = s.replace("ë", "e") # Replace special characters like 'ë' with 'e'
return re.sub(r"[^A-Za-z0-9]+", "_", s).strip("_").lower()
# Define layers for huishoudelijkafval
layers = [
{"group": "afvalcontainers", "name": "gft_coordinaten", "filter": "[fractie_omschrijving] = 'GFT' AND [status] = 1", "symbol": "gfe", "title": "Gftafvalcontainer"},
{"group": "afvalcontainers", "name": "textiel_coordinaten", "filter": "[fractie_omschrijving] = 'Textiel' AND [status] = 1", "symbol": "textiel", "title": "Textielafvalcontainer"},
{"group": "afvalcontainers", "name": "papier_coordinaten", "filter": "[fractie_omschrijving] = 'Papier' AND [status] = 1", "symbol": "papier", "title": "Papierafvalcontainer"},
{"group": "afvalcontainers", "name": "glas_coordinaten", "filter": "[fractie_omschrijving] = 'Glas' AND [status] = 1", "symbol": "glas", "title": "Glasafvalcontainer"},
{"group": "afvalcontainers", "name": "rest_coordinaten", "filter": "[fractie_omschrijving] = 'Rest' AND [status] = 1", "symbol": "rest", "title": "Restafvalcontainer"},
{"group": "afvalcontainers", "name": "brood_coordinaten", "filter": "[fractie_omschrijving] = 'Brood' AND [status] = 1", "symbol": "brood", "title": "Broodafvalcontainer"},
{"group": "afvalcontainers", "name": "onbekend_coordinaten", "filter": "fractie_omschrijving = '' and status = 1", "symbol": "onbekend", "title": "Onbekend"},
{"group": "kilogram", "name": "wegingen_rest", "filter": "[fractie_omschrijving] = 'Rest'","symbol": "stip","title": "Rest wegingen"},
{"group": "kilogram", "name": "wegingen_glas", "filter": "[fractie_omschrijving] = 'Glas'","symbol": "stip","title": "Glas wegingen"},
{"group": "kilogram", "name": "wegingen_papier", "filter": "[fractie_omschrijving] = 'Papier'","symbol": "stip","title": "Papier wegingen"},
{"group": "kilogram", "name": "wegingen_plastic", "filter": "[fractie_omschrijving] = 'Plastic'","symbol": "stip","title": "Plastic wegingen"},
{"group": "kilogram", "name": "wegingen_textiel", "filter": "[fractie_omschrijving] = 'Textiel'","symbol": "stip","title": "Textiel wegingen"},
{"group": "kilogram", "name": "wegingen_grof", "filter": "[fractie_omschrijving] = 'Grof'","symbol": "stip","title": "Grof wegingen"},
{"group": "kilogram", "name": "wegingen_PMD", "filter": "[fractie_omschrijving] = 'PMD'","symbol": "stip","title": "PMD wegingen"},
{"group": "kilogram", "name": "wegingen_brood", "filter": "[fractie_omschrijving] = 'Brood'","symbol": "stip","title": "Brood wegingen"},
{"group": "kilogram", "name": "wegingen_onbekend", "filter": "[fractie_omschrijving] isnull","symbol": "stip","title": "Onbekend wegingen"},
{"group": "pand_loopafstand", "name": "pand_loopafstand_rest", "filter": "[fractie_omschrijving] = 'Rest'", "symbol": "rest", "title": "Loopafstand tot restafvalcontainer"},
{"group": "pand_loopafstand", "name": "pand_loopafstand_glas", "filter": "[fractie_omschrijving] = 'Glas'", "symbol": "rest", "title": "Loopafstand tot glascontainer"},
{"group": "pand_loopafstand", "name": "pand_loopafstand_papier", "filter": "[fractie_omschrijving] = 'Papier'", "symbol": "rest", "title": "Loopafstand tot papiercontainer"},
{"group": "pand_loopafstand", "name": "pand_loopafstand_textiel", "filter": "[fractie_omschrijving] = 'Textiel'", "symbol": "rest", "title": "Loopafstand tot textielcontainer"},
{"group": "pand_loopafstand", "name": "pand_loopafstand_gft", "filter": "[fractie_omschrijving] = 'GFT'", "symbol": "rest", "title": "Loopafstand tot gftafvalcontainer"}
]
weight_ranges = [
{"name": "< 50 kg", "expression": "[netto_gewicht] < 50", "color": (0, 104, 55)},
{"name": "< 90 kg", "expression": "[netto_gewicht] < 90", "color": (26, 152, 80)},
{"name": "< 130 kg", "expression": "[netto_gewicht] < 130", "color": (102, 189, 99)},
{"name": "< 170 kg", "expression": "[netto_gewicht] < 170", "color": (166, 217, 106)},
{"name": "< 210 kg", "expression": "[netto_gewicht] < 210", "color": (217, 239, 139)},
{"name": "< 260 kg", "expression": "[netto_gewicht] < 260", "color": (254, 224, 139)},
{"name": "< 310 kg", "expression": "[netto_gewicht] < 310", "color": (253, 174, 97)},
{"name": "< 390 kg", "expression": "[netto_gewicht] < 390", "color": (244, 109, 67)},
{"name": "< 500 kg", "expression": "[netto_gewicht] < 500", "color": (215, 48, 39)},
{"name": "> 500 kg", "expression": "[netto_gewicht] >= 500", "color": (165, 0, 38)}
]
loopafstanden_ranges = [
{"name": "<= 30 m", "expression": "[loopafstand_categorie_omschrijving] eq '0 - 30 M'", "color": (50, 114, 48)},
{"name": "30 - 90 m", "expression": "[loopafstand_categorie_omschrijving] eq '30 - 90 M'", "color": (77, 175, 74)},
{"name": "90 - 120 m", "expression": "[loopafstand_categorie_omschrijving] eq '90 - 120 M'", "color": (157, 175, 157)},
{"name": "120 - 150 m", "expression": "[loopafstand_categorie_omschrijving] eq '120 - 150 M'", "color": (255, 127, 0)},
{"name": "150 - 210 m", "expression": "[loopafstand_categorie_omschrijving] eq '150 - 210 M'", "color": (255, 75, 0)},
{"name": "210 - 1000 m", "expression": "[loopafstand_categorie_omschrijving] eq '210 - 1000 M'", "color": (110, 110, 110)},
{"name": "vanaf 1000 m", "expression": "[loopafstand_categorie_omschrijving] eq 'Vanaf 1000 M'", "color": (204, 204, 204)}
]
loopafstanden_ranges_textiel = [
{"name": "<= 90 m", "expression": "[loopafstand_categorie_omschrijving] eq '0 - 90 M'", "color": (50, 114, 48)},
{"name": "90 - 180 m", "expression": "[loopafstand_categorie_omschrijving] eq '90 - 180 M'", "color": (77, 175, 74)},
{"name": "180 - 350 m", "expression": "[loopafstand_categorie_omschrijving] eq '180 - 350 M'", "color": (157, 175, 157)},
{"name": "350 - 370 m", "expression": "[loopafstand_categorie_omschrijving] eq '350 - 370 M'", "color": (253, 191, 111)},
{"name": "370 - 480 m", "expression": "[loopafstand_categorie_omschrijving] eq '370 - 480 M'", "color": (255, 75, 0)},
{"name": "480 - 1500 m", "expression": "[loopafstand_categorie_omschrijving] eq '480 - 1500 M'", "color": (110, 110, 110)},
{"name": "vanaf 1500 m", "expression": "[loopafstand_categorie_omschrijving] eq 'Vanaf 1500 M'", "color": (204, 204, 204)}
]
# Generate the mapfile
header("Huishoudelijk Afval Mapfile")
with block("MAP"):
p("NAME", "huishoudelijkafvalv2")
p("INCLUDE", "header.inc")
with block("WEB"):
with block("METADATA"):
q("ows_title", "afvalcontainers")
q("ows_abstract", "Kaart met gegevens over huishoudelijk afvalcontainers in Amsterdam")
q("wms_extent", "4.58565 52.03560 5.31360 52.48769")
q("wfs_extent", "4.58565 52.03560 5.31360 52.48769")
q("gml_types", "auto")
q("ows_onlineresource", "MAP_URL_REPLACE/maps/huishoudelijkafvalv2")
with block("LEGEND"):
p("STATUS ON")
p("KEYSIZE 30 30")
# Generate layers for huishoudelijkafval containers
for layer in layers:
if layer["group"] == 'afvalcontainers':
with block("LAYER"):
p("NAME", slugify(layer['name']))
p("GROUP", f"{layer['group']}")
with block("PROJECTION"):
q("init=epsg:28992")
p("INCLUDE", "connection/dataservices.inc")
if layer["name"] == 'onbekend_coordinaten':
p("DATA", f"geometrie FROM (select * FROM public.huishoudelijkafval_container where fractie_omschrijving is null and status = 1) as subquery USING srid=28992 USING UNIQUE id")
else:
p("DATA", f"geometrie FROM public.huishoudelijkafval_container USING srid=28992 USING UNIQUE id")
print(f"FILTER ({layer['filter']})")
p("TYPE POINT")
p("MINSCALEDENOM", 10)
p("MAXSCALEDENOM", 400000)
with block("METADATA"):
q("ows_title", layer['title'])
q("wfs_srs", "EPSG:28992")
q("wfs_abstract", f"{layer['title']} in Amsterdam")
q("wfs_enable_request", "*")
p("LABELITEM", "id_nummer")
with block ("CLASS"):
p("NAME", f"{slugify(layer['title'])}")
p("TITLE", f"{layer['title']}")
with block("STYLE"):
p("SYMBOL", layer['symbol'])
p("SIZE", 30)
with block("LABEL"):
p("MAXSCALEDENOM 4000")
p("COLOR 102 102 102")
p("OUTLINECOLOR 255 255 255")
p("OUTLINEWIDTH 3")
p("FONT", "Ubuntu-M")
p("TYPE truetype")
p("SIZE 10")
p("POSITION AUTO")
p("PARTIALS FALSE")
p("OFFSET -60 10")
# #vanaf hier is het voor de wegingen,
# DEZE IS NIET AF MAAR OP VERZOEK VAN ERGUDER IS DEZE UITGEZET
# if layer["group"] == 'kilogram':
# with block("LAYER"):
# p("NAME", slugify(layer['name']))
# p("GROUP", f"{layer['group']}")
# with block("PROJECTION"):
# q("init=epsg:28992")
# p("INCLUDE", "connection/dataservices.inc")
# p("DATA", """geometrie FROM (select * from public.huishoudelijkafval_weging where datum_weging > (NOW() - INTERVAL '6 months') ORDER BY datum_weging desc) as subquery USING srid=28992 USING UNIQUE id""")
# print(f"FILTER ({layer["filter"]})")
# p("TYPE POINT")
# p("MINSCALEDENOM", 10)
# p("MAXSCALEDENOM", 400000)
# with block("METADATA"):
# q("wfs_title", layer['title'])
# q("wfs_srs", "EPSG:28992")
# q("wfs_abstract", f"{layer['title']} in Amsterdam")
# q("wfs_enable_request", "*")
# p("LABELITEM", "id")
# for range in weight_ranges:
# with block ("CLASS"):
# p("NAME", slugify(range["name"]))
# p("TITLE", range["name"])
# p('EXPRESSION', range['expression'])
# with block("STYLE"):
# p('SYMBOL', 'stip')
# p(f"COLOR {" ".join(map(str, range['color']))}")
# p("SIZE", 6)
# with block("LABEL"):
# p("MAXSCALEDENOM 4000")
# p("COLOR 102 102 102")
# p("OUTLINECOLOR 255 255 255")
# p("OUTLINEWIDTH 3")
# p("FONT", "Ubuntu-M")
# p("TYPE truetype")
# p("SIZE 10")
# p("POSITION AUTO")
# p("PARTIALS FALSE")
# p("OFFSET -60 10")
#vanaf hier is het voor de loopafstanden
if layer["group"] == 'pand_loopafstand':
loopafstanden_ranges_selected = loopafstanden_ranges_textiel if layer['name'] == 'pand_loopafstand_textiel' else loopafstanden_ranges
for range in loopafstanden_ranges_selected:
with block("LAYER"):
p("NAME", slugify(layer['name']) + ' ' + range['name'])
p("GROUP", f"{layer['group']}")
with block("PROJECTION"):
q("init=epsg:28992")
p("INCLUDE", "connection/dataservices.inc")
p("DATA", "geometrie FROM (SELECT bol.id, bol.geometrie, bol.fractie_omschrijving, lac.loopafstand_categorie_omschrijving FROM public.huishoudelijkafval_bag_object_loopafstand_v2 bol INNER JOIN public.huishoudelijkafval_loopafstand_categorie_v2 lac ON bol.loopafstand_categorie_id = lac.id WHERE 1=1) rest USING srid=28992 USING UNIQUE id")
print(f"FILTER ({layer['filter']} AND {range['expression']})")
p("TYPE POLYGON")
p("MINSCALEDENOM", 10)
p("MAXSCALEDENOM", 400000)
with block("METADATA"):
q("ows_title", layer['title'] + ' ' + range["name"])
q("wfs_title", layer['title'] + ' ' + range["name"])
q("wfs_srs", "EPSG:28992")
q("wfs_abstract", f"{layer['title']} in Amsterdam")
q("wfs_enable_request", "*")
q("wms_group_title", "loopafstand (per pand)")
p("LABELITEM", "id")
with block ("CLASS"):
p("NAME", f"{slugify(range['name'])}")
p("TITLE", f"{range['name']}")
with block("STYLE"):
p(f"COLOR {' '.join(map(str, range['color']))}")
p("WIDTH ", 2)
p ("OPACITY", 80)
p (f"OUTLINECOLOR {' '.join(map(str, range['color']))}")
with block("LABEL"):
p("MAXSCALEDENOM 500")
p("COLOR 102 102 102")
p("OUTLINECOLOR 255 255 255")
p("OUTLINEWIDTH 3")
p("FONT", "Ubuntu-M")
p("TYPE truetype")
p("SIZE 10")
p("POSITION AUTO")
p("PARTIALS FALSE")
p("OFFSET -60 10")