{ "cells": [ { "cell_type": "markdown", "id": "e87bd72c", "metadata": {}, "source": [ "\n", "\n", "----------------\n", "\n", "```{admonition} Learning Objectives\n", "- Download and utilize OpenStreetMap data\n", "```\n", "```{admonition} Review\n", "* [Understanding CRS codes](d_understand_crs_codes.md)\n", "* [Creating Points, Lines, Polygons](c_new_vectors.md)\n", "```\n", "----------------\n", "\n", "# Accessing OSM Data in Python\n", "\n", "## What is OpenStreetMap?\n", "\n", "OpenStreetMap (OSM) is a global collaborative (crowd-sourced) dataset and project that aims at creating a free editable map of the world containing a lot of information about our environment [^gpd_clip]. It contains data for example about streets, buildings, different services, and landuse to mention a few. You can view the map at www.openstreetmap.org. You can also sign up as a contributor if you want to edit the map. More details about OpenStreetMap and its contents are available in the [OpenStreetMap Wiki](https://wiki.openstreetmap.org/wiki/Main_Page).\n", "\n", "## OSMnx\n", "\n", "This week we will explore a Python module called [OSMnx](https://github.com/gboeing/osmnx)\n", "that can be used to retrieve, construct, analyze, and visualize street networks from OpenStreetMap, and also retrieve data about Points of Interest such as restaurants, schools, and lots of different kind of services. It is also easy to conduct network routing based on walking, cycling or driving by combining OSMnx functionalities with a package called [NetworkX](https://networkx.github.io/documentation/stable/).\n", "\n", "To get an overview of the capabilities of the package, see an introductory video given by the lead developer of the package, Prof. Geoff Boeing: [\"Meet the developer: Introduction to OSMnx package by Geoff Boeing\"](https://www.youtube.com/watch?v=Q0uxu25ddc4&list=PLs9D4XVqc6dCAhhvhZB7aHGD8fCeCC_6N).\n", "\n", "## Download and visualize OpenStreetMap data with OSMnx\n", "\n", "One the most useful features that OSMnx provides is an easy-to-use way of retrieving [OpenStreetMap](http://www.openstreetmap.org) data (using [OverPass API](http://wiki.openstreetmap.org/wiki/Overpass_API)).\n", "\n", "In this tutorial, we will learn how to download and visualize OSM data covering a specified area of interest: the neighborhood of Edgewood in Washington DC USA." ] }, { "cell_type": "code", "execution_count": 1, "id": "bb0d67f4", "metadata": {}, "outputs": [], "source": [ "# Specify the name that is used to seach for the data\n", "place_name = \"Edgewood Washington, DC, USA\"" ] }, { "cell_type": "markdown", "id": "9fedad6d", "metadata": {}, "source": [ "### OSM Location Boundary\n", "\n", "Let's also plot the Polygon that represents the boundary of our area of interest (Washington DC). We can retrieve the Polygon geometry using the `ox.geocode_to_gdf` [docs](https://osmnx.readthedocs.io/en/stable/osmnx.html?highlight=geocode_to_gdf(#osmnx.geocoder.geocode_to_gdf) function." ] }, { "cell_type": "code", "execution_count": 2, "id": "bb64f848", "metadata": {}, "outputs": [], "source": [ "# import osmnx\n", "import osmnx as ox\n", "import geopandas as gpd\n", "\n", "# Get place boundary related to the place name as a geodataframe\n", "area = ox.geocode_to_gdf(place_name)" ] }, { "cell_type": "markdown", "id": "c015cbd2", "metadata": {}, "source": [ "As the name of the function already tells us, `gdf_from_place()`returns a GeoDataFrame based on the specified place name query." ] }, { "cell_type": "code", "execution_count": 3, "id": "b95c2068", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " | geometry | \n", "bbox_north | \n", "bbox_south | \n", "bbox_east | \n", "bbox_west | \n", "place_id | \n", "osm_type | \n", "osm_id | \n", "lat | \n", "lon | \n", "display_name | \n", "class | \n", "type | \n", "importance | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
0 | \n", "POLYGON ((-77.00892 38.92123, -77.00890 38.920... | \n", "38.934159 | \n", "38.917008 | \n", "-76.99358 | \n", "-77.008915 | \n", "282956700 | \n", "relation | \n", "4634158 | \n", "38.922613 | \n", "-77.000537 | \n", "Edgewood, Washington, District of Columbia, Un... | \n", "place | \n", "neighbourhood | \n", "0.47 | \n", "
\n", " | \n", " | addr:state | \n", "amenity | \n", "building | \n", "ele | \n", "gnis:county_id | \n", "gnis:county_name | \n", "gnis:created | \n", "gnis:edited | \n", "gnis:feature_id | \n", "gnis:import_uuid | \n", "... | \n", "shop | \n", "denomination | \n", "old_name | \n", "url | \n", "wikidata | \n", "office | \n", "short_name | \n", "shelter_type | \n", "ways | \n", "type | \n", "
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
element_type | \n", "osmid | \n", "\n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " | \n", " |
node | \n", "358955022 | \n", "DC | \n", "school | \n", "yes | \n", "60 | \n", "001 | \n", "District of Columbia | \n", "12/18/1979 | \n", "01/22/2008 | \n", "2062869 | \n", "57871b70-0100-4405-bb30-88b2e001a944 | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
367143640 | \n", "DC | \n", "NaN | \n", "yes | \n", "56 | \n", "NaN | \n", "District of Columbia | \n", "NaN | \n", "NaN | \n", "2110453 | \n", "57871b70-0100-4405-bb30-88b2e001a944 | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "|
way | \n", "52291432 | \n", "NaN | \n", "NaN | \n", "yes | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
55321503 | \n", "NaN | \n", "NaN | \n", "yes | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "|
55321504 | \n", "DC | \n", "NaN | \n", "yes | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "... | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "NaN | \n", "
5 rows × 55 columns
\n", "