From e3e4154b93479c829a3164c9d68009bc4a811854 Mon Sep 17 00:00:00 2001 From: Gabriele Filomena Date: Tue, 16 Apr 2024 12:56:30 +0100 Subject: [PATCH] Update w09_advanced.ipynb --- labs/w09_advanced.ipynb | 88 +++++++++++++++++++++++++++++------------ 1 file changed, 63 insertions(+), 25 deletions(-) diff --git a/labs/w09_advanced.ipynb b/labs/w09_advanced.ipynb index 985f4d4..ddf7424 100644 --- a/labs/w09_advanced.ipynb +++ b/labs/w09_advanced.ipynb @@ -36,7 +36,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -72,14 +72,57 @@ "\n", "It's not possible to download traces from OSM using `OSMnx`. One has to script their own code\n", "\n", - "This first part of the notebook has been readapted from this [notebook](https://github.com/movingpandas/movingpandas-examples/blob/main/2-analysis-examples/osm-traces.ipynb) created by Anita Graser.\n", + "Parts of this section of the notebook have been readapted from this [notebook](https://github.com/movingpandas/movingpandas-examples/blob/main/2-analysis-examples/osm-traces.ipynb) created by Anita Graser.\n", + "\n", + "### Downaloding GPS traces from the OpenStreetMap\n", + "\n", + "We can try to get OSM traces around the Uni of Liverpool Campus. Feel free to change the area." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(53.420732655032396,\n", + " 53.39375304496761,\n", + " -2.9432044446907044,\n", + " -2.988462877347038)" + ] + }, + "execution_count": 2, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "import osmnx as ox\n", + "# Define the place name\n", + "place_name = \"University of Liverpool, UK\"\n", + "\n", + "# Get the latitude and longitude\n", + "latitude, longitude = ox.geocoder.geocode(place_name)\n", "\n", - "### Downaloding GPS traces from the OpenStreetMap" + "# Create the bbox\n", + "bbox = ox.utils_geo.bbox_from_point((latitude, longitude), dist = 1500)\n", + "bbox" ] }, { "cell_type": "markdown", "metadata": {}, + "source": [ + "We need the `bbox_to_osm_format` function below to convert our bounding box coordinates into the format required by the OpenStreetMap (OSM) API. The input tuple contains coordinates in the order (north, south, east, west). The function rearranges these values into the string \"west,south,east,north\", which is the format expected by OSM for API queries. " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], "source": [ "def bbox_to_osm_format(bbox):\n", " \"\"\"\n", @@ -97,32 +140,28 @@ " \"\"\"\n", " north, south, east, west = bbox\n", " bbox = f\"{west},{south},{east},{north}\"\n", - " return bbox\n" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "We can try to get OSM traces around the Uni of Liverpool Campus. Feel free to change the area." + " return bbox" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'-2.988462877347038,53.39375304496761,-2.9432044446907044,53.420732655032396'" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "import osmnx as ox\n", - "# Define the place name\n", - "place_name = \"University of Liverpool, UK\"\n", - "\n", - "# Get the latitude and longitude\n", - "latitude, longitude = ox.geocoder.geocode(place_name)\n", - "\n", - "# Create the bbox\n", - "bbox = ox.utils_geo.bbox_from_point((latitude, longitude), dist = 1500)\n", - "bbox = bbox_to_osm_format(bbox) # needs to be {west},{south},{east},{north} for OSM Api" + "bbox = bbox_to_osm_format(bbox) # needs to be {west},{south},{east},{north} for OSM Api\n", + "bbox" ] }, { @@ -1312,15 +1351,14 @@ "source": [ "crs = 'EPSG:27700'\n", "gps_tracks = osm_traces.to_traj_gdf()\n", - "gps_tracks = gps_tracks.set_crs(\"EPSG:4326\").to_crs(crs)\n", - "gps_tracks.plot()" + "gps_tracks = gps_tracks.set_crs(\"EPSG:4326\").to_crs(crs)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "As you can see, from both visualisations, OSM traces may include also odd traces that jump from different locations of the city.\n", + "As you can see, from the map above, OSM traces may include also odd traces that jump from different locations of the city.\n", "\n", "
\n", "\n",