{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "[![image](https://colab.research.google.com/assets/colab-badge.svg)](https://githubtocolab.com/gee-community/geemap/blob/master/examples/notebooks/84_openstreetmap.ipynb)\n", "[![image](https://mybinder.org/badge_logo.svg)](https://gishub.org/geemap-binder)\n", "\n", "**Downloading OpenStreetMap data with a single line of code**\n", "\n", "Uncomment the following line to install [geemap](https://geemap.org) if needed." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# !pip install geopandas osmnx geemap" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import geemap.foliumap as geemap" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add OSM data of place(s) by name or ID to the map. Note that the geemap custom layer control does not support GeoJSON, we need to use the ipyleaflet built-in layer control." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(toolbar_control=False, layers_control=True)\n", "m.add_osm_from_geocode(\"New York City\", layer_name='NYC')\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(toolbar_control=False, layers_control=True)\n", "m.add_osm_from_geocode(\"Chicago, Illinois\", layer_name='Chicago, IL')\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add OSM entities within boundaries of geocodable place(s) to the map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(toolbar_control=False, layers_control=True)\n", "place = \"Bunker Hill, Los Angeles, California\"\n", "tags = {\"building\": True}\n", "m.add_osm_from_place(place, tags, layer_name=\"Los Angeles, CA\")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Show OSM feature tags.\n", "\n", "https://wiki.openstreetmap.org/wiki/Map_features" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# geemap.osm_tags_list()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add OSM entities within some distance N, S, E, W of address to the map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(toolbar_control=False, layers_control=True)\n", "m.add_osm_from_address(\n", " address=\"New York City\", tags={\"amenity\": \"bar\"}, dist=1500, layer_name=\"NYC bars\"\n", ")\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(toolbar_control=False, layers_control=True)\n", "m.add_osm_from_address(\n", " address=\"New York City\",\n", " tags={\"landuse\": [\"retail\", \"commercial\"], \"building\": True},\n", " dist=1000,\n", " layer_name=\"NYC buildings\",\n", ")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add OSM entities within a N, S, E, W bounding box to the map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(toolbar_control=False, layers_control=True)\n", "north, south, east, west = 40.7551, 40.7454, -73.9738, -73.9965\n", "m.add_osm_from_bbox(\n", " north, south, east, west, tags={\"amenity\": \"bar\"}, layer_name=\"NYC bars\"\n", ")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add OSM entities within some distance N, S, E, W of a point to the map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(\n", " center=[46.7808, -96.0156], zoom=12, toolbar_control=False, layers_control=True\n", ")\n", "m.add_osm_from_point(\n", " center_point=(46.7808, -96.0156),\n", " tags={\"natural\": \"water\"},\n", " dist=10000,\n", " layer_name=\"Lakes\",\n", ")\n", "m" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(\n", " center=[39.9170, 116.3908], zoom=15, toolbar_control=False, layers_control=True\n", ")\n", "m.add_osm_from_point(\n", " center_point=(39.9170, 116.3908),\n", " tags={\"building\": True, \"natural\": \"water\"},\n", " dist=1000,\n", " layer_name=\"Beijing\",\n", ")\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Add OSM entities within the current map view to the map." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "m = geemap.Map(toolbar_control=False, layers_control=True)\n", "m.set_center(-73.9854, 40.7500, 16)\n", "m" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The `add_osm_from_view()` is only available for the ipyleaflet plotting backend." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# m.add_osm_from_view(tags={\"amenity\": \"bar\", \"building\": True}, layer_name=\"New York\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Create a GeoPandas GeoDataFrame from place." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gdf = geemap.osm_gdf_from_place(\"New York City\", tags={\"amenity\": \"bar\"})\n", "gdf" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" } }, "nbformat": 4, "nbformat_minor": 5 }