fixed image paths

This commit is contained in:
Ollie Ballinger
2023-04-17 11:46:07 +01:00
parent 7ccf85e48e
commit 9eb020dab7
29 changed files with 1611 additions and 1734 deletions

View File

@@ -7,7 +7,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<title>Remote Sensing for OSINT - 7&nbsp; Vectors and Tables</title>
<title>Remote Sensing for OSINT - Vectors and Tables</title>
<style>
code{white-space: pre-wrap;}
span.smallcaps{font-variant: small-caps;}
@@ -199,20 +199,17 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
<ul id="quarto-sidebar-section-1" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./index.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">1</span>&nbsp; <span class="chapter-title">Overview</span></span></a>
<a href="./index.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Overview</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./A2_Remote_Sensing.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">2</span>&nbsp; <span class="chapter-title">Remote Sensing</span></span></a>
<a href="./A2_Remote_Sensing.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Remote Sensing</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./A3_Data_Acquisition.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">3</span>&nbsp; <span class="chapter-title">Data Acquisition</span></span></a>
<a href="./A3_Data_Acquisition.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Data Acquisition</span></a>
</div>
</li>
</ul>
@@ -228,26 +225,22 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
<ul id="quarto-sidebar-section-2" class="collapse list-unstyled sidebar-section depth1 show">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./B1_Getting_Started.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">4</span>&nbsp; <span class="chapter-title">Getting Started</span></span></a>
<a href="./B1_Getting_Started.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Getting Started</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./B2_Interpreting_Images.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">5</span>&nbsp; <span class="chapter-title">Interpreting Images</span></span></a>
<a href="./B2_Interpreting_Images.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Interpreting Images</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./B3_Image_Series.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Image Series</span></span></a>
<a href="./B3_Image_Series.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Image Series</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./B4_Vectors_Tables.html" class="sidebar-item-text sidebar-link active">
<span class="menu-text"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Vectors and Tables</span></span></a>
<a href="./B4_Vectors_Tables.html" class="sidebar-item-text sidebar-link active"><span class="chapter-title">Vectors and Tables</span></a>
</div>
</li>
</ul>
@@ -263,32 +256,27 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
<ul id="quarto-sidebar-section-3" class="collapse list-unstyled sidebar-section depth1 ">
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./C1_Lights.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">War at Night</span></span></a>
<a href="./C1_Lights.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">War at Night</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./C2_Refineries.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">9</span>&nbsp; <span class="chapter-title">Refinery Identification</span></span></a>
<a href="./C2_Refineries.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Refinery Identification</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./C3_Blast.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">10</span>&nbsp; <span class="chapter-title">Blast Damage Assessment</span></span></a>
<a href="./C3_Blast.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Blast Damage Assessment</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./C4_Ships.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">11</span>&nbsp; <span class="chapter-title">Ship Detection</span></span></a>
<a href="./C4_Ships.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Ship Detection</span></a>
</div>
</li>
<li class="sidebar-item">
<div class="sidebar-item-container">
<a href="./C5_Object_Detection.html" class="sidebar-item-text sidebar-link">
<span class="menu-text"><span class="chapter-number">12</span>&nbsp; <span class="chapter-title">Object Detection</span></span></a>
<a href="./C5_Object_Detection.html" class="sidebar-item-text sidebar-link"><span class="chapter-title">Object Detection</span></a>
</div>
</li>
</ul>
@@ -303,36 +291,36 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
<h2 id="toc-title">Table of contents</h2>
<ul>
<li><a href="#exploring-vectors" id="toc-exploring-vectors" class="nav-link active" data-scroll-target="#exploring-vectors"><span class="header-section-number">7.1</span> Exploring Vectors</a>
<li><a href="#exploring-vectors" id="toc-exploring-vectors" class="nav-link active" data-scroll-target="#exploring-vectors">Exploring Vectors</a>
<ul class="collapse">
<li><a href="#using-geometry-tools-to-create-features-in-earth-engine" id="toc-using-geometry-tools-to-create-features-in-earth-engine" class="nav-link" data-scroll-target="#using-geometry-tools-to-create-features-in-earth-engine"><span class="header-section-number">7.1.1</span> Using Geometry Tools to Create Features in Earth Engine</a></li>
<li><a href="#loading-existing-features-and-feature-collections-in-earth-engine" id="toc-loading-existing-features-and-feature-collections-in-earth-engine" class="nav-link" data-scroll-target="#loading-existing-features-and-feature-collections-in-earth-engine"><span class="header-section-number">7.1.2</span> Loading Existing Features and Feature Collections in Earth Engine</a></li>
<li><a href="#importing-features-into-earth-engine" id="toc-importing-features-into-earth-engine" class="nav-link" data-scroll-target="#importing-features-into-earth-engine"><span class="header-section-number">7.1.3</span> Importing Features into Earth Engine</a></li>
<li><a href="#filtering-feature-collections-by-attributes" id="toc-filtering-feature-collections-by-attributes" class="nav-link" data-scroll-target="#filtering-feature-collections-by-attributes"><span class="header-section-number">7.1.4</span> Filtering Feature Collections by Attributes</a></li>
<li><a href="#reducing-images-using-feature-geometry" id="toc-reducing-images-using-feature-geometry" class="nav-link" data-scroll-target="#reducing-images-using-feature-geometry"><span class="header-section-number">7.1.5</span> Reducing Images Using Feature Geometry</a></li>
<li><a href="#identifying-the-block-in-the-neighborhood-surrounding-usf-with-the-highest-ndvi" id="toc-identifying-the-block-in-the-neighborhood-surrounding-usf-with-the-highest-ndvi" class="nav-link" data-scroll-target="#identifying-the-block-in-the-neighborhood-surrounding-usf-with-the-highest-ndvi"><span class="header-section-number">7.1.6</span> Identifying the Block in the Neighborhood Surrounding USF with the Highest NDVI</a></li>
<li><a href="#using-geometry-tools-to-create-features-in-earth-engine" id="toc-using-geometry-tools-to-create-features-in-earth-engine" class="nav-link" data-scroll-target="#using-geometry-tools-to-create-features-in-earth-engine">Using Geometry Tools to Create Features in Earth Engine</a></li>
<li><a href="#loading-existing-features-and-feature-collections-in-earth-engine" id="toc-loading-existing-features-and-feature-collections-in-earth-engine" class="nav-link" data-scroll-target="#loading-existing-features-and-feature-collections-in-earth-engine">Loading Existing Features and Feature Collections in Earth Engine</a></li>
<li><a href="#importing-features-into-earth-engine" id="toc-importing-features-into-earth-engine" class="nav-link" data-scroll-target="#importing-features-into-earth-engine">Importing Features into Earth Engine</a></li>
<li><a href="#filtering-feature-collections-by-attributes" id="toc-filtering-feature-collections-by-attributes" class="nav-link" data-scroll-target="#filtering-feature-collections-by-attributes">Filtering Feature Collections by Attributes</a></li>
<li><a href="#reducing-images-using-feature-geometry" id="toc-reducing-images-using-feature-geometry" class="nav-link" data-scroll-target="#reducing-images-using-feature-geometry">Reducing Images Using Feature Geometry</a></li>
<li><a href="#identifying-the-block-in-the-neighborhood-surrounding-usf-with-the-highest-ndvi" id="toc-identifying-the-block-in-the-neighborhood-surrounding-usf-with-the-highest-ndvi" class="nav-link" data-scroll-target="#identifying-the-block-in-the-neighborhood-surrounding-usf-with-the-highest-ndvi">Identifying the Block in the Neighborhood Surrounding USF with the Highest NDVI</a></li>
<li><a href="#conclusion" id="toc-conclusion" class="nav-link" data-scroll-target="#conclusion">Conclusion</a></li>
</ul></li>
<li><a href="#rastervector-conversions" id="toc-rastervector-conversions" class="nav-link" data-scroll-target="#rastervector-conversions"><span class="header-section-number">7.2</span> Raster/Vector Conversions</a>
<li><a href="#rastervector-conversions" id="toc-rastervector-conversions" class="nav-link" data-scroll-target="#rastervector-conversions">Raster/Vector Conversions</a>
<ul class="collapse">
<li><a href="#raster-to-vector-conversion" id="toc-raster-to-vector-conversion" class="nav-link" data-scroll-target="#raster-to-vector-conversion"><span class="header-section-number">7.2.1</span> Raster to Vector Conversion</a></li>
<li><a href="#a-more-complex-example" id="toc-a-more-complex-example" class="nav-link" data-scroll-target="#a-more-complex-example"><span class="header-section-number">7.2.2</span> 3. A More Complex Example</a></li>
<li><a href="#vector-to-raster-conversion" id="toc-vector-to-raster-conversion" class="nav-link" data-scroll-target="#vector-to-raster-conversion"><span class="header-section-number">7.2.3</span> Vector-to-Raster Conversion</a></li>
<li><a href="#raster-to-vector-conversion" id="toc-raster-to-vector-conversion" class="nav-link" data-scroll-target="#raster-to-vector-conversion">Raster to Vector Conversion</a></li>
<li><a href="#a-more-complex-example" id="toc-a-more-complex-example" class="nav-link" data-scroll-target="#a-more-complex-example">3. A More Complex Example</a></li>
<li><a href="#vector-to-raster-conversion" id="toc-vector-to-raster-conversion" class="nav-link" data-scroll-target="#vector-to-raster-conversion">Vector-to-Raster Conversion</a></li>
<li><a href="#conclusion-1" id="toc-conclusion-1" class="nav-link" data-scroll-target="#conclusion-1">Conclusion</a></li>
</ul></li>
<li><a href="#zonal-statistics" id="toc-zonal-statistics" class="nav-link" data-scroll-target="#zonal-statistics"><span class="header-section-number">7.3</span> Zonal Statistics</a>
<li><a href="#zonal-statistics" id="toc-zonal-statistics" class="nav-link" data-scroll-target="#zonal-statistics">Zonal Statistics</a>
<ul class="collapse">
<li><a href="#functions" id="toc-functions" class="nav-link" data-scroll-target="#functions"><span class="header-section-number">7.3.1</span> Functions</a></li>
<li><a href="#point-collection-creation" id="toc-point-collection-creation" class="nav-link" data-scroll-target="#point-collection-creation"><span class="header-section-number">7.3.2</span> Point Collection Creation</a></li>
<li><a href="#neighborhood-statistic-examples" id="toc-neighborhood-statistic-examples" class="nav-link" data-scroll-target="#neighborhood-statistic-examples"><span class="header-section-number">7.3.3</span> Neighborhood Statistic Examples</a></li>
<li><a href="#additional-notes" id="toc-additional-notes" class="nav-link" data-scroll-target="#additional-notes"><span class="header-section-number">7.3.4</span> Additional Notes</a></li>
<li><a href="#functions" id="toc-functions" class="nav-link" data-scroll-target="#functions">Functions</a></li>
<li><a href="#point-collection-creation" id="toc-point-collection-creation" class="nav-link" data-scroll-target="#point-collection-creation">Point Collection Creation</a></li>
<li><a href="#neighborhood-statistic-examples" id="toc-neighborhood-statistic-examples" class="nav-link" data-scroll-target="#neighborhood-statistic-examples">Neighborhood Statistic Examples</a></li>
<li><a href="#additional-notes" id="toc-additional-notes" class="nav-link" data-scroll-target="#additional-notes">Additional Notes</a></li>
<li><a href="#conclusion-2" id="toc-conclusion-2" class="nav-link" data-scroll-target="#conclusion-2">Conclusion</a></li>
<li><a href="#references" id="toc-references" class="nav-link" data-scroll-target="#references">References</a></li>
</ul></li>
<li><a href="#advanced-vector-operations" id="toc-advanced-vector-operations" class="nav-link" data-scroll-target="#advanced-vector-operations"><span class="header-section-number">7.4</span> Advanced Vector Operations</a>
<li><a href="#advanced-vector-operations" id="toc-advanced-vector-operations" class="nav-link" data-scroll-target="#advanced-vector-operations">Advanced Vector Operations</a>
<ul class="collapse">
<li><a href="#visualizing-feature-collections" id="toc-visualizing-feature-collections" class="nav-link" data-scroll-target="#visualizing-feature-collections"><span class="header-section-number">7.4.1</span> Visualizing Feature Collections</a></li>
<li><a href="#joins-with-feature-collections" id="toc-joins-with-feature-collections" class="nav-link" data-scroll-target="#joins-with-feature-collections"><span class="header-section-number">7.4.2</span> Joins with Feature Collections</a></li>
<li><a href="#visualizing-feature-collections" id="toc-visualizing-feature-collections" class="nav-link" data-scroll-target="#visualizing-feature-collections">Visualizing Feature Collections</a></li>
<li><a href="#joins-with-feature-collections" id="toc-joins-with-feature-collections" class="nav-link" data-scroll-target="#joins-with-feature-collections">Joins with Feature Collections</a></li>
<li><a href="#conclusion-3" id="toc-conclusion-3" class="nav-link" data-scroll-target="#conclusion-3">Conclusion</a></li>
</ul></li>
</ul>
@@ -343,7 +331,7 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
<header id="title-block-header" class="quarto-title-block default">
<div class="quarto-title">
<h1 class="title"><span class="chapter-number">7</span>&nbsp; <span class="chapter-title">Vectors and Tables</span></h1>
<h1 class="title"><span class="chapter-title">Vectors and Tables</span></h1>
</div>
@@ -359,8 +347,8 @@ gtag('config', 'G-RK9ZLZQ6GL', { 'anonymize_ip': true});
</header>
<p>In addition to raster data processing, Earth Engine supports a rich set of vector processing tools. This Part introduces you to the vector framework in Earth Engine, shows you how to create and to import your vector data, and how to combine vector and raster data for analyses.</p>
<section id="exploring-vectors" class="level2" data-number="7.1">
<h2 data-number="7.1" class="anchored" data-anchor-id="exploring-vectors"><span class="header-section-number">7.1</span> Exploring Vectors</h2>
<section id="exploring-vectors" class="level2">
<h2 class="anchored" data-anchor-id="exploring-vectors">Exploring Vectors</h2>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
@@ -408,13 +396,13 @@ Chapter Information
<p>As you have seen, raster features in Earth Engine are stored as an Image or as part of an ImageCollection. Using a similar conceptual model, vector data in Earth Engine is stored as a Feature or as part of a FeatureCollection. Features and feature collections provide useful data to filter images and image collections by their location, clip images to a boundary, or statistically summarize the pixel values within a region.</p>
<p>In the following example, you will use features and feature collections to identify which city block near the University of San Francisco (USF) campus is the most green.</p>
</section>
<section id="using-geometry-tools-to-create-features-in-earth-engine" class="level3" data-number="7.1.1">
<h3 data-number="7.1.1" class="anchored" data-anchor-id="using-geometry-tools-to-create-features-in-earth-engine"><span class="header-section-number">7.1.1</span> Using Geometry Tools to Create Features in Earth Engine</h3>
<section id="using-geometry-tools-to-create-features-in-earth-engine" class="level3">
<h3 class="anchored" data-anchor-id="using-geometry-tools-to-create-features-in-earth-engine">Using Geometry Tools to Create Features in Earth Engine</h3>
<p>To demonstrate how geometry tools in Earth Engine work, lets start by creating a point, and two polygons to represent different elements on the USF campus.</p>
<p>Click on the geometry tools in the top left of the Map pane and create a point feature. Place a new point where USF is located (see Fig. F5.0.1).</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image54.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image54.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.0.1 Location of the USF campus in San Francisco, California. Your first point should be in this vicinity. The red arrow points to the geometry tools.</figcaption><p></p>
</figure>
</div>
@@ -423,7 +411,7 @@ Chapter Information
<p>After you create these layers, rename the geometry imports at the top of your script. Name the layers usf_point, usf_building, and usf_campus. These names are used within the script shown in Fig. F5.0.2.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image10.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image10.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.0.2 Rename the default variable names for each layer in the Imports section of the code at the top of your script</figcaption><p></p>
</figure>
</div>
@@ -441,8 +429,8 @@ Note
</div>
</div>
</section>
<section id="loading-existing-features-and-feature-collections-in-earth-engine" class="level3" data-number="7.1.2">
<h3 data-number="7.1.2" class="anchored" data-anchor-id="loading-existing-features-and-feature-collections-in-earth-engine"><span class="header-section-number">7.1.2</span> Loading Existing Features and Feature Collections in Earth Engine</h3>
<section id="loading-existing-features-and-feature-collections-in-earth-engine" class="level3">
<h3 class="anchored" data-anchor-id="loading-existing-features-and-feature-collections-in-earth-engine">Loading Existing Features and Feature Collections in Earth Engine</h3>
<p>If you wish to have the exact same geometry imports in this chapter for the rest of this exercise, begin this section using the code at the Code Checkpoint above.</p>
<p>Next, you will load a city block dataset to determine the amount of vegetation on blocks near USF. The code below imports an existing feature dataset in Earth Engine. The Topologically Integrated Geographic Encoding and Referencing (TIGER) boundaries are census-designated boundaries that are a useful resource when comparing socioeconomic and diversity metrics with environmental datasets in the United States.</p>
<div class="sourceCode" id="cb1"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb1-1"><a href="#cb1-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Import the Census Tiger Boundaries from GEE. </span></span>
@@ -452,37 +440,37 @@ Note
<span id="cb1-5"><a href="#cb1-5" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">addLayer</span>(tiger<span class="op">,</span> { <span class="st">'color'</span><span class="op">:</span> <span class="st">'black'</span>}<span class="op">,</span> <span class="st">'Tiger'</span><span class="op">,</span> <span class="kw">false</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>You should now have the geometry for USFs campus and a layer added to your map that is not visualized for census blocks across the United States. Next, we will use neighborhood data to spatially filter the TIGER feature collection for blocks near USFs campus.</p>
</section>
<section id="importing-features-into-earth-engine" class="level3" data-number="7.1.3">
<h3 data-number="7.1.3" class="anchored" data-anchor-id="importing-features-into-earth-engine"><span class="header-section-number">7.1.3</span> Importing Features into Earth Engine</h3>
<section id="importing-features-into-earth-engine" class="level3">
<h3 class="anchored" data-anchor-id="importing-features-into-earth-engine">Importing Features into Earth Engine</h3>
<p>There are many image collections loaded in Earth Engine, and they can cover a very large area that you might want to study. Borders can be quite intricate (for example, a detailed coastline), and fortunately there is no need for you to digitize the intricate boundary of a large geographic area. Instead, we will show how to find a spatial dataset online, download the data, and load this into Earth Engine as an asset for use.</p>
<section id="find-a-spatial-dataset-of-san-francisco-neighborhoods" class="level4" data-number="7.1.3.1">
<h4 data-number="7.1.3.1" class="anchored" data-anchor-id="find-a-spatial-dataset-of-san-francisco-neighborhoods"><span class="header-section-number">7.1.3.1</span> Find a Spatial Dataset of San Francisco Neighborhoods</h4>
<section id="find-a-spatial-dataset-of-san-francisco-neighborhoods" class="level4">
<h4 class="anchored" data-anchor-id="find-a-spatial-dataset-of-san-francisco-neighborhoods">Find a Spatial Dataset of San Francisco Neighborhoods</h4>
<p>Use your internet searching skills to locate the “Analysis Neighborhoods” dataset covering San Francisco. This data might be located in a number of places, including DataSF, the City of San Franciscos public-facing data repository.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image27.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image27.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.0.3 DataSF website neighborhood shapefile to download</figcaption><p></p>
</figure>
</div>
<p>After you find the Analysis Neighborhoods layer, click Export and select Shapefile (Fig. F5.0.3). Keep track of where you save the zipped file, as we will load this into Earth Engine. Shapefiles contain vector-based data—points, lines, polygons—and include a number of files, such as the location information, attribute information, and others.</p>
<p>Extract the folder to your computer. When you open the folder, you will see that there are actually many files. The extensions (.shp, .dbf, .shx, .prj) all provide a different piece of information to display vector-based data. The .shp file provides data on the geometry. The .dbf file provides data about the attributes. The .shx file is an index file. Lastly, the .prj file describes the map projection of the coordinate information for the shapefile. You will need to load all four files to create a new feature asset in Earth Engine.</p>
</section>
<section id="upload-sf-neighborhoods-file-as-an-asset" class="level4" data-number="7.1.3.2">
<h4 data-number="7.1.3.2" class="anchored" data-anchor-id="upload-sf-neighborhoods-file-as-an-asset"><span class="header-section-number">7.1.3.2</span> Upload SF Neighborhoods File as an Asset</h4>
<section id="upload-sf-neighborhoods-file-as-an-asset" class="level4">
<h4 class="anchored" data-anchor-id="upload-sf-neighborhoods-file-as-an-asset">Upload SF Neighborhoods File as an Asset</h4>
<p>Navigate to the Assets tab (near Scripts). Select New &gt; Table Upload &gt; Shape files (Fig. F5.0.4).</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image52.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image52.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.0.4 Import an asset as a zipped folder</figcaption><p></p>
</figure>
</div>
</section>
<section id="select-files-and-name-asset" class="level4" data-number="7.1.3.3">
<h4 data-number="7.1.3.3" class="anchored" data-anchor-id="select-files-and-name-asset"><span class="header-section-number">7.1.3.3</span> Select Files and Name Asset</h4>
<section id="select-files-and-name-asset" class="level4">
<h4 class="anchored" data-anchor-id="select-files-and-name-asset">Select Files and Name Asset</h4>
<p>Click the Select button and then use the file navigator to select the component files of the shapefile structure (i.e., .shp, .dbf, .shx, and .prj) (Fig. F5.0.5). Assign an Asset Name so you can recognize this asset.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image43.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image43.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.0.5 Select the four files extracted from the zipped folder. Make sure each file has the same name and that there are no spaces in the file names of the component files of the shapefile structure.</figcaption><p></p>
</figure>
</div>
@@ -511,10 +499,10 @@ Note
</div>
</section>
</section>
<section id="filtering-feature-collections-by-attributes" class="level3" data-number="7.1.4">
<h3 data-number="7.1.4" class="anchored" data-anchor-id="filtering-feature-collections-by-attributes"><span class="header-section-number">7.1.4</span> Filtering Feature Collections by Attributes</h3>
<section id="filter-by-geometry-of-another-feature" class="level4" data-number="7.1.4.1">
<h4 data-number="7.1.4.1" class="anchored" data-anchor-id="filter-by-geometry-of-another-feature"><span class="header-section-number">7.1.4.1</span> Filter by Geometry of Another Feature</h4>
<section id="filtering-feature-collections-by-attributes" class="level3">
<h3 class="anchored" data-anchor-id="filtering-feature-collections-by-attributes">Filtering Feature Collections by Attributes</h3>
<section id="filter-by-geometry-of-another-feature" class="level4">
<h4 class="anchored" data-anchor-id="filter-by-geometry-of-another-feature">Filter by Geometry of Another Feature</h4>
<p>First, lets find the neighborhood associated with USF. Use the first point you created to find the neighborhood that intersects this point; filterBounds is the tool that does that, returning a filtered feature.</p>
<div class="sourceCode" id="cb3"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb3-1"><a href="#cb3-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Filter sfNeighborhoods by USF. </span></span>
<span id="cb3-2"><a href="#cb3-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> usfNeighborhood <span class="op">=</span> sfNeighborhoods<span class="op">.</span><span class="fu">filterBounds</span>(usf_point)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
@@ -523,8 +511,8 @@ Note
<span id="cb4-2"><a href="#cb4-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> usfTiger <span class="op">=</span> tiger<span class="op">.</span><span class="fu">filterBounds</span>(usfNeighborhood)<span class="op">;</span> </span>
<span id="cb4-3"><a href="#cb4-3" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">addLayer</span>(usfTiger<span class="op">,</span> {}<span class="op">,</span> <span class="st">'usf_Tiger'</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</section>
<section id="filter-by-feature-attribute-properties" class="level4" data-number="7.1.4.2">
<h4 data-number="7.1.4.2" class="anchored" data-anchor-id="filter-by-feature-attribute-properties"><span class="header-section-number">7.1.4.2</span> Filter by Feature (Attribute) Properties</h4>
<section id="filter-by-feature-attribute-properties" class="level4">
<h4 class="anchored" data-anchor-id="filter-by-feature-attribute-properties">Filter by Feature (Attribute) Properties</h4>
<p>In addition to filtering a FeatureCollection by the location of another feature, you can also filter it by its properties. First, lets print the usfTiger variable to the Console and inspect the object.</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb5-1"><a href="#cb5-1" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(usfTiger)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>You can click on the feature collection name in the Console to uncover more information about the dataset. Click on the columns to learn about what attribute information is contained in this dataset. You will notice this feature collection contains information on both housing (housing10) and population (pop10).</p>
@@ -539,8 +527,8 @@ Note
<div class="sourceCode" id="cb8"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb8-1"><a href="#cb8-1" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">addLayer</span>(housing10_g50_l250<span class="op">,</span> { <span class="st">'color'</span><span class="op">:</span> <span class="st">'Magenta'</span>}<span class="op">,</span> <span class="st">'housing'</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>We have combined spatial and attribute information to narrow the set to only those blocks that meet our criteria of having between 50 and 250 housing units.</p>
</section>
<section id="print-feature-attribute-properties-to-console" class="level4" data-number="7.1.4.3">
<h4 data-number="7.1.4.3" class="anchored" data-anchor-id="print-feature-attribute-properties-to-console"><span class="header-section-number">7.1.4.3</span> Print Feature (Attribute) Properties to Console</h4>
<section id="print-feature-attribute-properties-to-console" class="level4">
<h4 class="anchored" data-anchor-id="print-feature-attribute-properties-to-console">Print Feature (Attribute) Properties to Console</h4>
<p>We can print out attribute information about these features. The block of code below prints out the area of the resultant geometry in square meters.</p>
<div class="sourceCode" id="cb9"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb9-1"><a href="#cb9-1" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> housing_area <span class="op">=</span> housing10_g50_l250<span class="op">.</span><span class="fu">geometry</span>()<span class="op">.</span><span class="fu">area</span>()<span class="op">;</span> </span>
<span id="cb9-2"><a href="#cb9-2" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(<span class="st">'housing_area:'</span><span class="op">,</span> housing_area)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
@@ -567,12 +555,12 @@ Note
</div>
</section>
</section>
<section id="reducing-images-using-feature-geometry" class="level3" data-number="7.1.5">
<h3 data-number="7.1.5" class="anchored" data-anchor-id="reducing-images-using-feature-geometry"><span class="header-section-number">7.1.5</span> Reducing Images Using Feature Geometry</h3>
<section id="reducing-images-using-feature-geometry" class="level3">
<h3 class="anchored" data-anchor-id="reducing-images-using-feature-geometry">Reducing Images Using Feature Geometry</h3>
<p>Now that we have identified the blocks around USFs campus that have the right housing density, lets find which blocks are the greenest.</p>
<p>The Normalized Difference Vegetation Index (NDVI), presented in detail in Chap. F2.0, is often used to compare the greenness of pixels in different locations. Values on land range from 0 to 1, with values closer to 1 representing healthier and greener vegetation than values near 0.</p>
<section id="create-an-ndvi-image" class="level4" data-number="7.1.5.1">
<h4 data-number="7.1.5.1" class="anchored" data-anchor-id="create-an-ndvi-image"><span class="header-section-number">7.1.5.1</span> Create an NDVI Image</h4>
<section id="create-an-ndvi-image" class="level4">
<h4 class="anchored" data-anchor-id="create-an-ndvi-image">Create an NDVI Image</h4>
<p>The code below imports the Landsat 8 ImageCollection as landsat8. Then, the code filters for images in 2021. Lastly, the code sorts the images from 2021 to find the least cloudy day.</p>
<div class="sourceCode" id="cb11"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb11-1"><a href="#cb11-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Import the Landsat 8 TOA image collection. </span></span>
<span id="cb11-2"><a href="#cb11-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> landsat8 <span class="op">=</span> ee<span class="op">.</span><span class="fu">ImageCollection</span>(<span class="st">'LANDSAT/LC08/C02/T1_TOA'</span>)<span class="op">;</span> </span>
@@ -589,8 +577,8 @@ Note
<span id="cb12-2"><a href="#cb12-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> red <span class="op">=</span> image<span class="op">.</span><span class="fu">select</span>(<span class="st">'B4'</span>)<span class="op">;</span> </span>
<span id="cb12-3"><a href="#cb12-3" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> ndvi <span class="op">=</span> nir<span class="op">.</span><span class="fu">subtract</span>(red)<span class="op">.</span><span class="fu">divide</span>(nir<span class="op">.</span><span class="fu">add</span>(red))<span class="op">.</span><span class="fu">rename</span>(<span class="st">'NDVI'</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</section>
<section id="clip-the-ndvi-image-to-the-blocks-near-usf" class="level4" data-number="7.1.5.2">
<h4 data-number="7.1.5.2" class="anchored" data-anchor-id="clip-the-ndvi-image-to-the-blocks-near-usf"><span class="header-section-number">7.1.5.2</span> Clip the NDVI Image to the Blocks Near USF</h4>
<section id="clip-the-ndvi-image-to-the-blocks-near-usf" class="level4">
<h4 class="anchored" data-anchor-id="clip-the-ndvi-image-to-the-blocks-near-usf">Clip the NDVI Image to the Blocks Near USF</h4>
<p>Next, you will clip the NDVI layer to only show NDVI over USFs neighborhood.</p>
<p>The first section of code provides visualization settings.</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb13-1"><a href="#cb13-1" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> ndviParams <span class="op">=</span> { </span>
@@ -604,8 +592,8 @@ Note
<span id="cb14-3"><a href="#cb14-3" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">centerObject</span>(usf_point<span class="op">,</span> <span class="dv">14</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>The NDVI map for all of San Francisco is interesting, and shows variability across the region. Now, lets compute mean NDVI values for each block of the city.</p>
</section>
<section id="compute-ndvi-statistics-by-block" class="level4" data-number="7.1.5.3">
<h4 data-number="7.1.5.3" class="anchored" data-anchor-id="compute-ndvi-statistics-by-block"><span class="header-section-number">7.1.5.3</span> Compute NDVI Statistics by Block</h4>
<section id="compute-ndvi-statistics-by-block" class="level4">
<h4 class="anchored" data-anchor-id="compute-ndvi-statistics-by-block">Compute NDVI Statistics by Block</h4>
<p>The code below uses the clipped image ndviUSFblocks and computes the mean NDVI value within each boundary. The scale provides a spatial resolution for the mean values to be computed on.</p>
<div class="sourceCode" id="cb15"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb15-1"><a href="#cb15-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Reduce image by feature to compute a statistic e.g. mean, max, min etc. </span></span>
<span id="cb15-2"><a href="#cb15-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> ndviPerBlock <span class="op">=</span> ndviUSFblocks<span class="op">.</span><span class="fu">reduceRegions</span>({ </span>
@@ -615,8 +603,8 @@ Note
<span id="cb15-6"><a href="#cb15-6" aria-hidden="true" tabindex="-1"></a>})<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>Now well use Earth Engine to find out which block is greenest.</p>
</section>
<section id="export-table-of-ndvi-data-by-block-from-earth-engine-to-google-drive" class="level4" data-number="7.1.5.4">
<h4 data-number="7.1.5.4" class="anchored" data-anchor-id="export-table-of-ndvi-data-by-block-from-earth-engine-to-google-drive"><span class="header-section-number">7.1.5.4</span> Export Table of NDVI Data by Block from Earth Engine to Google Drive</h4>
<section id="export-table-of-ndvi-data-by-block-from-earth-engine-to-google-drive" class="level4">
<h4 class="anchored" data-anchor-id="export-table-of-ndvi-data-by-block-from-earth-engine-to-google-drive">Export Table of NDVI Data by Block from Earth Engine to Google Drive</h4>
<p>Just as we loaded a feature into Earth Engine, we can export information from Earth Engine. Here, we will export the NDVI data, summarized by block, from Earth Engine to a Google Drive space so that we can interpret it in a program like Google Sheets or Excel.</p>
<div class="sourceCode" id="cb16"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb16-1"><a href="#cb16-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Get a table of data out of Google Earth Engine. </span></span>
<span id="cb16-2"><a href="#cb16-2" aria-hidden="true" tabindex="-1"></a>Export<span class="op">.</span><span class="at">table</span><span class="op">.</span><span class="fu">toDrive</span>({ </span>
@@ -626,7 +614,7 @@ Note
<p>When you run this code, you will notice that you have the Tasks tab highlighted on the top right of the Earth Engine Code Editor (Fig. F5.0.6). You will be prompted to name the directory when exporting the data.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image4.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image4.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.0.6 Under the Tasks tab, select Run to initiate download</figcaption><p></p>
</figure>
</div>
@@ -646,8 +634,8 @@ Note
</div>
</section>
</section>
<section id="identifying-the-block-in-the-neighborhood-surrounding-usf-with-the-highest-ndvi" class="level3" data-number="7.1.6">
<h3 data-number="7.1.6" class="anchored" data-anchor-id="identifying-the-block-in-the-neighborhood-surrounding-usf-with-the-highest-ndvi"><span class="header-section-number">7.1.6</span> Identifying the Block in the Neighborhood Surrounding USF with the Highest NDVI</h3>
<section id="identifying-the-block-in-the-neighborhood-surrounding-usf-with-the-highest-ndvi" class="level3">
<h3 class="anchored" data-anchor-id="identifying-the-block-in-the-neighborhood-surrounding-usf-with-the-highest-ndvi">Identifying the Block in the Neighborhood Surrounding USF with the Highest NDVI</h3>
<p>You are already familiar with filtering datasets by their attributes. Now you will sort a table and select the first element of the table.</p>
<div class="sourceCode" id="cb17"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb17-1"><a href="#cb17-1" aria-hidden="true" tabindex="-1"></a>ndviPerBlock <span class="op">=</span> ndviPerBlock<span class="op">.</span><span class="fu">select</span>([<span class="st">'blockid10'</span><span class="op">,</span> <span class="st">'mean'</span>])<span class="op">;</span> </span>
<span id="cb17-2"><a href="#cb17-2" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(<span class="st">'ndviPerBlock'</span><span class="op">,</span> ndviPerBlock)<span class="op">;</span> </span>
@@ -682,8 +670,8 @@ Note
<p>In this chapter, you learned how to import features into Earth Engine. In Sect. 1, you created new features using the geometry tools and loaded a feature from Earth Engines Data Catalog. In Sect. 2, you loaded a shapefile to an Earth Engine asset. In Sect. 3, you filtered feature collections based on their properties and locations. Finally, in Sects. 4 and 5, you used a feature collection to reduce an image, then exported the data from Earth Engine. Now you have all the tools you need to load, filter, and apply features to extract meaningful information from images using vector features in Earth Engine.</p>
</section>
</section>
<section id="rastervector-conversions" class="level2" data-number="7.2">
<h2 data-number="7.2" class="anchored" data-anchor-id="rastervector-conversions"><span class="header-section-number">7.2</span> Raster/Vector Conversions</h2>
<section id="rastervector-conversions" class="level2">
<h2 class="anchored" data-anchor-id="rastervector-conversions">Raster/Vector Conversions</h2>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
@@ -731,10 +719,10 @@ Chapter Information
<p>Raster and vector data are commonly combined (e.g., extracting image information for a given location or clipping an image to an area of interest); however, there are also situations in which conversion between the two formats is useful. In making such conversions, it is important to consider the key advantages of each format. Rasters can store data efficiently where each pixel has a numerical value, while vector data can more effectively represent geometric features where homogenous areas have shared properties. Each format lends itself to distinctive analytical operations, and combining them can be powerful.</p>
<p>In this exercise, well use topographic elevation and forest change images in Colombia as well as a protected area feature collection to practice the conversion between raster and vector formats, and to identify situations in which this is worthwhile.</p>
</section>
<section id="raster-to-vector-conversion" class="level3" data-number="7.2.1">
<h3 data-number="7.2.1" class="anchored" data-anchor-id="raster-to-vector-conversion"><span class="header-section-number">7.2.1</span> Raster to Vector Conversion</h3>
<section id="raster-to-polygons" class="level4" data-number="7.2.1.1">
<h4 data-number="7.2.1.1" class="anchored" data-anchor-id="raster-to-polygons"><span class="header-section-number">7.2.1.1</span> Raster to Polygons</h4>
<section id="raster-to-vector-conversion" class="level3">
<h3 class="anchored" data-anchor-id="raster-to-vector-conversion">Raster to Vector Conversion</h3>
<section id="raster-to-polygons" class="level4">
<h4 class="anchored" data-anchor-id="raster-to-polygons">Raster to Polygons</h4>
<p>In this section we will convert an elevation image (raster) to a feature collection (vector). We will start by loading the Global Multi-Resolution Terrain Elevation Data 2010 and the Global Administrative Unit Layers 2015 dataset to focus on Colombia. The elevation image is a raster at 7.5 arc-second spatial resolution containing a continuous measure of elevation in meters in each pixel.</p>
<div class="sourceCode" id="cb19"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb19-1"><a href="#cb19-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Load raster (elevation) and vector (colombia) datasets. </span></span>
<span id="cb19-2"><a href="#cb19-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> elevation <span class="op">=</span> ee<span class="op">.</span><span class="fu">Image</span>(<span class="st">'USGS/GMTED2010'</span>)<span class="op">.</span><span class="fu">rename</span>(<span class="st">'elevation'</span>)<span class="op">;</span> </span>
@@ -784,12 +772,12 @@ Chapter Information
<span id="cb21-19"><a href="#cb21-19" aria-hidden="true" tabindex="-1"></a> <span class="dt">strokeWidth</span><span class="op">:</span> <span class="dv">1</span> </span>
<span id="cb21-20"><a href="#cb21-20" aria-hidden="true" tabindex="-1"></a>})<span class="op">;</span> </span>
<span id="cb21-21"><a href="#cb21-21" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">addLayer</span>(elevationDrawn<span class="op">,</span> {}<span class="op">,</span> <span class="st">'Elevation zone polygon'</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p><img src="../images/F5/image50.png" class="img-fluid"></p>
<p><img src="../images/F5/image33.png" class="img-fluid"></p>
<p><img src="../images/F5/image36.png" class="img-fluid"></p>
<p><img src="images/F5/image50.png" class="img-fluid"></p>
<p><img src="images/F5/image33.png" class="img-fluid"></p>
<p><img src="images/F5/image36.png" class="img-fluid"></p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image7.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image7.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.1.1 Raster-based elevation (top left) and zones (top right), vectorized elevation zones overlaid on the raster (bottom-left) and vectorized elevation zones only (bottom-right)</figcaption><p></p>
</figure>
</div>
@@ -822,21 +810,21 @@ Chapter Information
<span id="cb22-26"><a href="#cb22-26" aria-hidden="true" tabindex="-1"></a>})<span class="op">;</span> </span>
<span id="cb22-27"><a href="#cb22-27" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">addLayer</span>(smoothDrawn<span class="op">,</span> {}<span class="op">,</span> <span class="st">'Elevation zone polygon (smooth)'</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>We can see now that the polygons have more distinct shapes with many fewer small polygons in the new map (Fig. F5.1.2). It is important to note that when you use methods like focalMode (or other, similar methods such as connectedComponents and connectedPixelCount), you need to reproject according to the original image in order to display properly with zoom using the interactive Code Editor.</p>
<p><img src="../images/F5/image20.png" class="img-fluid"></p>
<p><img src="images/F5/image20.png" class="img-fluid"></p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image37.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image37.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.1.2 Before (left) and after (right) applying focalMode</figcaption><p></p>
</figure>
</div>
</section>
<section id="raster-to-points" class="level4" data-number="7.2.1.2">
<h4 data-number="7.2.1.2" class="anchored" data-anchor-id="raster-to-points"><span class="header-section-number">7.2.1.2</span> Raster to Points</h4>
<section id="raster-to-points" class="level4">
<h4 class="anchored" data-anchor-id="raster-to-points">Raster to Points</h4>
<p>Lastly, we will convert a small part of this elevation image into a point vector dataset. For this exercise, we will use the same example and build on the code from the previous subsection. This might be useful when you want to use geospatial data in a tabular format in combination with other conventional datasets such as economic indicators (Fig. F5.1.3).</p>
<p><img src="../images/F5/image24.png" class="img-fluid"></p>
<p><img src="images/F5/image24.png" class="img-fluid"></p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image11.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image11.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.1.3 Elevation point values with latitude and longitude</figcaption><p></p>
</figure>
</div>
@@ -888,7 +876,7 @@ Chapter Information
<span id="cb24-10"><a href="#cb24-10" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">addLayer</span>(elevationSamplesStratified<span class="op">,</span> {}<span class="op">,</span> <span class="st">'Stratified samples'</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="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image23.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image23.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.1.4 Stratified sampling over different elevation zones</figcaption><p></p>
</figure>
</div>
@@ -907,8 +895,8 @@ Note
</div>
</section>
</section>
<section id="a-more-complex-example" class="level3" data-number="7.2.2">
<h3 data-number="7.2.2" class="anchored" data-anchor-id="a-more-complex-example"><span class="header-section-number">7.2.2</span> 3. A More Complex Example</h3>
<section id="a-more-complex-example" class="level3">
<h3 class="anchored" data-anchor-id="a-more-complex-example">3. A More Complex Example</h3>
<p>In this section well use two global datasets, one to represent raster formats and the other vectors:</p>
<ul>
<li>The Global Forest Change (GFC) dataset: a raster dataset describing global tree cover and change for 2001present.</li>
@@ -964,7 +952,7 @@ Note
<p>This will display the boundary of the La Paya protected area and deforestation in the region (Fig. F5.1.5).</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image55.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image55.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.1.5 View of the La Paya protected area in the Colombian Amazon (in white), and deforestation over the period 20012020 (in yellows and reds, with darker colors indicating more recent changes)</figcaption><p></p>
</figure>
</div>
@@ -991,10 +979,10 @@ Note
<span id="cb26-20"><a href="#cb26-20" aria-hidden="true" tabindex="-1"></a> <span class="dt">min</span><span class="op">:</span> <span class="dv">1</span><span class="op">,</span> </span>
<span id="cb26-21"><a href="#cb26-21" aria-hidden="true" tabindex="-1"></a> <span class="dt">max</span><span class="op">:</span> <span class="dv">20</span>}<span class="op">,</span> <span class="st">'Deforestation vector'</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>Fig. F5.1.6 shows a comparison of the raster versus vector representations of deforestation within the protected area.</p>
<p><img src="../images/F5/image42.png" class="img-fluid"></p>
<p><img src="images/F5/image42.png" class="img-fluid"></p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image13.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image13.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.1.6 Raster (left) versus vector (right) representations of deforestation data of the La Paya protected area</figcaption><p></p>
</figure>
</div>
@@ -1013,7 +1001,7 @@ Note
<span id="cb27-12"><a href="#cb27-12" aria-hidden="true" tabindex="-1"></a> })<span class="op">;</span><span class="fu">print</span>(chart)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image15.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image15.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.1.7 Plot of the number of deforestation events in La Paya for the years 20012020</figcaption><p></p>
</figure>
</div>
@@ -1058,8 +1046,8 @@ Note
<p>Code Checkpoint F51b. The books repository contains a script that shows what your code should look like at this point.</p>
</div>
</div>
<section id="raster-properties-to-vector-fields" class="level4" data-number="7.2.2.1">
<h4 data-number="7.2.2.1" class="anchored" data-anchor-id="raster-properties-to-vector-fields"><span class="header-section-number">7.2.2.1</span> Raster Properties to Vector Fields</h4>
<section id="raster-properties-to-vector-fields" class="level4">
<h4 class="anchored" data-anchor-id="raster-properties-to-vector-fields">Raster Properties to Vector Fields</h4>
<p>Sometimes we want to extract information from a raster to be included in an existing vector dataset. An example might be estimating a deforestation rate for a set of protected areas. Rather than perform this task on a case-by-case basis, we can attach information generated from an image as a property of a feature.</p>
<p>The following script shows how this can be used to quantify a deforestation rate for a set of protected areas in the Colombian Amazon.</p>
<div class="sourceCode" id="cb30"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb30-1"><a href="#cb30-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Load required datasets. </span></span>
@@ -1131,11 +1119,11 @@ Note
</div>
</section>
</section>
<section id="vector-to-raster-conversion" class="level3" data-number="7.2.3">
<h3 data-number="7.2.3" class="anchored" data-anchor-id="vector-to-raster-conversion"><span class="header-section-number">7.2.3</span> Vector-to-Raster Conversion</h3>
<section id="vector-to-raster-conversion" class="level3">
<h3 class="anchored" data-anchor-id="vector-to-raster-conversion">Vector-to-Raster Conversion</h3>
<p>In Sect. 1, we used the protected area feature collection as its original vector format. In this section, we will rasterize the protected area polygons to produce a mask and use this to assess rates of forest change.</p>
<section id="polygons-to-a-mask" class="level4" data-number="7.2.3.1">
<h4 data-number="7.2.3.1" class="anchored" data-anchor-id="polygons-to-a-mask"><span class="header-section-number">7.2.3.1</span> Polygons to a Mask</h4>
<section id="polygons-to-a-mask" class="level4">
<h4 class="anchored" data-anchor-id="polygons-to-a-mask">Polygons to a Mask</h4>
<p>The most common operation to convert from vector to raster is the production of binary image masks, describing whether a pixel intersects a line or falls within a polygon. To convert from vector to a raster mask, we can use the ee.FeatureCollection.reduceToImage method. Lets continue with our example of the WDPA database and Global Forest Change data from the previous section:</p>
<div class="sourceCode" id="cb32"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb32-1"><a href="#cb32-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Load required datasets. </span></span>
<span id="cb32-2"><a href="#cb32-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> gfc <span class="op">=</span> ee<span class="op">.</span><span class="fu">Image</span>(<span class="st">'UMD/hansen/global_forest_change_2020_v1_8'</span>)<span class="op">;</span> </span>
@@ -1196,8 +1184,8 @@ Note
</div>
</div>
</section>
<section id="a-more-complex-example-1" class="level4" data-number="7.2.3.2">
<h4 data-number="7.2.3.2" class="anchored" data-anchor-id="a-more-complex-example-1"><span class="header-section-number">7.2.3.2</span> A More Complex Example</h4>
<section id="a-more-complex-example-1" class="level4">
<h4 class="anchored" data-anchor-id="a-more-complex-example-1">A More Complex Example</h4>
<p>The reduceToImage method is not the only way to convert a feature collection to an image. We will create a distance image layer from the boundary of the protected area using distance. For this example, we return to the La Paya protected area explored in Sect. 1.</p>
<div class="sourceCode" id="cb35"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb35-1"><a href="#cb35-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Load required datasets. </span></span>
<span id="cb35-2"><a href="#cb35-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> gfc <span class="op">=</span> ee<span class="op">.</span><span class="fu">Image</span>(<span class="st">'UMD/hansen/global_forest_change_2020_v1_8'</span>)<span class="op">;</span> </span>
@@ -1229,11 +1217,11 @@ Note
<span id="cb36-10"><a href="#cb36-10" aria-hidden="true" tabindex="-1"></a><span class="op">.</span><span class="fu">not</span>())<span class="op">,</span> { </span>
<span id="cb36-11"><a href="#cb36-11" aria-hidden="true" tabindex="-1"></a> <span class="dt">min</span><span class="op">:</span> <span class="dv">0</span><span class="op">,</span> </span>
<span id="cb36-12"><a href="#cb36-12" aria-hidden="true" tabindex="-1"></a> <span class="dt">max</span><span class="op">:</span> <span class="dv">20000</span>}<span class="op">,</span> <span class="st">'Distance outside protected area'</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p><img src="../images/F5/image56.png" class="img-fluid"></p>
<p><img src="../images/F5/image9.png" class="img-fluid"></p>
<p><img src="images/F5/image56.png" class="img-fluid"></p>
<p><img src="images/F5/image9.png" class="img-fluid"></p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image25.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image25.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.1.8 Distance from the La Paya boundary (left), distance within the La Paya (middle), and distance outside the La Paya (right)</figcaption><p></p>
</figure>
</div>
@@ -1263,12 +1251,12 @@ Note
<span id="cb37-22"><a href="#cb37-22" aria-hidden="true" tabindex="-1"></a> <span class="dt">min</span><span class="op">:</span> <span class="dv">0</span><span class="op">,</span> </span>
<span id="cb37-23"><a href="#cb37-23" aria-hidden="true" tabindex="-1"></a> <span class="dt">max</span><span class="op">:</span> <span class="dv">1</span><span class="op">,</span> </span>
<span id="cb37-24"><a href="#cb37-24" aria-hidden="true" tabindex="-1"></a> <span class="dt">opacity</span><span class="op">:</span> <span class="fl">0.5</span>}<span class="op">,</span> <span class="st">'Deforestation within a 5km buffer'</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p><img src="../images/F5/image22.png" class="img-fluid"></p>
<p><img src="../images/F5/image6.png" class="img-fluid"></p>
<p><img src="../images/F5/image21.png" class="img-fluid"></p>
<p><img src="images/F5/image22.png" class="img-fluid"></p>
<p><img src="images/F5/image6.png" class="img-fluid"></p>
<p><img src="images/F5/image21.png" class="img-fluid"></p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image26.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image26.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.1.9 Distance zones (top left) and deforestation by zone (&lt;1 km, &lt;3 km, and &lt;5 km)</figcaption><p></p>
</figure>
</div>
@@ -1313,8 +1301,8 @@ Note
<p>In this chapter, you learned how to convert raster to vector and vice versa. More importantly, you now have a better understanding of why and when such conversions are useful. Our examples should give you practical applications and ideas for using these techniques.</p>
</section>
</section>
<section id="zonal-statistics" class="level2" data-number="7.3">
<h2 data-number="7.3" class="anchored" data-anchor-id="zonal-statistics"><span class="header-section-number">7.3</span> Zonal Statistics</h2>
<section id="zonal-statistics" class="level2">
<h2 class="anchored" data-anchor-id="zonal-statistics">Zonal Statistics</h2>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
@@ -1365,15 +1353,15 @@ Chapter Information
<p>In fieldwork, researchers often work with plots, which are commonly recorded as polygon files or as a center point with a set radius. It is rare that plots will be set directly in the center of pixels from your desired raster dataset, and many field GPS units have positioning errors. Because of these issues, it may be important to use a statistic of adjacent pixels (as described in Chap. F3.2) to estimate the central value in whats often called a neighborhood mean or focal mean (Cansler and McKenzie 2012, Miller and Thode 2007).</p>
<p>To choose the size of your neighborhood, you will need to consider your research questions, the spatial resolution of the dataset, the size of your field plot, and the error from your GPS. For example, the raster value extracted for randomly placed 20 m diameter plots would likely merit use of a neighborhood mean when using Sentinel-2 or Landsat 8—at 10 m and 30 m spatial resolution, respectively—while using a thermal band from MODIS (Moderate Resolution Imaging Spectroradiometer) at 1000 m may not. While much of this tutorial is written with plot points and buffers in mind, a polygon asset with predefined regions will serve the same purpose.</p>
</section>
<section id="functions" class="level3" data-number="7.3.1">
<h3 data-number="7.3.1" class="anchored" data-anchor-id="functions"><span class="header-section-number">7.3.1</span> Functions</h3>
<section id="functions" class="level3">
<h3 class="anchored" data-anchor-id="functions">Functions</h3>
<p>Two functions are provided; copy and paste them into your script:</p>
<ul>
<li>A function to generate circular or square regions from buffered points</li>
<li>A function to extract image pixel neighborhood statistics for a given region</li>
</ul>
<section id="function-bufferpointsradius-bounds" class="level4" data-number="7.3.1.1">
<h4 data-number="7.3.1.1" class="anchored" data-anchor-id="function-bufferpointsradius-bounds"><span class="header-section-number">7.3.1.1</span> Function: bufferPoints(radius, bounds)</h4>
<section id="function-bufferpointsradius-bounds" class="level4">
<h4 class="anchored" data-anchor-id="function-bufferpointsradius-bounds">Function: bufferPoints(radius, bounds)</h4>
<p>Our first function, bufferPoints, returns a function for adding a buffer to points and optionally transforming to rectangular bounds</p>
<div class="sourceCode" id="cb39"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb39-1"><a href="#cb39-1" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">bufferPoints</span>(radius<span class="op">,</span> bounds) {</span>
<span id="cb39-2"><a href="#cb39-2" aria-hidden="true" tabindex="-1"></a> <span class="cf">return</span> <span class="kw">function</span>(pt) {</span>
@@ -1383,8 +1371,8 @@ Chapter Information
<span id="cb39-6"><a href="#cb39-6" aria-hidden="true" tabindex="-1"></a> }<span class="op">;</span></span>
<span id="cb39-7"><a href="#cb39-7" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</section>
<section id="function-zonalstatsfc-params" class="level4" data-number="7.3.1.2">
<h4 data-number="7.3.1.2" class="anchored" data-anchor-id="function-zonalstatsfc-params"><span class="header-section-number">7.3.1.2</span> Function: zonalStats(fc, params)</h4>
<section id="function-zonalstatsfc-params" class="level4">
<h4 class="anchored" data-anchor-id="function-zonalstatsfc-params">Function: zonalStats(fc, params)</h4>
<p>The second function, zonalStats, reduces images in an ImageCollection by regions defined in a FeatureCollection. Note that reductions can return null statistics that you might want to filter out of the resulting feature collection. Null statistics occur when there are no valid pixels intersecting the region being reduced. This situation can be caused by points that are outside of an image or in regions that are masked for quality or clouds.</p>
<p>This function is written to include many optional parameters (see Table F5.2.2). Look at the function carefully and note how it is written to include defaults that make it easy to apply the basic function while allowing customization.</p>
<p>The desired datetime format. Use ISO 8601 data string standards. The datetime string is derived from the system:time_start value of the ee.Image being reduced. Optional.</p>
@@ -1462,8 +1450,8 @@ Chapter Information
<span id="cb40-72"><a href="#cb40-72" aria-hidden="true" tabindex="-1"></a>}</span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</section>
</section>
<section id="point-collection-creation" class="level3" data-number="7.3.2">
<h3 data-number="7.3.2" class="anchored" data-anchor-id="point-collection-creation"><span class="header-section-number">7.3.2</span> Point Collection Creation</h3>
<section id="point-collection-creation" class="level3">
<h3 class="anchored" data-anchor-id="point-collection-creation">Point Collection Creation</h3>
<p>Below, we create a set of points that form the basis of the zonal statistics calculations. Note that a unique plot_id property is added to each point. A unique plot or point ID is important to include in your vector dataset for future filtering and joining.</p>
<div class="sourceCode" id="cb41"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb41-1"><a href="#cb41-1" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> pts <span class="op">=</span> ee<span class="op">.</span><span class="fu">FeatureCollection</span>([</span>
<span id="cb41-2"><a href="#cb41-2" aria-hidden="true" tabindex="-1"></a> ee<span class="op">.</span><span class="fu">Feature</span>(ee<span class="op">.</span><span class="at">Geometry</span><span class="op">.</span><span class="fu">Point</span>([<span class="op">-</span><span class="fl">118.6010</span><span class="op">,</span> <span class="fl">37.0777</span>])<span class="op">,</span> {</span>
@@ -1498,8 +1486,8 @@ Note
</div>
</div>
</section>
<section id="neighborhood-statistic-examples" class="level3" data-number="7.3.3">
<h3 data-number="7.3.3" class="anchored" data-anchor-id="neighborhood-statistic-examples"><span class="header-section-number">7.3.3</span> Neighborhood Statistic Examples</h3>
<section id="neighborhood-statistic-examples" class="level3">
<h3 class="anchored" data-anchor-id="neighborhood-statistic-examples">Neighborhood Statistic Examples</h3>
<p>The following examples demonstrate extracting raster neighborhood statistics for the following:</p>
<ul>
<li>A single raster with elevation and slope bands</li>
@@ -1507,8 +1495,8 @@ Note
<li>A multiband Landsat time series</li>
</ul>
<p>In each example, the points created in the previous section will be buffered and then used as regions to extract zonal statistics for each image in the image collection.</p>
<section id="topographic-variables" class="level4" data-number="7.3.3.1">
<h4 data-number="7.3.3.1" class="anchored" data-anchor-id="topographic-variables"><span class="header-section-number">7.3.3.1</span> Topographic Variables</h4>
<section id="topographic-variables" class="level4">
<h4 class="anchored" data-anchor-id="topographic-variables">Topographic Variables</h4>
<p>This example demonstrates how to calculate zonal statistics for a single multiband image. This Digital Elevation Model (DEM) contains a single topographic band representing elevation.</p>
<p>####Buffer the Points</p>
<p>Nex, we will apply a 45 m radius buffer to the points defined previously by mapping the bufferPoints function over the feature collection. The radius is set to 45 m to correspond to the 90 m pixel resolution of the DEM. In this case, circles are used instead of squares (set the second argument as false, i.e., do not use bounds).</p>
@@ -1559,13 +1547,13 @@ Note
<p>The result is a copy of the buffered point feature collection with new properties added for the region reduction of each selected image band according to the given reducer. A part of the FeatureCollection is shown in Fig. F5.2.1. The data in that FeatureCollection corresponds to a table containing the information of Table F5.2.3. See Fig. F5.2.2 for a graphical representation of the points and the topographic data being summarized.</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image29.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image29.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.2.1 A part of the FeatureCollection produced by calculating the zonal statistics</figcaption><p></p>
</figure>
</div>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image5.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image5.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.2.2 Sample points and topographic slope. Elevation and slope values for regions intersecting each buffered point are reduced and attached as properties of the points.</figcaption><p></p>
</figure>
</div>
@@ -1619,17 +1607,17 @@ Note
</tbody>
</table>
</section>
<section id="modis-time-series" class="level4" data-number="7.3.3.2">
<h4 data-number="7.3.3.2" class="anchored" data-anchor-id="modis-time-series"><span class="header-section-number">7.3.3.2</span> MODIS Time Series</h4>
<section id="modis-time-series" class="level4">
<h4 class="anchored" data-anchor-id="modis-time-series">MODIS Time Series</h4>
<p>A time series of MODIS eight-day surface reflectance composites demonstrates how to calculate zonal statistics for a multiband ImageCollection that requires no preprocessing, such as cloud masking or computation. Note that there is no built-in function for performing region reductions on ImageCollection objects. The zonalStats function that we are using for reduction is mapping the reduceRegions function over an ImageCollection.</p>
</section>
<section id="buffer-the-points" class="level4" data-number="7.3.3.3">
<h4 data-number="7.3.3.3" class="anchored" data-anchor-id="buffer-the-points"><span class="header-section-number">7.3.3.3</span> Buffer the Points</h4>
<section id="buffer-the-points" class="level4">
<h4 class="anchored" data-anchor-id="buffer-the-points">Buffer the Points</h4>
<p>In this example, suppose the point collection represents center points for field plots that are 100 m x 100 m, and apply a 50 m radius buffer to the points to match the size of the plot. Since we want zonal statistics for square plots, set the second argument of the bufferPoints function to true, so that the bounds of the buffered points are returned.</p>
<p>var ptsModis = pts.map(bufferPoints(50, true));</p>
</section>
<section id="calculate-zonal-statistic" class="level4" data-number="7.3.3.4">
<h4 data-number="7.3.3.4" class="anchored" data-anchor-id="calculate-zonal-statistic"><span class="header-section-number">7.3.3.4</span> Calculate Zonal Statistic</h4>
<section id="calculate-zonal-statistic" class="level4">
<h4 class="anchored" data-anchor-id="calculate-zonal-statistic">Calculate Zonal Statistic</h4>
<p>Import the MODIS 500 m global eight-day surface reflectance composite collection and filter the collection to include data for July, August, and September from 2015 through 2019.</p>
<div class="sourceCode" id="cb45"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb45-1"><a href="#cb45-1" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> modisCol <span class="op">=</span> ee<span class="op">.</span><span class="fu">ImageCollection</span>(<span class="st">'MODIS/006/MOD09A1'</span>) </span>
<span id="cb45-2"><a href="#cb45-2" aria-hidden="true" tabindex="-1"></a> <span class="op">.</span><span class="fu">filterDate</span>(<span class="st">'2015-01-01'</span><span class="op">,</span> <span class="st">'2020-01-01'</span>) </span>
@@ -1650,13 +1638,13 @@ Note
<span id="cb46-13"><a href="#cb46-13" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> ptsModisStats <span class="op">=</span> <span class="fu">zonalStats</span>(modisCol<span class="op">,</span> ptsModis<span class="op">,</span> params)<span class="op">;</span><span class="fu">print</span>(<span class="st">'Limited MODIS zonal stats table'</span><span class="op">,</span> ptsModisStats<span class="op">.</span><span class="fu">limit</span>(<span class="dv">50</span>))<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>The result is a feature collection with a feature for all combinations of plots and images. Interpreted as a table, the result has 200 rows (5 plots times 40 images) and as many columns as there are feature properties. Feature properties include those from the plot asset and the image, and any associated non-system image properties. Note that the printed results are limited to the first 50 features for brevity.</p>
</section>
<section id="landsat-time-series" class="level4" data-number="7.3.3.5">
<h4 data-number="7.3.3.5" class="anchored" data-anchor-id="landsat-time-series"><span class="header-section-number">7.3.3.5</span> Landsat Time Series</h4>
<section id="landsat-time-series" class="level4">
<h4 class="anchored" data-anchor-id="landsat-time-series">Landsat Time Series</h4>
<p>This example combines Landsat surface reflectance imagery across three instruments: Thematic Mapper (TM) from Landsat 5, Enhanced Thematic Mapper Plus (ETM+) from Landsat 7, and Operational Land Imager (OLI) from Landsat 8.</p>
<p>The following section prepares these collections so that band names are consistent and cloud masks are applied. Reflectance among corresponding bands are roughly congruent for the three sensors when using the surface reflectance product; therefore the processing steps that follow do not address inter-sensor harmonization. Review the current literature on inter-sensor harmonization practices if youd like to apply a correction.</p>
</section>
<section id="prepare-the-landsat-image-collection" class="level4" data-number="7.3.3.6">
<h4 data-number="7.3.3.6" class="anchored" data-anchor-id="prepare-the-landsat-image-collection"><span class="header-section-number">7.3.3.6</span> Prepare the Landsat Image Collection</h4>
<section id="prepare-the-landsat-image-collection" class="level4">
<h4 class="anchored" data-anchor-id="prepare-the-landsat-image-collection">Prepare the Landsat Image Collection</h4>
<p>First, define the function to mask cloud and shadow pixels (See Chap. F4.3 for more detail on cloud masking).</p>
<div class="sourceCode" id="cb47"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb47-1"><a href="#cb47-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Mask clouds from images and apply scaling factors.</span></span>
<span id="cb47-2"><a href="#cb47-2" aria-hidden="true" tabindex="-1"></a><span class="kw">function</span> <span class="fu">maskScale</span>(img) {</span>
@@ -1719,8 +1707,8 @@ Note
<p>Merge the prepared sensor collections.</p>
<div class="sourceCode" id="cb51"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb51-1"><a href="#cb51-1" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> landsatCol <span class="op">=</span> oliCol<span class="op">.</span><span class="fu">merge</span>(etmCol)<span class="op">.</span><span class="fu">merge</span>(tmCol)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
</section>
<section id="calculate-zonal-statistics" class="level4" data-number="7.3.3.7">
<h4 data-number="7.3.3.7" class="anchored" data-anchor-id="calculate-zonal-statistics"><span class="header-section-number">7.3.3.7</span> Calculate Zonal Statistics</h4>
<section id="calculate-zonal-statistics" class="level4">
<h4 class="anchored" data-anchor-id="calculate-zonal-statistics">Calculate Zonal Statistics</h4>
<p>Reduce each image in the collection by each plot according to the following parameters. Note that this example defines the imgProps and imgPropsRename parameters to copy over and rename just two selected image properties: Landsat image ID and the satellite that collected the data. It also uses the max reducer, which, as an unweighted reducer, will return the maximum value from pixels that have their centroid within the buffer (see Sect. 4.1 below for more details).</p>
<div class="sourceCode" id="cb52"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb52-1"><a href="#cb52-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Define parameters for the zonalStats function. </span></span>
<span id="cb52-2"><a href="#cb52-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> params <span class="op">=</span> { </span>
@@ -1740,8 +1728,8 @@ Note
<span id="cb52-16"><a href="#cb52-16" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(<span class="st">'Limited Landsat zonal stats table'</span><span class="op">,</span> ptsLandsatStats<span class="op">.</span><span class="fu">limit</span>(<span class="dv">50</span>))<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>The result is a feature collection with a feature for all combinations of plots and images.</p>
</section>
<section id="dealing-with-large-collections" class="level4" data-number="7.3.3.8">
<h4 data-number="7.3.3.8" class="anchored" data-anchor-id="dealing-with-large-collections"><span class="header-section-number">7.3.3.8</span> Dealing with Large Collections</h4>
<section id="dealing-with-large-collections" class="level4">
<h4 class="anchored" data-anchor-id="dealing-with-large-collections">Dealing with Large Collections</h4>
<p>If your browser times out, try exporting the results (as described in Chap. F6.2). Its likely that point feature collections that cover a large area or contain many points (point-image observations) will need to be exported as a batch task by either exporting the final feature collection as an asset or as a CSV/shapefile/GeoJSON to Google Drive or GCS.</p>
<p>Here is how you would export the above Landsat image-point feature collection to an asset and to Google Drive. Run the following code, activate the Code Editor Tasks tab, and then click the Run button. If you dont specify your own existing folder in Drive, the folder “EEFA_outputs” will be created.</p>
<div class="sourceCode" id="cb53"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb53-1"><a href="#cb53-1" aria-hidden="true" tabindex="-1"></a>Export<span class="op">.</span><span class="at">table</span><span class="op">.</span><span class="fu">toAsset</span>({ </span>
@@ -1770,15 +1758,15 @@ Note
</div>
</section>
</section>
<section id="additional-notes" class="level3" data-number="7.3.4">
<h3 data-number="7.3.4" class="anchored" data-anchor-id="additional-notes"><span class="header-section-number">7.3.4</span> Additional Notes</h3>
<section id="weighted-versus-unweighted-region-reduction" class="level4" data-number="7.3.4.1">
<h4 data-number="7.3.4.1" class="anchored" data-anchor-id="weighted-versus-unweighted-region-reduction"><span class="header-section-number">7.3.4.1</span> Weighted Versus Unweighted Region Reduction</h4>
<section id="additional-notes" class="level3">
<h3 class="anchored" data-anchor-id="additional-notes">Additional Notes</h3>
<section id="weighted-versus-unweighted-region-reduction" class="level4">
<h4 class="anchored" data-anchor-id="weighted-versus-unweighted-region-reduction">Weighted Versus Unweighted Region Reduction</h4>
<p>A region used for calculation of zonal statistics often bisects multiple pixels. Should partial pixels be included in zonal statistics? Earth Engine lets you decide by allowing you to define a reducer as either weighted or unweighted (or you can provide per-pixel weight specification as an image band). A weighted reducer will include partial pixels in the zonal statistic calculation by weighting each pixels contribution according to the fraction of the area intersecting the region. An unweighted reducer, on the other hand, gives equal weight to all pixels whose cell center intersects the region; all other pixels are excluded from calculation of the statistic.</p>
<p>For aggregate reducers like ee.Reducer.mean and ee.Reducer.median, the default mode is weighted, while identifier reducers such as ee.Reducer.min and ee.Reducer.max are unweighted. You can adjust the behavior of weighted reducers by calling unweighted on them, as in ee.Reducer.mean.unweighted. You may also specify the weights by modifying the reducer with splitWeights; however, that is beyond the scope of this book.</p>
</section>
<section id="copy-properties-to-computed-images" class="level4" data-number="7.3.4.2">
<h4 data-number="7.3.4.2" class="anchored" data-anchor-id="copy-properties-to-computed-images"><span class="header-section-number">7.3.4.2</span> Copy Properties to Computed Images</h4>
<section id="copy-properties-to-computed-images" class="level4">
<h4 class="anchored" data-anchor-id="copy-properties-to-computed-images">Copy Properties to Computed Images</h4>
<p>Derived, computed images do not retain the properties of their source image, so be sure to copy properties to computed images if you want them included in the region reduction table. For instance, consider the simple computation of unscaling Landsat SR data:</p>
<div class="sourceCode" id="cb54"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb54-1"><a href="#cb54-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Define a Landsat image. </span></span>
<span id="cb54-2"><a href="#cb54-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> img <span class="op">=</span> ee<span class="op">.</span><span class="fu">ImageCollection</span>(<span class="st">'LANDSAT/LC08/C02/T1_L2'</span>)<span class="op">.</span><span class="fu">first</span>()<span class="op">;</span> </span>
@@ -1802,8 +1790,8 @@ Note
<span id="cb55-8"><a href="#cb55-8" aria-hidden="true" tabindex="-1"></a><span class="op">.</span><span class="fu">propertyNames</span>())<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p>Now selected properties are included. Use this technique when returning computed, derived images in a mapped function, and in single-image operations.</p>
</section>
<section id="understanding-which-pixels-are-included-in-polygon-statistics" class="level4" data-number="7.3.4.3">
<h4 data-number="7.3.4.3" class="anchored" data-anchor-id="understanding-which-pixels-are-included-in-polygon-statistics"><span class="header-section-number">7.3.4.3</span> Understanding Which Pixels are Included in Polygon Statistics</h4>
<section id="understanding-which-pixels-are-included-in-polygon-statistics" class="level4">
<h4 class="anchored" data-anchor-id="understanding-which-pixels-are-included-in-polygon-statistics">Understanding Which Pixels are Included in Polygon Statistics</h4>
<p>If you want to visualize what pixels are included in a polygon for a region reducer, you can adapt the following code to use your own region (by replacing geometry), dataset, desired scale, and CRS parameters. The important part to note is that the image data you are adding to the map is reprojected using the same scale and CRS as that used in your region reduction (see Fig. F5.2.3).</p>
<div class="sourceCode" id="cb56"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb56-1"><a href="#cb56-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Define polygon geometry. </span></span>
<span id="cb56-2"><a href="#cb56-2" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> geometry <span class="op">=</span> ee<span class="op">.</span><span class="at">Geometry</span><span class="op">.</span><span class="fu">Polygon</span>( </span>
@@ -1863,7 +1851,7 @@ Note
<span id="cb57-36"><a href="#cb57-36" aria-hidden="true" tabindex="-1"></a> <span class="dt">color</span><span class="op">:</span> <span class="st">'purple'</span>}<span class="op">,</span> <span class="st">'Pixels in reduction'</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="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image44.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image44.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.2.3 Identifying pixels used in zonal statistics. By mapping the image and vector together, you can see which pixels are included in the unweighted statistic. For this example, three pixels would be included in the statistic because the polygon covers the center point of three pixels.</figcaption><p></p>
</figure>
</div>
@@ -1899,8 +1887,8 @@ Note
<p>Miller JD, Thode AE (2007) Quantifying burn severity in a heterogeneous landscape with a relative version of the delta Normalized Burn Ratio (dNBR). Remote Sens Environ 109:6680. https://doi.org/10.1016/j.rse.2006.12.006</p>
</section>
</section>
<section id="advanced-vector-operations" class="level2" data-number="7.4">
<h2 data-number="7.4" class="anchored" data-anchor-id="advanced-vector-operations"><span class="header-section-number">7.4</span> Advanced Vector Operations</h2>
<section id="advanced-vector-operations" class="level2">
<h2 class="anchored" data-anchor-id="advanced-vector-operations">Advanced Vector Operations</h2>
<div class="callout callout-style-default callout-tip callout-titled">
<div class="callout-header d-flex align-content-center">
<div class="callout-icon-container">
@@ -1936,8 +1924,8 @@ Chapter Information
</section>
</div>
</div>
<section id="visualizing-feature-collections" class="level3" data-number="7.4.1">
<h3 data-number="7.4.1" class="anchored" data-anchor-id="visualizing-feature-collections"><span class="header-section-number">7.4.1</span> Visualizing Feature Collections</h3>
<section id="visualizing-feature-collections" class="level3">
<h3 class="anchored" data-anchor-id="visualizing-feature-collections">Visualizing Feature Collections</h3>
<p>There is a distinct difference between how rasters and vectors are visualized. While images are typically visualized based on pixel values, vector layers use feature properties (i.e., attributes) to create a visualization. Vector layers are rendered on the Map by assigning a value to the red, green, and blue channels for each pixel on the screen based on the geometry and attributes of the features. The functions used for vector data visualization in Earth Engine are listed below in increasing order of complexity.</p>
<ul>
<li>Map.addLayer: As with raster layers, you can add a FeatureCollection to the Map by specifying visualization parameters. This method supports only one visualization parameter: color. All features are rendered with the specified color.</li>
@@ -1946,8 +1934,8 @@ Chapter Information
<li>style: This is the most versatile function. It can apply a different style to each feature, including color, pointSize, pointShape, width, fillColor, and lineType.</li>
</ul>
<p>In the exercises below, we will learn how to use each of these functions and see how they can generate different types of maps.</p>
<section id="creating-a-choropleth-map" class="level4" data-number="7.4.1.1">
<h4 data-number="7.4.1.1" class="anchored" data-anchor-id="creating-a-choropleth-map"><span class="header-section-number">7.4.1.1</span> Creating a Choropleth Map</h4>
<section id="creating-a-choropleth-map" class="level4">
<h4 class="anchored" data-anchor-id="creating-a-choropleth-map">Creating a Choropleth Map</h4>
<p>We will use the TIGER: US Census Blocks layer, which stores census block boundaries and their characteristics within the United States, along with the San Francisco neighborhoods layer from Chap. F5.0 to create a population density map for the city of San Francisco.</p>
<p>We start by loading the census blocks and San Francisco neighborhoods layers. We use ee.Filter.bounds to filter the census blocks layer to the San Francisco boundary.</p>
<div class="sourceCode" id="cb58"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb58-1"><a href="#cb58-1" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> blocks <span class="op">=</span> ee<span class="op">.</span><span class="fu">FeatureCollection</span>(<span class="st">'TIGER/2010/Blocks'</span>)<span class="op">;</span> </span>
@@ -1965,7 +1953,7 @@ Chapter Information
<span id="cb59-3"><a href="#cb59-3" aria-hidden="true" tabindex="-1"></a> <span class="dt">color</span><span class="op">:</span> <span class="st">'#de2d26'</span>}<span class="op">,</span> <span class="st">'Census Blocks (single color)'</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="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image34.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image34.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.3.1 San Francisco census blocks</figcaption><p></p>
</figure>
</div>
@@ -1995,13 +1983,13 @@ Chapter Information
<span id="cb62-7"><a href="#cb62-7" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">addLayer</span>(sfBlocksPaint<span class="op">.</span><span class="fu">clip</span>(geometry)<span class="op">,</span> visParams<span class="op">,</span> <span class="st">'Population Density'</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="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image41.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image41.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.3.2 San Francisco population density</figcaption><p></p>
</figure>
</div>
</section>
<section id="creating-a-categorical-map" class="level4" data-number="7.4.1.2">
<h4 data-number="7.4.1.2" class="anchored" data-anchor-id="creating-a-categorical-map"><span class="header-section-number">7.4.1.2</span> Creating a Categorical Map</h4>
<section id="creating-a-categorical-map" class="level4">
<h4 class="anchored" data-anchor-id="creating-a-categorical-map">Creating a Categorical Map</h4>
<p>Continuing the exploration of styling methods, we will now learn about draw and style. These are the preferred methods of styling for points and line layers. Lets see how we can visualize the TIGER: US Census Roads layer to create a categorical map.</p>
<p>We start by filtering the roads layer to the San Francisco boundary and using Map.addLayer to visualize it.</p>
<div class="sourceCode" id="cb63"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb63-1"><a href="#cb63-1" aria-hidden="true" tabindex="-1"></a><span class="co">// Filter roads to San Francisco boundary. </span></span>
@@ -2016,10 +2004,10 @@ Chapter Information
<span id="cb64-4"><a href="#cb64-4" aria-hidden="true" tabindex="-1"></a> <span class="dt">strokeWidth</span><span class="op">:</span> <span class="dv">1</span> </span>
<span id="cb64-5"><a href="#cb64-5" aria-hidden="true" tabindex="-1"></a>})<span class="op">;</span> </span>
<span id="cb64-6"><a href="#cb64-6" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">addLayer</span>(sfRoadsDraw<span class="op">,</span> {}<span class="op">,</span> <span class="st">'Roads (Draw)'</span>)<span class="op">;</span></span></code><button title="Copy to Clipboard" class="code-copy-button"><i class="bi"></i></button></pre></div>
<p><img src="../images/F5/image28.png" class="img-fluid"></p>
<p><img src="images/F5/image28.png" class="img-fluid"></p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image31.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image31.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.3.3 San Francisco roads rendered with a line width of 2 pixels (left) and and a line width of 1 pixel (right)</figcaption><p></p>
</figure>
</div>
@@ -2040,7 +2028,7 @@ Chapter Information
<span id="cb67-4"><a href="#cb67-4" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">addLayer</span>(sfRoadsStyle<span class="op">.</span><span class="fu">clip</span>(geometry)<span class="op">,</span> {}<span class="op">,</span> <span class="st">'Roads (Style)'</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="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image46.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image46.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.3.4 San Francisco roads rendered according to road priority</figcaption><p></p>
</figure>
</div>
@@ -2060,8 +2048,8 @@ Note
<p>Save your script for your own future use, as outlined in Chap. F1.0. Then, refresh the Code Editor to begin with a new script for the next section.</p>
</section>
</section>
<section id="joins-with-feature-collections" class="level3" data-number="7.4.2">
<h3 data-number="7.4.2" class="anchored" data-anchor-id="joins-with-feature-collections"><span class="header-section-number">7.4.2</span> Joins with Feature Collections</h3>
<section id="joins-with-feature-collections" class="level3">
<h3 class="anchored" data-anchor-id="joins-with-feature-collections">Joins with Feature Collections</h3>
<p>Earth Engine was designed as a platform for processing raster data, and that is where it shines. Over the years, it has acquired advanced vector data processing capabilities, and users are now able to carry out complex geoprocessing tasks within Earth Engine. You can leverage the distributed processing power of Earth Engine to process large vector layers in parallel.</p>
<p>This section shows how you can do spatial queries and spatial joins using multiple large feature collections. This requires the use of joins. As described for Image Collections in Chap. F4.9, a join allows you to match every item in a collection with items in another collection based on certain conditions. While you can achieve similar results using map and filter, joins perform better and give you more flexibility. We need to define the following items to perform a join on two collections.</p>
<ol type="1">
@@ -2069,8 +2057,8 @@ Note
<li>Join type: While the filter determines which features will be joined, the join type determines how they will be joined. There are many join types, including simple join, inner join, and save-all join.</li>
</ol>
<p>Joins are one of the harder skills to master, but doing so will help you perform many complex analysis tasks within Earth Engine. We will go through practical examples that will help you understand these concepts and the workflow better.</p>
<section id="selecting-by-location" class="level4" data-number="7.4.2.1">
<h4 data-number="7.4.2.1" class="anchored" data-anchor-id="selecting-by-location"><span class="header-section-number">7.4.2.1</span> Selecting by Location</h4>
<section id="selecting-by-location" class="level4">
<h4 class="anchored" data-anchor-id="selecting-by-location">Selecting by Location</h4>
<p>In this section, we will learn how to select features from one layer that are within a specified distance from features in another layer. We will continue to work with the San Francisco census blocks and roads datasets from the previous section. We will implement a join to select all blocks in San Francisco that are within 1 km of an interstate highway.</p>
<p>We start by loading the census blocks and roads collections and filtering the roads layer to the San Francisco boundary.</p>
<div class="sourceCode" id="cb68"><pre class="sourceCode js code-with-copy"><code class="sourceCode javascript"><span id="cb68-1"><a href="#cb68-1" aria-hidden="true" tabindex="-1"></a><span class="kw">var</span> blocks <span class="op">=</span> ee<span class="op">.</span><span class="fu">FeatureCollection</span>(<span class="st">'TIGER/2010/Blocks'</span>)<span class="op">;</span> </span>
@@ -2098,7 +2086,7 @@ Note
<span id="cb70-10"><a href="#cb70-10" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">addLayer</span>(interstateRoadsDrawn<span class="op">,</span> {}<span class="op">,</span> <span class="st">'Interstate Roads'</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="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image2.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image2.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.3.5 San Francisco blocks and interstate highways</figcaption><p></p>
</figure>
</div>
@@ -2123,13 +2111,13 @@ Note
<span id="cb73-5"><a href="#cb73-5" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">addLayer</span>(closeBlocksDrawn<span class="op">,</span> {}<span class="op">,</span> <span class="st">'Blocks within 1km'</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="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image40.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image40.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.3.6 Selected blocks within 1 km of an interstate highway</figcaption><p></p>
</figure>
</div>
</section>
<section id="spatial-joins" class="level4" data-number="7.4.2.2">
<h4 data-number="7.4.2.2" class="anchored" data-anchor-id="spatial-joins"><span class="header-section-number">7.4.2.2</span> Spatial Joins</h4>
<section id="spatial-joins" class="level4">
<h4 class="anchored" data-anchor-id="spatial-joins">Spatial Joins</h4>
<p>A spatial join allows you to query two collections based on the spatial relationship. We will now implement a spatial join to count points in polygons. We will work with a dataset of tree locations in San Francisco and polygons of neighborhoods to produce a CSV file with the total number of trees in each neighborhood.</p>
<p>The San Francisco Open Data Portal maintains a street tree map dataset that has a list of street trees with their latitude and longitude. We will also use the San Francisco neighborhood dataset from the same portal. We downloaded, processed, and uploaded these layers as Earth Engine assets for use in this exercise. We start by loading both layers and using the paint and style functions, covered in Sect. 1, to visualize them (Fig. F5.3.7).</p>
<p>var sfNeighborhoods = ee.FeatureCollection( projects/gee-book/assets/F5-0/SFneighborhoods);<br>
@@ -2154,7 +2142,7 @@ var sfTrees = ee.FeatureCollection( projects/gee-book/assets/F5-3/SFTrees)
<span id="cb74-18"><a href="#cb74-18" aria-hidden="true" tabindex="-1"></a><span class="bu">Map</span><span class="op">.</span><span class="fu">addLayer</span>(sfTreesStyled<span class="op">,</span> {}<span class="op">,</span> <span class="st">'SF Trees'</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="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image35.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image35.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.3.7 San Francisco neighborhoods and trees</figcaption><p></p>
</figure>
</div>
@@ -2174,7 +2162,7 @@ var sfTrees = ee.FeatureCollection( projects/gee-book/assets/F5-3/SFTrees)
<span id="cb77-3"><a href="#cb77-3" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(joined<span class="op">.</span><span class="fu">first</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="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image1.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image1.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.3.8 Result of the save-all join</figcaption><p></p>
</figure>
</div>
@@ -2186,7 +2174,7 @@ var sfTrees = ee.FeatureCollection( projects/gee-book/assets/F5-3/SFTrees)
<span id="cb78-5"><a href="#cb78-5" aria-hidden="true" tabindex="-1"></a><span class="fu">print</span>(sfNeighborhoods<span class="op">.</span><span class="fu">first</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="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image18.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image18.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.3.9 Final FeatureCollection with the new property</figcaption><p></p>
</figure>
</div>
@@ -2204,7 +2192,7 @@ var sfTrees = ee.FeatureCollection( projects/gee-book/assets/F5-3/SFTrees)
<p>The final result is a CSV file with the neighborhood names and total numbers of trees counted using the join (Fig. F5.3.10).</p>
<div class="quarto-figure quarto-figure-center">
<figure class="figure">
<p><img src="../images/F5/image3.png" class="img-fluid figure-img"></p>
<p><img src="images/F5/image3.png" class="img-fluid figure-img"></p>
<p></p><figcaption class="figure-caption">Fig. F5.3.10 Exported CSV file with tree counts for San Francisco neighborhoods</figcaption><p></p>
</figure>
</div>
@@ -2583,12 +2571,12 @@ window.document.addEventListener("DOMContentLoaded", function (event) {
<nav class="page-navigation">
<div class="nav-page nav-page-previous">
<a href="./B3_Image_Series.html" class="pagination-link">
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-number">6</span>&nbsp; <span class="chapter-title">Image Series</span></span>
<i class="bi bi-arrow-left-short"></i> <span class="nav-page-text"><span class="chapter-title">Image Series</span></span>
</a>
</div>
<div class="nav-page nav-page-next">
<a href="./C1_Lights.html" class="pagination-link">
<span class="nav-page-text"><span class="chapter-number">8</span>&nbsp; <span class="chapter-title">War at Night</span></span> <i class="bi bi-arrow-right-short"></i>
<span class="nav-page-text"><span class="chapter-title">War at Night</span></span> <i class="bi bi-arrow-right-short"></i>
</a>
</div>
</nav>