Skip to content

Commit

Permalink
Merge pull request #75 from OnroerendErfgoed/FIX_0.8.1
Browse files Browse the repository at this point in the history
Fix 0.8.1
  • Loading branch information
koenedaele committed Apr 20, 2017
2 parents 4a29118 + d27e4f8 commit b3e8a55
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 11 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
@@ -1,3 +1,9 @@
0.8.1 (??-04-2017)
------------------

- Updated center and bounding box format in responses of the CapakeyRestGateway
in accordance with the CapakeyGateway (#73).

0.8.0 (19-04-2017)
------------------

Expand Down
45 changes: 35 additions & 10 deletions crabpy/gateway/capakey.py
Expand Up @@ -7,6 +7,7 @@

from __future__ import unicode_literals
import six
import json

import logging
log = logging.getLogger(__name__)
Expand Down Expand Up @@ -503,6 +504,30 @@ def __init__(self, **kwargs):
'%s.' % cr
)

@staticmethod
def _parse_centroid(center):
'''
Parse response center from the CapakeyRestGateway to (CenterX, CenterY)
:param center: response center from the CapakeyRestGateway
:return: (CenterX, CenterY)
'''
coordinates = json.loads(center)["coordinates"]
return coordinates[0], coordinates[1]

@staticmethod
def _parse_bounding_box(bounding_box):
'''
Parse response bounding box from the CapakeyRestGateway to (MinimumX, MinimumY, MaximumX, MaximumY)
:param bounding_box: response bounding box from the CapakeyRestGateway
:return: (MinimumX, MinimumY, MaximumX, MaximumY)
'''
coordinates = json.loads(bounding_box)["coordinates"]
x_coords = [x for x, y in coordinates[0]]
y_coords = [y for x, y in coordinates[0]]
return min(x_coords), min(y_coords), max(x_coords), max(y_coords)

def list_gemeenten(self, sort=1):
'''
List all `gemeenten` in Vlaanderen.
Expand Down Expand Up @@ -547,8 +572,8 @@ def creator():
return Gemeente(
res['municipalityCode'],
res['municipalityName'],
res['geometry']['center'],
res['geometry']['boundingBox']
self._parse_centroid(res['geometry']['center']),
self._parse_bounding_box(res['geometry']['boundingBox'])
)
if self.caches['long'].is_configured:
key = 'get_gemeente_by_id_rest#%s' % id
Expand Down Expand Up @@ -635,8 +660,8 @@ def creator():
id=res['departmentCode'],
naam=res['departmentName'],
gemeente=Gemeente(res['municipalityCode'], res['municipalityName']),
centroid=res['geometry']['center'],
bounding_box=res['geometry']['boundingBox']
centroid=self._parse_centroid(res['geometry']['center']),
bounding_box=self._parse_bounding_box(res['geometry']['boundingBox'])
)
if self.caches['long'].is_configured:
key = 'get_kadastrale_afdeling_by_id_rest#%s' % aid
Expand Down Expand Up @@ -709,8 +734,8 @@ def creator():
return Sectie(
res['sectionCode'],
afdeling,
res['geometry']['center'],
res['geometry']['boundingBox'],
self._parse_centroid(res['geometry']['center']),
self._parse_bounding_box(res['geometry']['boundingBox'])
)
if self.caches['long'].is_configured:
key = 'get_sectie_by_id_and_afdeling_rest#%s#%s' % (id, aid)
Expand Down Expand Up @@ -816,8 +841,8 @@ def creator():
Perceel.get_percid_from_capakey(res['capakey']),
None,
None,
res['geometry']['center'],
res['geometry']['boundingBox']
self._parse_centroid(res['geometry']['center']),
self._parse_bounding_box(res['geometry']['boundingBox'])
)
if self.caches['short'].is_configured:
key = 'get_perceel_by_id_and_sectie_rest#%s#%s#%s' % (id, sectie.id, sectie.afdeling.id)
Expand Down Expand Up @@ -857,8 +882,8 @@ def creator():
Perceel.get_percid_from_capakey(res['capakey']),
None,
None,
res['geometry']['center'],
res['geometry']['boundingBox']
self._parse_centroid(res['geometry']['center']),
self._parse_bounding_box(res['geometry']['boundingBox'])
)
if self.caches['short'].is_configured:
key = 'get_perceel_by_capakey_rest#%s' % capakey
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -20,7 +20,7 @@

setup(
name='crabpy',
version='0.8.0',
version='0.8.1',
description='Interact with AGIV webservices.',
long_description=open('README.rst').read() + '\n\n' +
open('CHANGES.rst').read(),
Expand Down
4 changes: 4 additions & 0 deletions tests/gateway/test_capakey.py
Expand Up @@ -176,6 +176,8 @@ def test_get_perceel_by_capakey(self, capakey_gateway):
assert isinstance(res, Perceel)
assert res.sectie.id == 'A'
assert res.sectie.afdeling.id == 44021
assert res.centroid == (104033.43150000274, 194675.36899999902)
assert res.bounding_box == (104026.09700000286, 194663.61899999902, 104040.76600000262, 194687.11899999902)

def test_get_perceel_by_unexisting_capakey(self, capakey_gateway):
with pytest.raises(GatewayResourceNotFoundException):
Expand Down Expand Up @@ -281,6 +283,8 @@ def test_get_perceel_by_capakey(self, capakey_rest_gateway):
assert isinstance(res, Perceel)
assert res.sectie.id == 'A'
assert res.sectie.afdeling.id == 44021
assert res.centroid == (104033.43150000274, 194675.36899999902)
assert res.bounding_box == (104026.09700000286, 194663.61899999902, 104040.76600000262, 194687.11899999902)

def test_get_perceel_by_percid(self, capakey_rest_gateway):
s = capakey_rest_gateway.get_sectie_by_id_and_afdeling('A', 44021)
Expand Down

0 comments on commit b3e8a55

Please sign in to comment.