﻿{"id":5898,"date":"2018-08-07T00:19:25","date_gmt":"2018-08-06T22:19:25","guid":{"rendered":"http:\/\/www.sigterritoires.fr\/?p=5898"},"modified":"2018-10-17T12:07:41","modified_gmt":"2018-10-17T10:07:41","slug":"spatial-analysis-with-sql-4-spatial-processing-functions","status":"publish","type":"post","link":"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/","title":{"rendered":"Spatial Analysis with SQL: 4-Spatial Processing Functions"},"content":{"rendered":"<p>In the previous article we discussed <a href=\"https:\/\/translate.google.com\/translate?hl=en&amp;prev=_t&amp;sl=auto&amp;tl=en&amp;u=http:\/\/www.sigterritoires.fr\/index.php\/lanalyse-spatiale-avec-sql3-les-fonctions-de-relation-spatiale\/\">the SQL functions of spatial relationship<\/a> . Let&rsquo;s now discuss the SQL spatial processing functions. Let\u2019s start with the difference between the notion of spatial relation and spatial treatment.<\/p>\n<p>The simplest way is to use an example. We have geometries that share the occupation of space<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5899\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql41\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql41.png?fit=147%2C133&amp;ssl=1\" data-orig-size=\"147,133\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql41\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql41.png?fit=147%2C133&amp;ssl=1\" class=\"alignnone size-full wp-image-5899\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql41.png?resize=147%2C133\" alt=\"\" width=\"147\" height=\"133\" \/><\/p>\n<p>A spatial relationship function, such as <strong><em><a href=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/postgis-st-intersects-vs-st-within\/\">st_intersects<\/a><\/em><\/strong> , will answer the question \u201cdo these geometries intersect ?\u201d\u00a0 TRUE or FALSE?.<!--more--><\/p>\n<p>A spatial processing function, such as <strong><em>ST_Intersection,<\/em><\/strong> will extract the common part of the geometries returning as result a geometry :<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5900\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql42\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql42.png?fit=111%2C72&amp;ssl=1\" data-orig-size=\"111,72\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql42\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql42.png?fit=111%2C72&amp;ssl=1\" class=\"alignnone size-full wp-image-5900\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql42.png?resize=111%2C72\" alt=\"\" width=\"111\" height=\"72\" \/><\/p>\n<p>Let\u2019s suppose that we have two tables: rectangles and circles, and that we want to retrieve the result from this image. How does one design the adequate SQL query ?<\/p>\n<p>By adopting the same approach as described in the <a href=\"https:\/\/translate.google.com\/translate?hl=en&amp;prev=_t&amp;sl=auto&amp;tl=en&amp;u=http:\/\/www.sigterritoires.fr\/index.php\/lanalyse-spatiale-avec-sql2-les-fausses-idees-recues\/\">second article of this<\/a> <a href=\"https:\/\/translate.google.com\/translate?hl=en&amp;prev=_t&amp;sl=auto&amp;tl=en&amp;u=http:\/\/www.sigterritoires.fr\/index.php\/lanalyse-spatiale-avec-sql2-les-fausses-idees-recues\/\">series<\/a> :<\/p>\n<ul>\n<li>which is the data I want to obtain ?: I want the resulting geometries originating in the intersection of circles and rectangles-&gt; SELECT clause:<\/li>\n<\/ul>\n<p><strong><em>SELECT<\/em><\/strong> <strong><em>st_<\/em><\/strong> <strong><em>intersection<\/em><\/strong> <strong><em>(<\/em><\/strong> <strong><em>circles.geometry, rectangles.geometry<\/em><\/strong> <strong><em>) as geometry<\/em><\/strong><\/p>\n<ul>\n<li>where are they stored ? : in the circles and rectangles tables-&gt; FROM clause:<\/li>\n<\/ul>\n<p><strong><em>FROM<\/em><\/strong> <strong><em>circles<\/em><\/strong>,<strong><em> rectangles<\/em><\/strong><\/p>\n<ul>\n<li>which are the conditions I want to apply , spatial or not? \u00a0select only entities that occupy common space -&gt; WHERE clause:<\/li>\n<\/ul>\n<p><strong><em>\u00a0<\/em><\/strong> <strong><em>WHERE<\/em><\/strong> <strong><em>st_<\/em><\/strong> <strong><em>intersects<\/em><\/strong> <strong><em>(<\/em><\/strong> <strong><em>circles.geometry, rectangles.geometry<\/em><\/strong> <strong><em>)<\/em><\/strong><\/p>\n<p>What makes the request :<\/p>\n<p><strong><em>SELECT<\/em><\/strong> <strong><em>st_<\/em><\/strong> <strong><em>intersection<\/em><\/strong> <strong><em>(<\/em><\/strong> <strong><em>circles.geometry, rectangles.geometry<\/em><\/strong> <strong><em>) as geometry<\/em><\/strong><br \/>\n<strong><em>FROM<\/em><\/strong> <strong><em>circles, rectangles<\/em><\/strong><br \/>\n<strong><em>WHERE<\/em><\/strong> <strong><em>st_intersects<\/em><\/strong> <strong><em>(<\/em><\/strong> <strong><em>circles.geometry, rectangles.geometry<\/em><\/strong> <strong><em>)<\/em><\/strong><\/p>\n<p>You can omit the WHERE clause and get the same result, except that it will take a lot more time. It is logical to limit the operation intersection of st_intersection to places where the geometries intersect.<\/p>\n<h2><strong>The<\/strong> <strong>batch<\/strong> <strong>and interactive<\/strong><strong> tools<\/strong><\/h2>\n<p>Before discussing the spatial processing functions in detail, let\u2019s do a little parenthesis. In office GIS, such as ArcGis, you, usually, work with two groups of different tools according to what you are going to process (a layer as a whole or a specific entity).<\/p>\n<p>When processing the layer as a whole, you use the tools in the Toolbox. When processing the specific entities you use the ArcMap interactive tools.<\/p>\n<p>An advantage of SQL is that you work with only one tool. Let&rsquo;s return to the previous query to apply it at the intersections between a layer map_ risks ( in beige) \u00a0 and flooding areas ( in blue)<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5901\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql43\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql43.png?fit=805%2C803&amp;ssl=1\" data-orig-size=\"805,803\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql43\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql43.png?fit=640%2C638&amp;ssl=1\" class=\"alignnone size-medium wp-image-5901\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql43-300x300.png?resize=300%2C300\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql43.png?resize=300%2C300&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql43.png?resize=150%2C150&amp;ssl=1 150w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql43.png?resize=768%2C766&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql43.png?w=805&amp;ssl=1 805w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>We can use the query :<\/p>\n<p><strong><em>SELECT<\/em><\/strong> <strong><em>st_<\/em><\/strong> <strong><em>intersection<\/em><\/strong> <strong><em>(<\/em><\/strong> <strong><em>map_risk.geometry, flooding_zones.geometry<\/em><\/strong> <strong><em>) as geometry<\/em><\/strong><br \/>\n<strong><em>FROM<\/em><\/strong> <strong><em>map_risk, flooding_zones<\/em><\/strong><br \/>\n<strong><em>WHERE<\/em><\/strong> <strong><em>st_intersects<\/em><\/strong> <strong><em>(<\/em><\/strong> <strong><em>map_risk.geometry, flooding_zones.geometry<\/em><\/strong> <strong><em>)<\/em><\/strong><\/p>\n<p>To intersect all the present entities in the risk map with flooding areas:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5902\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql44\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql44.png?fit=697%2C683&amp;ssl=1\" data-orig-size=\"697,683\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql44\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql44.png?fit=640%2C627&amp;ssl=1\" class=\"alignnone size-medium wp-image-5902\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql44-300x294.png?resize=300%2C294\" alt=\"\" width=\"300\" height=\"294\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql44.png?resize=300%2C294&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql44.png?w=697&amp;ssl=1 697w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Where only the area with a Maximum risk for flood areas<\/p>\n<p><strong><em>SELECT<\/em><\/strong> <strong><em>st_<\/em><\/strong> <strong><em>intersection<\/em><\/strong> <strong><em>(<\/em><\/strong> <strong><em>map_risk.geometry, flooding_zones.geometry<\/em><\/strong> <strong><em>) as geometry<\/em><\/strong><br \/>\n<strong><em>FROM<\/em><\/strong> <strong><em>map_risk, flooding_zones<\/em><\/strong><br \/>\n<strong><em>WHERE<\/em><\/strong> <strong><em>st_intersects<\/em><\/strong> <strong><em>(<\/em><\/strong> <strong><em>map_risk.geometry, flooding_zones.geometry<\/em><\/strong> <strong><em>)<\/em><\/strong> AND<br \/>\nmap_risk.zone = &lsquo;max&rsquo;<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5903\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql45\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql45.png?fit=657%2C747&amp;ssl=1\" data-orig-size=\"657,747\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql45\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql45.png?fit=640%2C728&amp;ssl=1\" class=\"alignnone size-medium wp-image-5903\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql45-264x300.png?resize=264%2C300\" alt=\"\" width=\"264\" height=\"300\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql45.png?resize=264%2C300&amp;ssl=1 264w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql45.png?w=657&amp;ssl=1 657w\" sizes=\"auto, (max-width: 264px) 100vw, 264px\" \/><\/p>\n<p>The only difference is in the <strong>WHERE<\/strong> clause where we add \u00a0\u00bb \u00a0 <strong><em>AND<\/em><\/strong><br \/>\n<strong><em>map_risk.zone<\/em><\/strong> <strong><em>= &lsquo;max&rsquo;<\/em><\/strong> \u00ab<\/p>\n<h2><strong>Spatial<\/strong> <strong>processing<\/strong> <strong>functions<\/strong><\/h2>\n<p>If you take a look to the help page of ArcGis Overlay tools ( <a href=\"https:\/\/translate.google.com\/translate?hl=en&amp;prev=_t&amp;sl=auto&amp;tl=en&amp;u=https:\/\/pro.arcgis.com\/fr\/pro-app\/tool-reference\/analysis\/an-overview-of-the-overlay-toolset.htm\">https:\/\/pro.arcgis.com\/fr\/pro-app\/tool-reference\/analysis\/an-overview-of-the-overlay-toolset.htm<\/a> ) you will find a description of a series of spatial processing functions:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5904\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql46a\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql46a.png?fit=840%2C437&amp;ssl=1\" data-orig-size=\"840,437\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql46a\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql46a.png?fit=640%2C333&amp;ssl=1\" class=\"alignnone size-medium wp-image-5904\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql46a-300x156.png?resize=300%2C156\" alt=\"\" width=\"300\" height=\"156\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql46a.png?resize=300%2C156&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql46a.png?resize=768%2C400&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql46a.png?w=840&amp;ssl=1 840w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5905\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql46b\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql46b.png?fit=824%2C721&amp;ssl=1\" data-orig-size=\"824,721\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql46b\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql46b.png?fit=640%2C560&amp;ssl=1\" class=\"alignnone size-medium wp-image-5905\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql46b-300x263.png?resize=300%2C263\" alt=\"\" width=\"300\" height=\"263\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql46b.png?resize=300%2C263&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql46b.png?resize=768%2C672&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql46b.png?w=824&amp;ssl=1 824w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p>They are seven: Erase, Identity, Intersection, Spatial joint, Symmetric difference, Aggregation and Update.<\/p>\n<p>In SQL we will use only three functions: st_difference , st_intersection and ST_Union to build the equivalent queries.<\/p>\n<p>Firstly, let\u2019s discuss these three functions and their equivalent in the ArcGis Toolset , then we will discuss how to get the equivalence with others tools from the Toolset combining the three basic functions .<\/p>\n<h3><strong>st_Difference<\/strong> <strong>= Erase<\/strong><\/h3>\n<p>It bears the form st_ difference (geometry A, geometry B). This function returns the A geometry part that does not intersect the B geometry.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5906\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql47\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql47.png?fit=428%2C180&amp;ssl=1\" data-orig-size=\"428,180\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql47\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql47.png?fit=428%2C180&amp;ssl=1\" class=\"alignnone size-medium wp-image-5906\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql47-300x126.png?resize=300%2C126\" alt=\"\" width=\"300\" height=\"126\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql47.png?resize=300%2C126&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql47.png?w=428&amp;ssl=1 428w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>In the risk mapping and flood zones example we can wish, for example, to see the part of the classified areas as maximum risk that are not floodable:<\/p>\n<p>SELECT ST_ Difference (map_risk.geometry, flooding_zones.geometry) as geometry<br \/>\nFROM flooding_zones, map_risk<br \/>\nWHERE map_risk.zone = &lsquo;max&rsquo;<\/p>\n<p>The result of the query appears in yellow.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5907\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql48\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql48.png?fit=840%2C803&amp;ssl=1\" data-orig-size=\"840,803\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql48\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql48.png?fit=640%2C612&amp;ssl=1\" class=\"alignnone size-medium wp-image-5907\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql48-300x287.png?resize=300%2C287\" alt=\"\" width=\"300\" height=\"287\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql48.png?resize=300%2C287&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql48.png?resize=768%2C734&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql48.png?w=840&amp;ssl=1 840w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<h3><strong>st_intersection<\/strong> <strong>= Intersection<\/strong><\/h3>\n<p>It bears the form ST_ intersection geometry, B geometry). This function returns the part of the A geometry that intersects \u00a0 the B geometry.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5908\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql49\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql49.png?fit=409%2C207&amp;ssl=1\" data-orig-size=\"409,207\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql49\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql49.png?fit=409%2C207&amp;ssl=1\" class=\"alignnone size-medium wp-image-5908\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql49-300x152.png?resize=300%2C152\" alt=\"\" width=\"300\" height=\"152\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql49.png?resize=300%2C152&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql49.png?w=409&amp;ssl=1 409w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>We have already detailed the query<\/p>\n<p><strong><em>SELECT<\/em><\/strong> <strong><em>st_<\/em><\/strong> <strong><em>intersection<\/em><\/strong> <strong><em>(<\/em><\/strong> <strong><em>map_risk. geometry, flooding_zones.geometry<\/em><\/strong> <strong><em>) as geometry<\/em><\/strong><br \/>\n<strong><em>FROM<\/em><\/strong> <strong><em>map_risk, flooding_zones<\/em><\/strong><br \/>\n<strong><em>WHERE<\/em><\/strong> <strong><em>st_intersects<\/em><\/strong> <strong><em>(<\/em><\/strong> <strong><em>map_risk.geometry, flooding_zones.geometry<\/em><\/strong> <strong><em>)<\/em><\/strong><\/p>\n<p>in the previous paragraph dealing with batch and interactive functions. But we will complete the use of functions with another element. In the examples used so far we get as result of the query only geometries. But most of the time we, also, need to recover the attributes of the concerned entities.<\/p>\n<p>For example, in the resulting entities of the query we want to know the version of \u00a0 \u201cflooding zones\u201d as well as the risk level. We add these fields in the SELECT part of the query<\/p>\n<p><strong>SELECT<\/strong> flooding_zones.version , map_risk.zone , st_ intersection ( map_risk.geometry , flooding_zones.geometry ) as geometry<br \/>\n<strong>FROM<\/strong> map_risk, flooding_zones<br \/>\n<strong>WHERE<\/strong> st_intersects (map_risk.geometry , flooding_zones.geometry )<\/p>\n<p>and the result will be:<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5909\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql410\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql410.png?fit=840%2C501&amp;ssl=1\" data-orig-size=\"840,501\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql410\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql410.png?fit=640%2C382&amp;ssl=1\" class=\"alignnone size-medium wp-image-5909\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql410-300x179.png?resize=300%2C179\" alt=\"\" width=\"300\" height=\"179\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql410.png?resize=300%2C179&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql410.png?resize=768%2C458&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql410.png?w=840&amp;ssl=1 840w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>Attributes fields are added in the resulting table. Each geometry will have the value of the attribute of the geometries that intersect at that place.<\/p>\n<h3><strong>ST_Union<\/strong><\/h3>\n<p>It bears the form st_ union ( A geometry, B geometry). This function take each A geometry and merging with the B geometry\/es by merging the points that compose them.<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5910\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql411\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql411.png?fit=840%2C217&amp;ssl=1\" data-orig-size=\"840,217\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql411\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql411.png?fit=640%2C165&amp;ssl=1\" class=\"alignnone size-medium wp-image-5910\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql411-300x78.png?resize=300%2C78\" alt=\"\" width=\"300\" height=\"78\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql411.png?resize=300%2C78&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql411.png?resize=768%2C198&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql411.png?w=840&amp;ssl=1 840w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>If you have x geometries in A, you will have the same number of geometries in the result. It\u2019s not the number that changes but the geometry of each entity of A that associates with the space occupied with the B geometry (ies).<\/p>\n<p>This SQL function is confusing, especially in English, with the operation Union (in French Aggregation) of the ArcGis Toolset. Let&rsquo;s see immediately this one to avoid any misunderstanding.<\/p>\n<h3><strong>Union<\/strong> <strong>(Aggregation in French<\/strong>)<\/h3>\n<p>This function allows recovering all the space that is occupied by the A and B geometries:<\/p>\n<ul>\n<li>areas in which the geometries intersect<\/li>\n<li>areas where only A geometries are present<\/li>\n<li>areas where only B geometries are present<\/li>\n<\/ul>\n<p>The following scheme shows, by imputing a layer A with two rectangles, and a layer B with a circle .<\/p>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"5911\" data-permalink=\"https:\/\/www.sigterritoires.fr\/index.php\/en\/spatial-analysis-with-sql-4-spatial-processing-functions\/sql412\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql412.png?fit=840%2C402&amp;ssl=1\" data-orig-size=\"840,402\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"sql412\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql412.png?fit=640%2C306&amp;ssl=1\" class=\"alignnone size-medium wp-image-5911\" src=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql412-300x144.png?resize=300%2C144\" alt=\"\" width=\"300\" height=\"144\" srcset=\"https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql412.png?resize=300%2C144&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql412.png?resize=768%2C368&amp;ssl=1 768w, https:\/\/i0.wp.com\/www.sigterritoires.fr\/wp-content\/uploads\/2018\/08\/sql412.png?w=840&amp;ssl=1 840w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>The result of the union of these two layers includes 5 geometries:<\/p>\n<ul>\n<li>the two parts of the rectangles that do not intersect with B<\/li>\n<li>the two parts of the rectangles that intersect with the circle<\/li>\n<li>the part of the circle that does not intersect with the rectangles<\/li>\n<\/ul>\n<p>We have seen that the function ST_Union keeps the same number of A geometries A in the result. With Union Toolset, there is always more geometries in the result than in the layer A, the number depending on the intersection areas of the two layers.<\/p>\n<h3><strong>The sequel\u2026<\/strong><\/h3>\n<p>We have discussed \u00a0 the three \u00a0SQL basic functions for spatial processing. In the next article we will see how to combine these basic functions to get functions such as Identity , Aggregation and Update .<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In the previous article we discussed the SQL functions of spatial relationship . Let&rsquo;s now discuss the SQL spatial processing functions. Let\u2019s start with the difference between the notion of spatial relation and spatial treatment. The&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"give_campaign_id":0,"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sfsi_plus_gutenberg_text_before_share":"","sfsi_plus_gutenberg_show_text_before_share":"","sfsi_plus_gutenberg_icon_type":"","sfsi_plus_gutenberg_icon_alignemt":"","sfsi_plus_gutenburg_max_per_row":"","_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[1260],"tags":[],"class_list":["post-5898","post","type-post","status-publish","format-standard","hentry","category-non-classe-en"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p6XU0A-1x8","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/posts\/5898","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/comments?post=5898"}],"version-history":[{"count":0,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/posts\/5898\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/media?parent=5898"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/categories?post=5898"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sigterritoires.fr\/index.php\/wp-json\/wp\/v2\/tags?post=5898"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}