Skip to content

Commit

Permalink
Deploy commit: Minor change to test #183 solution dc6ec89
Browse files Browse the repository at this point in the history
  • Loading branch information
Robinlovelace committed Aug 11, 2023
1 parent fe36000 commit ce98011
Show file tree
Hide file tree
Showing 24 changed files with 3,339 additions and 282 deletions.
272 changes: 136 additions & 136 deletions 02-spatial-data.html

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions 03-attribute-operations.html
Original file line number Diff line number Diff line change
Expand Up @@ -303,14 +303,14 @@ <h2 data-number="2.1" class="anchored" data-anchor-id="prerequisites"><span clas
</section>
<section id="introduction" class="level2" data-number="2.2">
<h2 data-number="2.2" class="anchored" data-anchor-id="introduction"><span class="header-section-number">2.2</span> Introduction</h2>
<p>Attribute data is non-spatial information associated with geographic (geometry) data. A bus stop provides a simple example: its position would typically be represented by latitude and longitude coordinates (geometry data), in addition to its name. The Elephant &amp; Castle / New Kent Road stop in London, for example has coordinates of <code>-0.098</code> degrees longitude and <code>51.495</code> degrees latitude which can be represented as <code>POINT (-0.098 51.495)</code> in the Simple Feature representation described in <a href="#sec-spatial-class"><span class="quarto-unresolved-ref">sec-spatial-class</span></a>. Attributes such as the name attribute of the <code>POINT</code> feature (to use Simple Features terminology) are the topic of this chapter.</p>
<p>Attribute data is non-spatial information associated with geographic (geometry) data. A bus stop provides a simple example: its position would typically be represented by latitude and longitude coordinates (geometry data), in addition to its name. The Elephant &amp; Castle / New Kent Road stop in London, for example has coordinates of <code>-0.098</code> degrees longitude and <code>51.495</code> degrees latitude which can be represented as <code>POINT (-0.098 51.495)</code> in the Simple Feature representation described in <a href="02-spatial-data.html"><span>Chapter&nbsp;1</span></a>. Attributes such as the name attribute of the <code>POINT</code> feature (to use Simple Features terminology) are the topic of this chapter.</p>
<p>Another example is the elevation value (attribute) for a specific grid cell in raster data. Unlike the vector data model, the raster data model stores the coordinate of the grid cell indirectly, meaning the distinction between attribute and spatial information is less clear. To illustrate the point, think of a pixel in the 3rd row and the 4th column of a raster matrix. Its spatial location is defined by its index in the matrix: move from the origin four cells in the x direction (typically east and right on maps) and three cells in the y direction (typically south and down). The raster’s resolution defines the distance for each x- and y-step which is specified in a header. The header is a vital component of raster datasets which specifies how pixels relate to geographic coordinates (see also Chapter <span class="citation" data-cites="spatial-operations">@spatial-operations</span>).</p>
<p>This chapter teaches how to manipulate geographic objects based on attributes such as the names of bus stops in a vector dataset and elevations of pixels in a raster dataset. For vector data, this means techniques such as subsetting and aggregation (see <a href="#sec-vector-attribute-subsetting"><span class="quarto-unresolved-ref">sec-vector-attribute-subsetting</span></a> and <a href="#sec-vector-attribute-aggregation"><span class="quarto-unresolved-ref">sec-vector-attribute-aggregation</span></a>). <a href="#sec-vector-attribute-joining"><span class="quarto-unresolved-ref">sec-vector-attribute-joining</span></a> and <a href="#sec-creating-attributes-and-removing-spatial-information"><span class="quarto-unresolved-ref">sec-creating-attributes-and-removing-spatial-information</span></a> demonstrate how to join data onto simple feature objects using a shared ID and how to create new variables, respectively. Each of these operations has a spatial equivalent: <code>[</code> operator for subsetting a <code>(Geo)DataFrame</code> using a boolean <code>Series</code>, for example, is applicable both for subsetting objects based on their attribute and spatial relations derived using methods such as <code>.intersects</code>; you can also join attributes in two geographic datasets using spatial joins. This is good news: skills developed in this chapter are cross-transferable. <a href="#sec-spatial-operations"><span class="quarto-unresolved-ref">sec-spatial-operations</span></a> extends the methods presented here to the spatial world.</p>
<p>After a deep dive into various types of vector attribute operations in the next section, raster attribute data operations are covered in <a href="#sec-manipulating-raster-objects"><span class="quarto-unresolved-ref">sec-manipulating-raster-objects</span></a>, which demonstrates how to create raster layers containing continuous and categorical attributes and extracting cell values from one or more layer (raster subsetting). <a href="#sec-summarizing-raster-objects"><span class="quarto-unresolved-ref">sec-summarizing-raster-objects</span></a> provides an overview of ‘global’ raster operations which can be used to summarize entire raster datasets.</p>
<p>This chapter teaches how to manipulate geographic objects based on attributes such as the names of bus stops in a vector dataset and elevations of pixels in a raster dataset. For vector data, this means techniques such as subsetting and aggregation (see <a href="#sec-vector-attribute-subsetting"><span>Section&nbsp;2.3.1</span></a> and <a href="#sec-vector-attribute-aggregation"><span>Section&nbsp;2.3.2</span></a>). <a href="#sec-vector-attribute-joining"><span>Section&nbsp;2.3.3</span></a> and <a href="#sec-creating-attributes-and-removing-spatial-information"><span>Section&nbsp;2.3.4</span></a> demonstrate how to join data onto simple feature objects using a shared ID and how to create new variables, respectively. Each of these operations has a spatial equivalent: <code>[</code> operator for subsetting a <code>(Geo)DataFrame</code> using a boolean <code>Series</code>, for example, is applicable both for subsetting objects based on their attribute and spatial relations derived using methods such as <code>.intersects</code>; you can also join attributes in two geographic datasets using spatial joins. This is good news: skills developed in this chapter are cross-transferable. <a href="04-spatial-operations.html"><span>Chapter&nbsp;3</span></a> extends the methods presented here to the spatial world.</p>
<p>After a deep dive into various types of vector attribute operations in the next section, raster attribute data operations are covered in <a href="#sec-manipulating-raster-objects"><span>Section&nbsp;2.4</span></a>, which demonstrates how to create raster layers containing continuous and categorical attributes and extracting cell values from one or more layer (raster subsetting). <a href="#sec-summarizing-raster-objects"><span>Section&nbsp;2.4.2</span></a> provides an overview of ‘global’ raster operations which can be used to summarize entire raster datasets.</p>
</section>
<section id="vector-attribute-manipulation" class="level2" data-number="2.3">
<h2 data-number="2.3" class="anchored" data-anchor-id="vector-attribute-manipulation"><span class="header-section-number">2.3</span> Vector attribute manipulation</h2>
<p>As mentioned in <a href="#sec-vector-layers"><span class="quarto-unresolved-ref">sec-vector-layers</span></a>, vector layers (<code>GeoDataFrame</code>, from package <strong>geopandas</strong>) are basically extended tables (<code>DataFrame</code> from package <strong>pandas</strong>), the difference being that a vector layer has a geometry column. Since <code>GeoDataFrame</code> extends <code>DataFrame</code>, all ordinary table-related operations from package <strong>pandas</strong> are supported for vector layers as well, as shown below.</p>
<p>As mentioned in <a href="02-spatial-data.html#sec-vector-layers"><span>Section&nbsp;1.2.2</span></a>, vector layers (<code>GeoDataFrame</code>, from package <strong>geopandas</strong>) are basically extended tables (<code>DataFrame</code> from package <strong>pandas</strong>), the difference being that a vector layer has a geometry column. Since <code>GeoDataFrame</code> extends <code>DataFrame</code>, all ordinary table-related operations from package <strong>pandas</strong> are supported for vector layers as well, as shown below.</p>
<section id="sec-vector-attribute-subsetting" class="level3" data-number="2.3.1">
<h3 data-number="2.3.1" class="anchored" data-anchor-id="sec-vector-attribute-subsetting"><span class="header-section-number">2.3.1</span> Vector attribute subsetting</h3>
<p><strong>pandas</strong> supports several subsetting interfaces, though the most <a href="https://stackoverflow.com/questions/38886080/python-pandas-series-why-use-loc">recommended</a> ones are:</p>
Expand Down Expand Up @@ -1117,7 +1117,7 @@ <h3 data-number="2.3.1" class="anchored" data-anchor-id="sec-vector-attribute-su
</div>
</div>
</div>
<p>The standard <strong>numpy</strong> comparison operators can be used in boolean subsetting, as illustrated in Table <a href="#tbl-comparison-operators">Table&nbsp;<span class="quarto-unresolved-ref">tbl-comparison-operators</span></a>.</p>
<p>The standard <strong>numpy</strong> comparison operators can be used in boolean subsetting, as illustrated in Table <a href="#tbl-comparison-operators">Table&nbsp;<span>2.1</span></a>.</p>
<div id="tbl-comparison-operators" class="anchored">
<table class="table">
<caption>Table&nbsp;2.1: Comparison operators that return Booleans (<code>True</code>/<code>False</code>).</caption>
Expand Down Expand Up @@ -1625,7 +1625,7 @@ <h3 data-number="2.3.2" class="anchored" data-anchor-id="sec-vector-attribute-ag
</div>
</div>
</div>
<p><a href="#fig-spatial-aggregation">Figure&nbsp;<span class="quarto-unresolved-ref">fig-spatial-aggregation</span></a> shows the result:</p>
<p><a href="#fig-spatial-aggregation">Figure&nbsp;<span>2.1</span></a> shows the result:</p>
<div class="cell" data-execution_count="23">
<div class="sourceCode cell-code" id="cb22"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb22-1"><a href="#cb22-1" aria-hidden="true" tabindex="-1"></a>world_agg2.plot(column<span class="op">=</span><span class="st">'pop'</span>, legend<span class="op">=</span><span class="va">True</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="cell-output cell-output-display">
Expand Down Expand Up @@ -1736,7 +1736,7 @@ <h3 data-number="2.3.2" class="anchored" data-anchor-id="sec-vector-attribute-ag
</div>
</div>
</div>
<p>Figure <a href="#fig-spatial-aggregation-different-functions">Figure&nbsp;<span class="quarto-unresolved-ref">fig-spatial-aggregation-different-functions</span></a> visualizes the resulting layer (<code>world_agg3</code>) of continents with the three aggregated attributes.</p>
<p>Figure <a href="#fig-spatial-aggregation-different-functions">Figure&nbsp;<span>2.2</span></a> visualizes the resulting layer (<code>world_agg3</code>) of continents with the three aggregated attributes.</p>
<div class="cell" data-execution_count="25">
<div class="sourceCode cell-code" id="cb24"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb24-1"><a href="#cb24-1" aria-hidden="true" tabindex="-1"></a>fig, axes <span class="op">=</span> plt.subplots(<span class="dv">2</span>, <span class="dv">2</span>, figsize<span class="op">=</span>(<span class="dv">9</span>, <span class="dv">5</span>))</span>
<span id="cb24-2"><a href="#cb24-2" aria-hidden="true" tabindex="-1"></a>world_agg3.plot(column<span class="op">=</span><span class="st">'pop'</span>, edgecolor<span class="op">=</span><span class="st">'black'</span>, legend<span class="op">=</span><span class="va">True</span>, ax<span class="op">=</span>axes[<span class="dv">0</span>][<span class="dv">0</span>])</span>
Expand All @@ -1755,7 +1755,7 @@ <h3 data-number="2.3.2" class="anchored" data-anchor-id="sec-vector-attribute-ag
</div>
</div>
</div>
<p>Let’s proceed with the last result to demonstrate other table-related operations. Given the <code>world_agg3</code> continent summary (<a href="#fig-spatial-aggregation-different-functions">Figure&nbsp;<span class="quarto-unresolved-ref">fig-spatial-aggregation-different-functions</span></a>), we:</p>
<p>Let’s proceed with the last result to demonstrate other table-related operations. Given the <code>world_agg3</code> continent summary (<a href="#fig-spatial-aggregation-different-functions">Figure&nbsp;<span>2.2</span></a>), we:</p>
<ul>
<li>drop the geometry columns,</li>
<li>calculate population density of each continent,</li>
Expand Down Expand Up @@ -1992,7 +1992,7 @@ <h3 data-number="2.3.3" class="anchored" data-anchor-id="sec-vector-attribute-jo
</div>
</div>
</div>
<p>The result is a <code>GeoDataFrame</code> object identical to the original <code>world</code> object, but with two new variables (<code>coffee_production_2016</code> and <code>coffee_production_2017</code>) on coffee production. This can be plotted as a map, as illustrated in <a href="#fig-join-coffee-production">Figure&nbsp;<span class="quarto-unresolved-ref">fig-join-coffee-production</span></a>:</p>
<p>The result is a <code>GeoDataFrame</code> object identical to the original <code>world</code> object, but with two new variables (<code>coffee_production_2016</code> and <code>coffee_production_2017</code>) on coffee production. This can be plotted as a map, as illustrated in <a href="#fig-join-coffee-production">Figure&nbsp;<span>2.3</span></a>:</p>
<div class="cell" data-execution_count="29">
<div class="sourceCode cell-code" id="cb28"><pre class="sourceCode python code-with-copy"><code class="sourceCode python"><span id="cb28-1"><a href="#cb28-1" aria-hidden="true" tabindex="-1"></a>base <span class="op">=</span> world_coffee.plot(color<span class="op">=</span><span class="st">'white'</span>, edgecolor<span class="op">=</span><span class="st">'lightgrey'</span>)</span>
<span id="cb28-2"><a href="#cb28-2" aria-hidden="true" tabindex="-1"></a>coffee_map <span class="op">=</span> world_coffee.plot(ax<span class="op">=</span>base, column<span class="op">=</span><span class="st">'coffee_production_2017'</span>)</span>
Expand Down
Loading

0 comments on commit ce98011

Please sign in to comment.