From bd0bff0d1a4a57758136f02c5c43b06148cfd33e Mon Sep 17 00:00:00 2001 From: Claudio Ortega Date: Fri, 10 Nov 2023 17:08:44 +0000 Subject: [PATCH 1/3] Add option to return all results --- urbanpy/download/download.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/urbanpy/download/download.py b/urbanpy/download/download.py index c0d0524..25c8ead 100644 --- a/urbanpy/download/download.py +++ b/urbanpy/download/download.py @@ -35,22 +35,23 @@ ) -def nominatim_osm(query: str, expected_position=0) -> GeoDataFrame: +def nominatim_osm(query: str, expected_position: int | None = 0) -> GeoDataFrame: """ Download OpenStreetMaps data for a specific city. Parameters ---------- query: str - Query for city polygon data to be downloaded. + Query string for OSM data to be downloaded (e.g. "Lima, Peru"). expected_position: int 0:n Expected position of the polygon data within the Nominatim results. - Default 0 (first result). + Default 0 returns the first result. + If set to None, all the results are returned. Returns ------- - city: GeoDataFrame - GeoDataFrame with the city's polygon as its geometry column. + gdf: GeoDataFrame + GeoDataFrame with the fetched OSM data. Examples -------- @@ -66,9 +67,10 @@ def nominatim_osm(query: str, expected_position=0) -> GeoDataFrame: response = requests.get(osm_url, params=osm_parameters) all_results = response.json() gdf = gpd.GeoDataFrame.from_features(all_results["features"], crs="EPSG:4326") - city = gdf.iloc[expected_position : expected_position + 1, :] + if expected_position: + return gdf.iloc[expected_position : expected_position + 1] # this returns a GeoDataFrame instead of GeoSeries - return city + return gdf def overpass_pois(bounds, facilities=None, custom_query=None): From b0aae31dbe8e711eb09da26bc3066ae9e6ae0adb Mon Sep 17 00:00:00 2001 From: Claudio Ortega Date: Fri, 10 Nov 2023 17:27:00 +0000 Subject: [PATCH 2/3] use string for python 3.9 compat --- urbanpy/download/download.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/urbanpy/download/download.py b/urbanpy/download/download.py index 25c8ead..e8d03ae 100644 --- a/urbanpy/download/download.py +++ b/urbanpy/download/download.py @@ -35,7 +35,7 @@ ) -def nominatim_osm(query: str, expected_position: int | None = 0) -> GeoDataFrame: +def nominatim_osm(query: str, expected_position: "int | None" = 0) -> GeoDataFrame: """ Download OpenStreetMaps data for a specific city. From c54b67edd6e72a315d9425db1cf20b6e7a9c3ceb Mon Sep 17 00:00:00 2001 From: Claudio Ortega Date: Fri, 10 Nov 2023 17:37:08 +0000 Subject: [PATCH 3/3] check if param is None --- urbanpy/download/download.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/urbanpy/download/download.py b/urbanpy/download/download.py index e8d03ae..b420db2 100644 --- a/urbanpy/download/download.py +++ b/urbanpy/download/download.py @@ -67,10 +67,10 @@ def nominatim_osm(query: str, expected_position: "int | None" = 0) -> GeoDataFra response = requests.get(osm_url, params=osm_parameters) all_results = response.json() gdf = gpd.GeoDataFrame.from_features(all_results["features"], crs="EPSG:4326") - if expected_position: - return gdf.iloc[expected_position : expected_position + 1] # this returns a GeoDataFrame instead of GeoSeries - - return gdf + if expected_position is None: + return gdf + + return gdf.iloc[expected_position : expected_position + 1] def overpass_pois(bounds, facilities=None, custom_query=None):