Skip to content

Commit

Permalink
Add support for downloading overture maps data (#890)
Browse files Browse the repository at this point in the history
* Add support for downloading overture maps data

* Fix docs build error
  • Loading branch information
giswqs authored Sep 20, 2024
1 parent 2b6dfad commit 5576ea1
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 0 deletions.
182 changes: 182 additions & 0 deletions docs/notebooks/97_overture_data.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "0",
"metadata": {},
"source": [
"[![image](https://jupyterlite.rtfd.io/en/latest/_static/badge.svg)](https://demo.leafmap.org/lab/index.html?path=notebooks/97_overture_data.ipynb)\n",
"[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/opengeos/leafmap/blob/master/docs/notebooks/97_overture_data.ipynb)\n",
"[![image](https://mybinder.org/badge_logo.svg)](https://mybinder.org/v2/gh/opengeos/leafmap/HEAD)\n",
"\n",
"**Download Overture Maps Data**\n",
"\n",
"Uncomment the following line to install [leafmap](https://leafmap.org) if needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1",
"metadata": {},
"outputs": [],
"source": [
"# %pip install -U leafmap overturemaps"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2",
"metadata": {},
"outputs": [],
"source": [
"from leafmap import leafmap"
]
},
{
"cell_type": "markdown",
"id": "3",
"metadata": {},
"source": [
"Create an interactive map."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "4",
"metadata": {},
"outputs": [],
"source": [
"m = leafmap.Map(center=[36.120725, -115.203795], zoom=17)\n",
"m.add_basemap(\"SATELLITE\")\n",
"m"
]
},
{
"cell_type": "markdown",
"id": "5",
"metadata": {},
"source": [
"Draw a rectangle on the map to download the data within the rectangle."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6",
"metadata": {},
"outputs": [],
"source": [
"if m.user_roi is not None:\n",
" bbox = m.user_roi_coords()\n",
"else:\n",
" bbox = [-115.2081, 36.119, -115.1994, 36.1226]"
]
},
{
"cell_type": "markdown",
"id": "7",
"metadata": {},
"source": [
"Download Overature Maps building data."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8",
"metadata": {},
"outputs": [],
"source": [
"columns = [\"id\", \"height\", \"geometry\"]\n",
"output = \"buildings.geojson\"\n",
"buildings_gdf = leafmap.get_overture_data(\n",
" \"building\", bbox=bbox, columns=columns, output=output\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9",
"metadata": {},
"outputs": [],
"source": [
"m.add_gdf(buildings_gdf, layer_name=\"Buildings\")"
]
},
{
"cell_type": "markdown",
"id": "10",
"metadata": {},
"source": [
"Download Overature Maps transportation data."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "11",
"metadata": {},
"outputs": [],
"source": [
"output = \"roads.geojson\"\n",
"columns = [\"id\", \"subtype\", \"class\", \"geometry\"]\n",
"roads_gdf = leafmap.get_overture_data(\n",
" \"segment\", bbox=bbox, columns=columns, output=output\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "12",
"metadata": {},
"outputs": [],
"source": [
"m.add_gdf(roads_gdf, layer_name=\"Roads\", style={\"color\": \"red\", \"weight\": 2})"
]
},
{
"cell_type": "markdown",
"id": "13",
"metadata": {},
"source": [
"The overture maps data type can be one of the following:\n",
"\n",
"address|building|building_part|division|division_area|division_boundary|place|segment|connector|infrastructure|land|land_cover|land_use|water"
]
},
{
"cell_type": "markdown",
"id": "14",
"metadata": {},
"source": [
"![image](https://github.com/user-attachments/assets/e584348b-5e36-425b-9d39-8f436b7477a3)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "geo",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
1 change: 1 addition & 0 deletions docs/tutorials.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
94. Creating 3D maps with Mapbox ([notebook](https://leafmap.org/notebooks/94_mapbox))
95. Editing vector data interactively ([notebook](https://leafmap.org/notebooks/95_edit_vector))
96. Batch editing vector data attributes interactively ([notebook](https://leafmap.org/notebooks/96_batch_edit_vector))
97. Downloading Overture Maps data ([notebook](https://leafmap.org/notebooks/97_overture_data))

## Demo

Expand Down
2 changes: 2 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
93. Visualizing PMTiles with Leafmap and MapLibre ([notebook](https://leafmap.org/notebooks/93_maplibre_pmtiles))
94. Creating 3D maps with Mapbox ([notebook](https://leafmap.org/notebooks/94_mapbox))
95. Editing vector data interactively ([notebook](https://leafmap.org/notebooks/95_edit_vector))
96. Batch editing vector data attributes interactively ([notebook](https://leafmap.org/notebooks/96_batch_edit_vector))
97. Downloading Overture Maps data ([notebook](https://leafmap.org/notebooks/97_overture_data))

## Demo

Expand Down
43 changes: 43 additions & 0 deletions leafmap/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -14220,3 +14220,46 @@ def read_file(data: str, **kwargs: Any) -> Union[pd.DataFrame, "gpd.GeoDataFrame
)

return df


def get_overture_data(
overture_type: str,
bbox: Tuple[float, float, float, float] = None,
columns: List[str] = None,
output: str = None,
) -> "gpd.GeoDataFrame":
"""Fetches overture data and returns it as a GeoDataFrame.
Args:
overture_type (str): The type of overture data to fetch.It can be one of the following:
address|building|building_part|division|division_area|division_boundary|place|
segment|connector|infrastructure|land|land_cover|land_use|water
bbox (Tuple[float, float, float, float], optional): The bounding box to
filter the data. Defaults to None.
columns (List[str], optional): The columns to include in the output.
Defaults to None.
output (str, optional): The file path to save the output GeoDataFrame.
Defaults to None.
Returns:
gpd.GeoDataFrame: The fetched overture data as a GeoDataFrame.
Raises:
ImportError: If the overture package is not installed.
"""

try:
from overturemaps import core
except ImportError:
install_package("overture")
from overturemaps import core

gdf = core.geodataframe(overture_type, bbox=bbox)
if columns is not None:
gdf = gdf[columns]

gdf.crs = "EPSG:4326"
if output is not None:
gdf.to_file(output)

return gdf
1 change: 1 addition & 0 deletions requirements_dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ maplibre
mss
netcdf4
osmnx
overturemaps
owslib
palettable
panel
Expand Down

0 comments on commit 5576ea1

Please sign in to comment.