{"id":3876,"date":"2023-03-01T10:50:51","date_gmt":"2023-02-28T21:50:51","guid":{"rendered":"http:\/\/blogs.lincoln.ac.nz\/gis\/?p=3876"},"modified":"2023-03-30T04:35:26","modified_gmt":"2023-03-30T04:35:26","slug":"spatial-joins-made-easy","status":"publish","type":"post","link":"https:\/\/blogs.lincoln.ac.nz\/gis\/spatial-joins-made-easy\/","title":{"rendered":"Spatial Joins Made Easy"},"content":{"rendered":"<p><em>We cover a quick and easy way to do temporary spatial joins<\/em><\/p>\n<p>When we opened up the mail bag here at GIS Central recently, out popped a request from a colleague: &#8220;Do we have a mapping table of LAWA monitoring site names to the regional council site names?&#8221;&nbsp; Perhaps I should decode this a bit before we get to a solution.<\/p>\n<p>LAWA is <a href=\"https:\/\/www.lawa.org.nz\/\" target=\"_blank\" rel=\"noopener noreferrer\">Land, Air, Water Aoteroa<\/a>, a consortium of regional councils, DOC, MFE and <a href=\"https:\/\/www.lawa.org.nz\/about\" target=\"_blank\" rel=\"noopener noreferrer\">several others<\/a>&nbsp;(<em>Ed.:&nbsp;Egads!&nbsp; Government working together&#8230;?!?<\/em>) that aims to provide public access to&nbsp; monitoring data on our natural resources.<\/p>\n<p><a href=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/lawa.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3961\" src=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/lawa.jpg\" alt=\"\" width=\"1431\" height=\"821\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/lawa.jpg 1431w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/lawa-300x172.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/lawa-1024x587.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/lawa-768x441.jpg 768w\" sizes=\"auto, (max-width: 1431px) 100vw, 1431px\" \/><\/a><\/p>\n<p>When you want to find out which beaches have the <a href=\"https:\/\/www.lawa.org.nz\/explore-data\/swimming\/\" target=\"_blank\" rel=\"noopener noreferrer\">best water quality for swimming<\/a>, this is probably where you&#8217;ll end up:<\/p>\n<p><a href=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/swim.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3962\" src=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/swim.jpg\" alt=\"\" width=\"1599\" height=\"998\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/swim.jpg 1599w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/swim-300x187.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/swim-1024x639.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/swim-768x479.jpg 768w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/swim-1536x959.jpg 1536w\" sizes=\"auto, (max-width: 1599px) 100vw, 1599px\" \/><\/a><\/p>\n<p>My colleague had a layer of these water quality monitoring sites but the attributes didn&#8217;t include which region each site was in.&nbsp; Could GIS help?&nbsp; Absolutely.&nbsp; And in getting to a solution we discovered a nice quick way to do some temporary spatial joins.<\/p>\n<p>So let&#8217;s start with the data.&nbsp; The monitoring sites were in the form of a .gpkg file.&nbsp; The is a <a href=\"https:\/\/www.geopackage.org\/\" target=\"_blank\" rel=\"noopener noreferrer\">geopackage<\/a>, a format I&#8217;ve not come across much but is basically an open-source data container for sharing spatial data.&nbsp; It&#8217;s a nice compact way to share data as email attachments, for example.&nbsp; Pro can read these like many of the <a href=\"https:\/\/pro.arcgis.com\/en\/pro-app\/latest\/help\/data\/introduction\/data-types.htm\" target=\"_blank\" rel=\"noopener noreferrer\">data formats available<\/a>, so it was easily added to a map:<\/p>\n<p><a href=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/Map1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3964\" src=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/Map1.jpg\" alt=\"\" width=\"1103\" height=\"811\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/Map1.jpg 1103w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/Map1-300x221.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/Map1-1024x753.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/Map1-768x565.jpg 768w\" sizes=\"auto, (max-width: 1103px) 100vw, 1103px\" \/><\/a><\/p>\n<p>You can see that the attribute table is pretty simple &#8211; the main information available is the &#8220;lawaid&#8221;, a unique identifier for each of the 1,013 sites.&nbsp; What&#8217;s missing is information on what region each site is in.&nbsp; Let&#8217;s address that by adding a layer of the regional council boundaries (J:\\Data\\Administrative_Boundaries\\regional_council_2018_clipped.shp):<\/p>\n<p><a href=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/map3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3965\" src=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/map3.jpg\" alt=\"\" width=\"1137\" height=\"834\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/map3.jpg 1137w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/map3-300x220.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/map3-1024x751.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/map3-768x563.jpg 768w\" sizes=\"auto, (max-width: 1137px) 100vw, 1137px\" \/><\/a><\/p>\n<p>Also a relatively simple layer, the most useful thing being the REGC2018_1 attribute which has the name of each region.&nbsp; At this point, these are two separate layers on the map and I need to come up with some way to bring all the attributes together in to one layer, ideally so that I have a single layer with regional council names attached to each site.&nbsp; I can&#8217;t do a <a href=\"https:\/\/pro.arcgis.com\/en\/pro-app\/latest\/tool-reference\/data-management\/add-join.htm\" target=\"_blank\" rel=\"noopener noreferrer\">table join<\/a> as there&#8217;s no common attribute between the two layers so I need to use their locations do to the join.&nbsp; This suggests that I could&nbsp;use a <a href=\"https:\/\/gisgeography.com\/spatial-join\/\" target=\"_blank\" rel=\"noopener noreferrer\">spatial join<\/a> tool, such as <a href=\"https:\/\/pro.arcgis.com\/en\/pro-app\/latest\/tool-reference\/analysis\/intersect.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Intersect<\/a>, <a href=\"https:\/\/pro.arcgis.com\/en\/pro-app\/latest\/tool-reference\/analysis\/identity.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Identity <\/a>or <a href=\"https:\/\/desktop.arcgis.com\/en\/arcmap\/latest\/tools\/analysis-toolbox\/union.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Union<\/a>.&nbsp; These tools create a new layer that combines the input layers based on their locations.<\/p>\n<p>In this latest version of Pro (3.0.3 as of this writing) I discovered a handy new addition that could save me a few steps.&nbsp; In the Contents pane, clicking on the layer name gets you a context menu &#8211; we&#8217;re looking for Joins and Relates and what&#8217;s under there:<\/p>\n<p><a href=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/menu.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3966\" src=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/menu.jpg\" alt=\"\" width=\"579\" height=\"666\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/menu.jpg 579w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/menu-261x300.jpg 261w\" sizes=\"auto, (max-width: 579px) 100vw, 579px\" \/><\/a><\/p>\n<p>Those of you used to doing Table Joins will be familiar with this menu &#8211; very handy.&nbsp; The new addition here is &#8220;Add Spatial Join&#8221;, so let&#8217;s check that out.<\/p>\n<p><a href=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/join.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3967\" src=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/join.jpg\" alt=\"\" width=\"406\" height=\"322\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/join.jpg 406w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/join-300x238.jpg 300w\" sizes=\"auto, (max-width: 406px) 100vw, 406px\" \/><\/a><\/p>\n<p>The Target Features are&nbsp;the LAWA sites while the Join Features come from the regional council layer.&nbsp; Intersect is a good option for the match but be aware that there are lots of others.&nbsp; When I click OK, the attribute values from the the regional council layer that intersects with the LAWA point layer are added in the table:<\/p>\n<p><a href=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/joined.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3968\" src=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/joined.jpg\" alt=\"\" width=\"1053\" height=\"646\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/joined.jpg 1053w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/joined-300x184.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/joined-1024x628.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2023\/03\/joined-768x471.jpg 768w\" sizes=\"auto, (max-width: 1053px) 100vw, 1053px\" \/><\/a><\/p>\n<p>Nifty, now with this layer we know the region that each site is in.<\/p>\n<p>One important note is that this join is temporary.&nbsp; If I add this layer to another map, or send it to someone else, the regional council data won&#8217;t be a part of it.&nbsp; To make it permanent I would need to make a new copy of the data (right-click the layer name &gt; Data &gt; Export Features).<\/p>\n<p>My next step was to export this table as a CSV file that my colleague could use.&nbsp; Job done.<\/p>\n<p>Most of the time, GIS only gives me trouble and heartache (I exaggerate&#8230;slightly) so it was nice that I could help out a colleague and do it quite easily.&nbsp; And once again, we get to see the value of spatial joins.&nbsp; This won&#8217;t be the last time.<\/p>\n<p>C<\/p>\n","protected":false},"excerpt":{"rendered":"<p>We cover a quick and easy way to do temporary spatial joins When we opened up the mail bag here at GIS Central recently, out popped a request from a colleague: &#8220;Do we have a mapping table of LAWA monitoring site names to the regional council site names?&#8221;&nbsp; Perhaps I should decode this a bit [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":3961,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3876","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/posts\/3876","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/comments?post=3876"}],"version-history":[{"count":2,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/posts\/3876\/revisions"}],"predecessor-version":[{"id":3971,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/posts\/3876\/revisions\/3971"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/media\/3961"}],"wp:attachment":[{"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/media?parent=3876"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/categories?post=3876"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/tags?post=3876"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}