diff --git a/docs/notebooks/97_overture_data.ipynb b/docs/notebooks/97_overture_data.ipynb new file mode 100644 index 0000000000..4888da35c9 --- /dev/null +++ b/docs/notebooks/97_overture_data.ipynb @@ -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 +} diff --git a/docs/tutorials.md b/docs/tutorials.md index 23cf84a141..57440c18d7 100644 --- a/docs/tutorials.md +++ b/docs/tutorials.md @@ -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 diff --git a/examples/README.md b/examples/README.md index 016983c067..6c02488628 100644 --- a/examples/README.md +++ b/examples/README.md @@ -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 diff --git a/leafmap/common.py b/leafmap/common.py index 0d7c5a28c9..94e9ad289c 100644 --- a/leafmap/common.py +++ b/leafmap/common.py @@ -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 diff --git a/requirements_dev.txt b/requirements_dev.txt index 731c2ec468..099dd6e000 100644 --- a/requirements_dev.txt +++ b/requirements_dev.txt @@ -23,6 +23,7 @@ maplibre mss netcdf4 osmnx +overturemaps owslib palettable panel