Skip to content

Commit

Permalink
get_oe_dict_by_ids adapted for eo-objects
Browse files Browse the repository at this point in the history
get_oe_dict_by_ids adapted for eo-objects
  • Loading branch information
dieuska committed Jun 17, 2024
1 parent e581b7f commit 83e0569
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
20 changes: 11 additions & 9 deletions brdr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,35 +138,37 @@ def polygonize_reference_data(dict_ref):
return dict_ref


def get_oe_dict_by_ids(aanduidingsobjecten):
def get_oe_dict_by_ids(objectids, oetype='aanduidingsobjecten'):
"""
Fetches thematic data for a list of aanduidingsobject IDs from the Inventaris Onroerend Erfgoed API.
Fetches thematic data for a list of objectIDs from the Inventaris Onroerend Erfgoed API.
This function retrieves information about designated heritage objects (aanduidingsobjecten)
This function retrieves information about designated heritage objects (erfgoedobjecten or aanduidingsobjecten)
from the Flemish Agency for Heritage (Inventaris Onroerend Erfgoed) based on a list of their IDs.
Args:
aanduidingsobjecten (list): A list of aanduidingsobject (designation object) IDs.
objectids (list): A list of objectIDs of 'erfgoedobjecten' or 'aanduidingsobjecten'.
oetype (string): A string: 'aanduidingsobjecten' (default) or 'erfgoedobjecten'
Returns:
dict: A dictionary where keys are aanduidingsobject IDs (as strings) and values are GeoJSON geometry objects.
If an aanduidingsobject is not found, a corresponding warning message will be logged
dict: A dictionary where keys are objectIDs (as strings) and values are GeoJSON geometry objects.
If an erfgoedobject/aanduidingsobject is not found, a corresponding warning message will be logged
but it won't be included in the returned dictionary.
Raises:
requests.exceptions.RequestException: If there is an error fetching data from the API.
"""
dict_thematic = {}
base_url = "https://inventaris.onroerenderfgoed.be/" + oetype + "/"
headers = {"Accept": "application/json"}
for a in aanduidingsobjecten:
url = "https://inventaris.onroerenderfgoed.be/aanduidingsobjecten/" + str(a)
for a in objectids:
url = base_url + str(a)
response = requests.get(url, headers=headers).json()
if 'id' in response.keys():
key = str(response["id"])
geom = shape(response["locatie"]["contour"])
dict_thematic[key] = geom
else:
logging.warning('aanduidingsobject met id ' + str(a) +' werd niet gevonden' )
logging.warning('object met id ' + str(a) +' werd niet gevonden in ' + oetype)
return dict_thematic


Expand Down
4 changes: 4 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,10 @@ def test_get_oe_dict_by_ids(self):
dict_thematic = get_oe_dict_by_ids([aanduid_id])
self.assertFalse(is_empty(dict_thematic[str(aanduid_id)]))

def test_get_oe_dict_by_ids_erfgoedobject(self):
eo_id = 206363
dict_thematic = get_oe_dict_by_ids([eo_id],oetype='erfgoedobjecten')
self.assertFalse(is_empty(dict_thematic[str(eo_id)]))
def test_get_oe_dict_by_ids_empty(self):
dict_thematic = get_oe_dict_by_ids([])
self.assertEqual(dict_thematic, {})
Expand Down

0 comments on commit 83e0569

Please sign in to comment.