Skip to content

Commit

Permalink
Update w09_advanced.html
Browse files Browse the repository at this point in the history
  • Loading branch information
g-filomena committed Apr 16, 2024
1 parent e59d470 commit 821686d
Showing 1 changed file with 24 additions and 27 deletions.
51 changes: 24 additions & 27 deletions docs/labs/w09_advanced.html
Original file line number Diff line number Diff line change
Expand Up @@ -321,27 +321,22 @@ <h2 data-number="8.1" class="anchored" data-anchor-id="getting-gps-trajectories-
<p>This first part of the notebook has been readapted from this <a href="https://github.com/movingpandas/movingpandas-examples/blob/main/2-analysis-examples/osm-traces.ipynb">notebook</a> created by Anita Graser.</p>
<section id="downaloding-gps-traces-from-the-openstreetmap" class="level3" data-number="8.1.1">
<h3 data-number="8.1.1" class="anchored" data-anchor-id="downaloding-gps-traces-from-the-openstreetmap"><span class="header-section-number">8.1.1</span> Downaloding GPS traces from the OpenStreetMap</h3>
<div id="cell-6" class="cell" data-execution_count="3">
<div class="sourceCode cell-code" id="cb3"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> bbox_to_osm_format(bbox):</span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a> <span class="co">"""</span></span>
<span id="cb3-3"><a href="#cb3-3" aria-hidden="true" tabindex="-1"></a><span class="co"> Convert bounding box coordinates to OSM API format.</span></span>
<span id="cb3-4"><a href="#cb3-4" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-5"><a href="#cb3-5" aria-hidden="true" tabindex="-1"></a><span class="co"> Parameters</span></span>
<span id="cb3-6"><a href="#cb3-6" aria-hidden="true" tabindex="-1"></a><span class="co"> ----------</span></span>
<span id="cb3-7"><a href="#cb3-7" aria-hidden="true" tabindex="-1"></a><span class="co"> bbox: tuple</span></span>
<span id="cb3-8"><a href="#cb3-8" aria-hidden="true" tabindex="-1"></a><span class="co"> A tuple containing the bounding box coordinates in the order (north, south, east, west).</span></span>
<span id="cb3-9"><a href="#cb3-9" aria-hidden="true" tabindex="-1"></a></span>
<span id="cb3-10"><a href="#cb3-10" aria-hidden="true" tabindex="-1"></a><span class="co"> Returns</span></span>
<span id="cb3-11"><a href="#cb3-11" aria-hidden="true" tabindex="-1"></a><span class="co"> -------</span></span>
<span id="cb3-12"><a href="#cb3-12" aria-hidden="true" tabindex="-1"></a><span class="co"> bbox_str: str</span></span>
<span id="cb3-13"><a href="#cb3-13" aria-hidden="true" tabindex="-1"></a><span class="co"> A string representing the bounding box in the format "west,south,east,north".</span></span>
<span id="cb3-14"><a href="#cb3-14" aria-hidden="true" tabindex="-1"></a><span class="co"> """</span></span>
<span id="cb3-15"><a href="#cb3-15" aria-hidden="true" tabindex="-1"></a> north, south, east, west <span class="op">=</span> bbox</span>
<span id="cb3-16"><a href="#cb3-16" aria-hidden="true" tabindex="-1"></a> bbox <span class="op">=</span> <span class="ss">f"</span><span class="sc">{</span>west<span class="sc">}</span><span class="ss">,</span><span class="sc">{</span>south<span class="sc">}</span><span class="ss">,</span><span class="sc">{</span>east<span class="sc">}</span><span class="ss">,</span><span class="sc">{</span>north<span class="sc">}</span><span class="ss">"</span></span>
<span id="cb3-17"><a href="#cb3-17" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> bbox</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>Now trying to get data around Liverpool Campus. Feel free to change area.</p>
<div id="cell-8" class="cell" data-execution_count="4">
<p>def bbox_to_osm_format(bbox): ““” Convert bounding box coordinates to OSM API format.</p>
<pre><code>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</code></pre>
<p>We can try to get OSM traces around the Uni of Liverpool Campus. Feel free to change the area.</p>
<div id="cell-7" class="cell" data-execution_count="4">
<div class="sourceCode cell-code" id="cb4"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb4-1"><a href="#cb4-1" aria-hidden="true" tabindex="-1"></a><span class="im">import</span> osmnx <span class="im">as</span> ox</span>
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="co"># Define the place name</span></span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a>place_name <span class="op">=</span> <span class="st">"University of Liverpool, UK"</span></span>
Expand All @@ -353,6 +348,8 @@ <h3 data-number="8.1.1" class="anchored" data-anchor-id="downaloding-gps-traces-
<span id="cb4-9"><a href="#cb4-9" aria-hidden="true" tabindex="-1"></a>bbox <span class="op">=</span> ox.utils_geo.bbox_from_point((latitude, longitude), dist <span class="op">=</span> <span class="dv">1500</span>)</span>
<span id="cb4-10"><a href="#cb4-10" aria-hidden="true" tabindex="-1"></a>bbox <span class="op">=</span> bbox_to_osm_format(bbox) <span class="co"># needs to be {west},{south},{east},{north} for OSM Api</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>The <code>get_osm_traces</code> 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.</p>
<p>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.</p>
<div id="cell-9" class="cell" data-execution_count="5">
<div class="sourceCode cell-code" id="cb5"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="kw">def</span> get_osm_traces(max_pages <span class="op">=</span> <span class="dv">2</span>, bbox<span class="op">=</span><span class="st">'16.18, 48.09, 16.61, 48.32'</span>):</span>
<span id="cb5-2"><a href="#cb5-2" aria-hidden="true" tabindex="-1"></a> <span class="co">"""</span></span>
Expand Down Expand Up @@ -407,7 +404,7 @@ <h3 data-number="8.1.1" class="anchored" data-anchor-id="downaloding-gps-traces-
<span id="cb5-51"><a href="#cb5-51" aria-hidden="true" tabindex="-1"></a> final_gdf <span class="op">=</span> final_gdf.drop(columns<span class="op">=</span>[col <span class="cf">for</span> col <span class="kw">in</span> columns_to_drop <span class="cf">if</span> col <span class="kw">in</span> final_gdf.columns])</span>
<span id="cb5-52"><a href="#cb5-52" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> final_gdf</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
<p>We initial download 2 pages of GSP traces. We can try with higher numbers to get more data. More recent traces are downloaded first.</p>
<p>We initially download 2 pages of GSP traces. We can try with higher numbers to get more data. More recent traces are downloaded first.</p>
<div id="cell-11" class="cell" data-execution_count="6">
<div class="sourceCode cell-code" id="cb6"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb6-1"><a href="#cb6-1" aria-hidden="true" tabindex="-1"></a>max_pages <span class="op">=</span> <span class="dv">2</span> <span class="co"># pages of data, </span></span>
<span id="cb6-2"><a href="#cb6-2" aria-hidden="true" tabindex="-1"></a>gps_track_points <span class="op">=</span> get_osm_traces(max_pages, bbox)</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
Expand Down Expand Up @@ -481,7 +478,7 @@ <h3 data-number="8.1.1" class="anchored" data-anchor-id="downaloding-gps-traces-
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="w09_advanced_files/figure-html/cell-10-output-1.png" class="img-fluid figure-img"></p>
<p><img src="w09_advanced_files/figure-html/cell-8-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
Expand Down Expand Up @@ -1259,7 +1256,7 @@ <h3 data-number="8.1.2" class="anchored" data-anchor-id="transform-the-point-geo
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="w09_advanced_files/figure-html/cell-16-output-1.png" class="img-fluid figure-img"></p>
<p><img src="w09_advanced_files/figure-html/cell-14-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
Expand All @@ -1272,8 +1269,8 @@ <h3 data-number="8.1.2" class="anchored" data-anchor-id="transform-the-point-geo
</section>
<section id="animations-in-folium" class="level2" data-number="8.2">
<h2 data-number="8.2" class="anchored" data-anchor-id="animations-in-folium"><span class="header-section-number">8.2</span> Animations in Folium</h2>
<section id="animating-a-gps-track" class="level3" data-number="8.2.1">
<h3 data-number="8.2.1" class="anchored" data-anchor-id="animating-a-gps-track"><span class="header-section-number">8.2.1</span> Animating a GPS track</h3>
<section id="animating-gps-tracks" class="level3" data-number="8.2.1">
<h3 data-number="8.2.1" class="anchored" data-anchor-id="animating-gps-tracks"><span class="header-section-number">8.2.1</span> Animating GPS tracks</h3>
<div id="cell-28" class="cell" data-execution_count="15">
<div class="sourceCode cell-code" id="cb17"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a><span class="im">from</span> folium.plugins <span class="im">import</span> TimestampedGeoJson</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</div>
Expand All @@ -1287,7 +1284,7 @@ <h3 data-number="8.2.1" class="anchored" data-anchor-id="animating-a-gps-track">
<div class="cell-output cell-output-display">
<div>
<figure class="figure">
<p><img src="w09_advanced_files/figure-html/cell-18-output-1.png" class="img-fluid figure-img"></p>
<p><img src="w09_advanced_files/figure-html/cell-16-output-1.png" class="img-fluid figure-img"></p>
</figure>
</div>
</div>
Expand Down

0 comments on commit 821686d

Please sign in to comment.