Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to get all results in download.nominatim osm function #32

Merged
merged 3 commits into from
Nov 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 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, :]

return city
if expected_position is None:
return gdf

return gdf.iloc[expected_position : expected_position + 1]


def overpass_pois(bounds, facilities=None, custom_query=None):
Expand Down