Skip to content

Commit

Permalink
replace atlas with pdok api
Browse files Browse the repository at this point in the history
  • Loading branch information
NvdLaan authored and remyvdwereld committed Nov 21, 2024
1 parent 9a8aa7b commit f77abc7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ LOGGING_LEVEL=WARNING # To prevent flooding the logging in local development. De
SECRET_KEY_TOP_ZAKEN=SECRET_KEY_TOP_ZAKEN
SECRET_KEY_TON_ZAKEN=SECRET_KEY_TON_ZAKEN
BELASTING_API_URL=https://api-acc.belastingen.centric.eu/bel/inn/afne/vora/v1/vorderingenidentificatienummer/
BAG_API_SEARCH_URL=https://api.data.amsterdam.nl/atlas/search/adres/
BAG_API_SEARCH_URL=https://api.pdok.nl/bzk/locatieserver/search/v3_1/free
BAG_API_NUMMERAANDUIDING_SEARCH_URL=https://api.data.amsterdam.nl/v1/bag/nummeraanduidingen/
BAG_API_BENKAGG_SEARCH_URL=https://api.data.amsterdam.nl/v1/benkagg/adresseerbareobjecten/
DECOS_JOIN_USERNAME=ZakenTop
Expand Down
37 changes: 18 additions & 19 deletions app/apps/addresses/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ def get_or_create_by_bag_id(bag_id):

def get_bag_address_data(self):
bag_search_response = do_bag_search_by_bag_id(self.bag_id)
bag_search_results = bag_search_response.get("results", [])

bag_search_results = bag_search_response.get("response", {}).get("docs", [])
if bag_search_results:
# A BAG search will return an array with 1 or more results.
# There could be a "Nevenadres" so check addresses for "Hoofdadres".
Expand All @@ -98,12 +97,11 @@ def get_bag_address_data(self):
self.postal_code = found_bag_data.get("postcode", "")
self.street_name = found_bag_data.get("straatnaam", "")
self.number = found_bag_data.get("huisnummer", "")
self.suffix_letter = found_bag_data.get("bag_huisletter", "")
self.suffix = found_bag_data.get("bag_toevoeging", "")
# Temporarily property for type. Could be verblijfsobject (huis) or standplaats (woonboot).
self.type = found_bag_data.get("type", "verblijfsobject")

centroid = found_bag_data.get("centroid", None)
self.suffix_letter = found_bag_data.get("huisletter", "")
self.suffix = found_bag_data.get("huisnummertoevoeging", "")
self.nummeraanduiding_id = found_bag_data.get("nummeraanduiding_id", "")
centroid_string = found_bag_data.get("centroide_ll", None)
centroid = self._parse_centroid(centroid_string)
if centroid:
self.lng = centroid[0]
self.lat = centroid[1]
Expand Down Expand Up @@ -133,18 +131,7 @@ def get_bag_identificatie_and_stadsdeel(self):
{},
)

nummeraanduiding_id = found_bag_object.get("identificatie")
if nummeraanduiding_id:
self.nummeraanduiding_id = nummeraanduiding_id

district_name = found_bag_object.get("gebiedenStadsdeelNaam")

if district_name:
self.district = District.objects.get_or_create(name=district_name)[0]

# Get coordinates for standplaats (woonboot).
ligplaats_geometrie = found_bag_object.get("ligplaatsGeometrie") or {}
ligplaats_coordinates = ligplaats_geometrie.get("coordinates")
if ligplaats_coordinates:
(lat, lng) = convert_polygon_to_latlng(ligplaats_coordinates)
self.lng = lng
Expand All @@ -168,3 +155,15 @@ def save(self, *args, **kwargs):
if not self.bag_id or not self.nummeraanduiding_id:
self.update_bag_data()
return super().save(*args, **kwargs)

def _parse_centroid(self, centroid):
# Check if the string starts with 'POINT(' and ends with ')'
if centroid.startswith("POINT(") and centroid.endswith(")"):
# Remove the 'POINT(' at the beginning and ')' at the end
coordinates_str = centroid[6:-1]
# Split the string by space to get the individual numbers
coordinates = coordinates_str.split()
# Convert the string numbers to float and return as a list
return [float(coordinates[0]), float(coordinates[1])]
else:
raise ValueError("Input string is not in the correct format.")
2 changes: 1 addition & 1 deletion app/apps/health/health_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class BAGAtlasServiceCheck(APIServiceCheckBackend):
"""

critical_service = True
api_url = settings.BAG_API_SEARCH_URL
api_url = f"{settings.BAG_API_SEARCH_URL}?q={settings.BAG_ID_AMSTEL_1}"
verbose_name = "BAG Atlas"


Expand Down
8 changes: 2 additions & 6 deletions app/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,9 @@ def filter_traces(envelope):

# BAG Atlas
BAG_API_SEARCH_URL = os.getenv(
"BAG_API_SEARCH_URL", "https://api.data.amsterdam.nl/atlas/search/adres/"
)
# BAG Nummeraanduidingen
BAG_API_NUMMERAANDUIDING_SEARCH_URL = os.getenv(
"BAG_API_NUMMERAANDUIDING_SEARCH_URL",
"https://api.data.amsterdam.nl/v1/bag/nummeraanduidingen/",
"BAG_API_SEARCH_URL", "https://api.pdok.nl/bzk/locatieserver/search/v3_1/free"
)

# BAG benkagg for nummeraanduidingen and stadsdeel
BAG_API_BENKAGG_SEARCH_URL = os.getenv(
"BAG_API_BENKAGG_SEARCH_URL",
Expand Down
8 changes: 7 additions & 1 deletion app/utils/api_queries_bag.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ def do_bag_search_by_bag_id(bag_id):
Search BAG using a BWV 'landelijk BAG ID'
"""
address_search = requests.get(
settings.BAG_API_SEARCH_URL, params={"q": bag_id}, timeout=5
settings.BAG_API_SEARCH_URL,
params={
"q": bag_id,
"fq": f"gemeentenaam:(amsterdam) AND (type:adres) AND (adresseerbaarobject_id: {bag_id}) AND (adrestype: hoofdadres)",
},
timeout=5,
)

return address_search.json()


Expand Down

0 comments on commit f77abc7

Please sign in to comment.