@@ 284-320 (lines=37) @@ | ||
281 | s.set_gateway(self) |
|
282 | return secties |
|
283 | ||
284 | def get_sectie_by_id_and_afdeling(self, id, afdeling): |
|
285 | ''' |
|
286 | Get a `sectie`. |
|
287 | ||
288 | :param id: An id of a sectie. eg. "A" |
|
289 | :param afdeling: The :class:`Afdeling` for in which the `sectie` can \ |
|
290 | be found. Can also be the id of and `afdeling`. |
|
291 | :rtype: A :class:`Sectie`. |
|
292 | ''' |
|
293 | try: |
|
294 | aid = afdeling.id |
|
295 | except AttributeError: |
|
296 | aid = afdeling |
|
297 | afdeling = self.get_kadastrale_afdeling_by_id(aid) |
|
298 | afdeling.clear_gateway() |
|
299 | ||
300 | def creator(): |
|
301 | url = self.base_url + '/municipality/%s/department/%s/section/%s' % (afdeling.gemeente.id, afdeling.id, id) |
|
302 | h = self.base_headers |
|
303 | p = { |
|
304 | 'geometry': 'bbox', |
|
305 | 'srs': '31370' |
|
306 | } |
|
307 | res = capakey_rest_gateway_request(url, h, p).json() |
|
308 | return Sectie( |
|
309 | res['sectionCode'], |
|
310 | afdeling, |
|
311 | self._parse_centroid(res['geometry']['center']), |
|
312 | self._parse_bounding_box(res['geometry']['boundingBox']) |
|
313 | ) |
|
314 | if self.caches['long'].is_configured: |
|
315 | key = 'get_sectie_by_id_and_afdeling_rest#%s#%s' % (id, aid) |
|
316 | sectie = self.caches['long'].get_or_create(key, creator) |
|
317 | else: |
|
318 | sectie = creator() |
|
319 | sectie.set_gateway(self) |
|
320 | return sectie |
|
321 | ||
322 | def parse_percid(self, capakey): |
|
323 | import re |
|
@@ 354-388 (lines=35) @@ | ||
351 | "Invalid percid %s can't be parsed" % percid |
|
352 | ) |
|
353 | ||
354 | def list_percelen_by_sectie(self, sectie): |
|
355 | ''' |
|
356 | List all percelen in a `sectie`. |
|
357 | ||
358 | :param sectie: The :class:`Sectie` for which the percelen are wanted. |
|
359 | :param integer sort: Field to sort on. |
|
360 | :rtype: A :class:`list` of :class:`Perceel`. |
|
361 | ''' |
|
362 | sid = sectie.id |
|
363 | aid = sectie.afdeling.id |
|
364 | gid = sectie.afdeling.gemeente.id |
|
365 | sectie.clear_gateway() |
|
366 | def creator(): |
|
367 | url = self.base_url + '/municipality/%s/department/%s/section/%s/parcel' % (gid, aid, sid) |
|
368 | h = self.base_headers |
|
369 | p = { |
|
370 | 'data': 'cadmap' |
|
371 | } |
|
372 | res = capakey_rest_gateway_request(url, h, p).json() |
|
373 | return [ |
|
374 | Perceel( |
|
375 | r['perceelnummer'], |
|
376 | sectie, |
|
377 | r['capakey'], |
|
378 | self.parse_percid(r['capakey']), |
|
379 | ) for r in res['parcels'] |
|
380 | ] |
|
381 | if self.caches['short'].is_configured: |
|
382 | key = 'list_percelen_by_sectie_rest#%s#%s#%s' % (gid, aid, sid) |
|
383 | percelen = self.caches['short'].get_or_create(key, creator) |
|
384 | else: |
|
385 | percelen = creator() |
|
386 | for p in percelen: |
|
387 | p.set_gateway(self) |
|
388 | return percelen |
|
389 | ||
390 | def get_perceel_by_id_and_sectie(self, id, sectie): |
|
391 | ''' |