Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix 0.8.1 #75

Merged
merged 3 commits into from
Apr 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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