Skip to content

Commit

Permalink
Add option to return all results
Browse files Browse the repository at this point in the history
  • Loading branch information
Claudio9701 committed Nov 10, 2023
1 parent ab43196 commit bd0bff0
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions urbanpy/download/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------
Expand All @@ -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):
Expand Down

0 comments on commit bd0bff0

Please sign in to comment.