From 9d2c6bb27d75829f90de12197c98cecfa1d98a71 Mon Sep 17 00:00:00 2001 From: Benjamin Pelletier Date: Fri, 17 May 2024 11:32:43 -0700 Subject: [PATCH] Add exclude_heliports --- aerodata/__init__.py | 4 +++- aerodata/query.py | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/aerodata/__init__.py b/aerodata/__init__.py index 84c0a2f..b840b09 100644 --- a/aerodata/__init__.py +++ b/aerodata/__init__.py @@ -1,9 +1,10 @@ from gevent import monkey -from requests import HTTPError monkey.patch_all() import flask +from loguru import logger +from requests import HTTPError from aerodata.fetch import get_features from aerodata.query import AerodromeQueryParams, select_features @@ -13,6 +14,7 @@ @webapp.route("/aerodromes") def get_aerodromes(): + logger.debug(f"Staring aerodromes handler for {flask.request.query_string.decode()}") try: query_params = AerodromeQueryParams.from_dict(flask.request.args) except ValueError as e: diff --git a/aerodata/query.py b/aerodata/query.py index 596c806..c4b5ed7 100644 --- a/aerodata/query.py +++ b/aerodata/query.py @@ -9,6 +9,7 @@ class AerodromeQueryParams(object): page_size: int exclude_runways: bool exclude_helipads: bool + exclude_heliports: bool exclude_aerodromes: bool latA: float latB: float @@ -27,6 +28,7 @@ def from_dict(params: dict) -> AerodromeQueryParams: raise ValueError("Invalid page_size") kwargs["exclude_runways"] = params.get("exclude_runways", "false").lower() == "true" kwargs["exclude_helipads"] = params.get("exclude_helipads", "false").lower() == "true" + kwargs["exclude_heliports"] = params.get("exclude_heliports", "false").lower() == "true" kwargs["exclude_aerodromes"] = params.get("exclude_aerodromes", "false").lower() == "true" bounding_box = params.get("bounding_box", None) @@ -71,7 +73,7 @@ def from_dict(params: dict) -> AerodromeQueryParams: return AerodromeQueryParams(**kwargs) -def select_features(all_features: dict, query: AerodromeQueryParams) -> dict: +def select_features(all_features: list[dict], query: AerodromeQueryParams) -> dict: """Filter the provided features and return a FeatureCollection with selected features. Args: @@ -119,6 +121,20 @@ def select_features(all_features: dict, query: AerodromeQueryParams) -> dict: features.append(feature) + if query.exclude_heliports: + to_remove = [] + for feature in features: + if feature["properties"]["aerodrome_element_type"] == "Aerodrome": + surfaces = [ + f for f in all_features + if f is not feature + and f["properties"].get("aerodrome_identifier", "") == feature["properties"]["aerodrome_identifier"] + ] + if all(s["properties"]["aerodrome_element_type"] == "Helipad" for s in surfaces): + to_remove.append(feature) + for feature in to_remove: + features.remove(feature) + if query.page_token: skip = int(query.page_token) if skip >= len(features):