8.1.1 Downaloding GPS traces from the OpenStreetMap
-
-
def bbox_to_osm_format(bbox):
-"""
- Convert bounding box coordinates to OSM API format.
-
- Parameters
- ----------
- bbox: tuple
- A tuple containing the bounding box coordinates in the order (north, south, east, west).
-
- Returns
- -------
- bbox_str: str
- A string representing the bounding box in the format "west,south,east,north".
- """
- north, south, east, west = bbox
- bbox =f"{west},{south},{east},{north}"
-return bbox
-
-
Now trying to get data around Liverpool Campus. Feel free to change area.
-
+
def bbox_to_osm_format(bbox): ““” Convert bounding box coordinates to OSM API format.
+
Parameters
+----------
+bbox: tuple
+ A tuple containing the bounding box coordinates in the order (north, south, east, west).
+
+Returns
+-------
+bbox_str: str
+ A string representing the bounding box in the format "west,south,east,north".
+"""
+north, south, east, west = bbox
+bbox = f"{west},{south},{east},{north}"
+return bbox
+
We can try to get OSM traces around the Uni of Liverpool Campus. Feel free to change the area.
+
import osmnx as ox# Define the place nameplace_name ="University of Liverpool, UK"
@@ -353,6 +348,8 @@
bbox = ox.utils_geo.bbox_from_point((latitude, longitude), dist =1500)
bbox = bbox_to_osm_format(bbox) # needs to be {west},{south},{east},{north} for OSM Api
+
The get_osm_traces function below retrieves GPS traces from OpenStreetMap within a specified bounding box, processing up to a user-defined maximum number of pages. It uses a while loop to fetch and parse GPS data into GeoDataFrames, querying the OSM API by incrementally updating the page number until no more data is available or the maximum page limit is reached.
+
Upon fetching the data, the function concatenates these individual GeoDataFrames into a single comprehensive GeoDataFrame. Before returning the final GeoDataFrame, it cleans the dataset by dropping a predefined list of potentially irrelevant or empty columns.