{"id":3747,"date":"2022-09-16T15:00:25","date_gmt":"2022-09-16T03:00:25","guid":{"rendered":"http:\/\/blogs.lincoln.ac.nz\/gis\/?p=3747"},"modified":"2023-05-07T02:42:40","modified_gmt":"2023-05-07T02:42:40","slug":"sometimes-simple-is-best","status":"publish","type":"post","link":"https:\/\/blogs.lincoln.ac.nz\/gis\/sometimes-simple-is-best\/","title":{"rendered":"Sometimes Simple Is Best"},"content":{"rendered":"<p><em>When faced with a potentially challenging task, a simple tool made it all possible.<\/em><\/p>\n<p>Sometimes using a simple tool can make all the difference.\u00a0 While working on a <a href=\"https:\/\/ourlandandwater.nz\/news\/designing-freshwater-monitoring-programmes-to-detect-early-improvement\/\" target=\"_blank\" rel=\"noopener noreferrer\">recent project<\/a>, one of my colleagues needed some data from the<a href=\"https:\/\/niwa.co.nz\/freshwater\/management-tools\/river-environment-classification-0\" target=\"_blank\" rel=\"noopener noreferrer\"> River Environment Classification<\/a>\u00a0(REC) dataset, developed by our good friends at NIWA.\u00a0 This is a really useful surface water layer with a number of different uses.\u00a0 Its original aim was to map all of NZ&#8217;s river reaches while also classifying them in a hierarchical schema which took into account six factors: climate, source of flow, geology, land cover, network position and valley landform.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3766\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/IMG_20220906_085803624_HDR2.jpg\" alt=\"\" width=\"1229\" height=\"1632\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/IMG_20220906_085803624_HDR2.jpg 1229w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/IMG_20220906_085803624_HDR2-226x300.jpg 226w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/IMG_20220906_085803624_HDR2-771x1024.jpg 771w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/IMG_20220906_085803624_HDR2-768x1020.jpg 768w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/IMG_20220906_085803624_HDR2-1157x1536.jpg 1157w\" sizes=\"auto, (max-width: 1229px) 100vw, 1229px\" \/><\/p>\n<p>By being able to group river reaches at a level of your choice, the results can allow you to identify reaches that have common characteristics, regardless of where they are. In other words, rivers may be geographically separated but still share common environmental factors.\u00a0 This may help with, say, finding the reaches that have characteristics beneficial for Canterbury mudfish populations or for the design of monitoring programmes.\u00a0 For many, just having a national scale layer of rivers is useful in and of itself, but there are times when the extra depth those attributes provide comes in very handy.<\/p>\n<p>Case in point: in this\u00a0project we&#8217;ve been looking at some river characteristics to support the design water quality monitoring programmes at specific sites (and oh, the (GIS) stories I could tell you&#8230;another time).\u00a0 Of particular interest for my colleague were the Climate and Source of Flow attributes in the REC data.\u00a0 And here&#8217;s where the problem arose.<\/p>\n<p>There are currently two version of REC, oddly enough known as version 1 and version 2.\u00a0 Even odder, there are some subtle differences between the two, not least is that REC1 has 576,688 reaches while REC2 has 593,517.\u00a0 My colleague has been using REC2 reaches for his modelling and we quickly saw that the Climate and Source of Flow attributes weren&#8217;t included in REC2 &#8211; data he needed for some subsequent analysis.\u00a0 At first I though there would be no big problems here\u00a0&#8211; I knew that each reach had a unique identifier and <em>surely<\/em> it&#8217;s the same in both versions, right?\u00a0 Alas, no.\u00a0 The IDs are close but are nonetheless different, so my initial thought of a <a href=\"http:\/\/blogs.lincoln.ac.nz\/gis\/a-humble-table-join-saves-the-day\/\" target=\"_blank\" rel=\"noopener noreferrer\">simple table join<\/a> wasn&#8217;t going to work.\u00a0 To make matters worse, the river lines aren&#8217;t in the same place between the two versions &#8211; in the image below, REC1 is in green and REC2 is in blue:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3748\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v1.jpg\" alt=\"\" width=\"1268\" height=\"777\" \/><\/p>\n<p><em>(Ed. Hmmmm&#8230;what&#8217;s with the jagged nature of those lines?\u00a0 And why don&#8217;t they match the basemap very well?\u00a0 C. I&#8217;ll get to that.)<\/em><\/p>\n<p>So, how am I going to transfer the attributes from V1 to V2 without there being a unique ID between the two?\u00a0 This was starting to feel like it was going to be a big job (and of course they needed these data today!)\u00a0 After I gave it some more thought, though, a very simple solution presented itself; the image above helps to illustrate &#8211; I&#8217;ll zoom in a bit:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3749\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v2.jpg\" alt=\"\" width=\"513\" height=\"313\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v2.jpg 513w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v2-300x183.jpg 300w\" sizes=\"auto, (max-width: 513px) 100vw, 513px\" \/><\/p>\n<p>Each reach has been labelled with its unique ID &#8211; you can see they&#8217;re not the same and that they are in different places, even though they are representing the same reach of the Avon.\u00a0 What I&#8217;ve got going for me is that they are <em>close<\/em> to each other, so some proximity tools might help my cause.\u00a0 Prime candidate: <a href=\"https:\/\/pro.arcgis.com\/en\/pro-app\/latest\/tool-reference\/analysis\/near.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Near<\/a>.\u00a0 This handy tool does a very simple job &#8211; it calculates the straight line distance between two features.<\/p>\n<figure id=\"attachment_3767\" aria-describedby=\"caption-attachment-3767\" style=\"width: 878px\" class=\"wp-caption alignnone\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-3767 size-full\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/near.jpg\" alt=\"\" width=\"878\" height=\"295\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/near.jpg 878w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/near-300x101.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/near-768x258.jpg 768w\" sizes=\"auto, (max-width: 878px) 100vw, 878px\" \/><figcaption id=\"caption-attachment-3767\" class=\"wp-caption-text\"><span style=\"font-size: 8pt\"><em>https:\/\/pro.arcgis.com\/en\/pro-app\/2.8\/tool-reference\/analysis\/near.htm<\/em><\/span><\/figcaption><\/figure>\n<p>While the distance is\u00a0<a href=\"https:\/\/blogs.lincoln.ac.nz\/gis\/near-and-deer\/\" target=\"_blank\" rel=\"noopener noreferrer\">often very useful<\/a>, what I&#8217;m really counting on is something that comes along for the ride.\u00a0 When\u00a0the the Near tool runs, it adds\u00a0two new fields to the input layer, NEAR_ID and NEAR_DIST.\u00a0 <em>(NB: this is one of the few tools that makes changes to the input layer rather than creating a new output layer.)<\/em>\u00a0 As you might imagine, the calculated distance is in NEAR_DIST but to solve this problem, the more valuable thing is the NEAR_ID &#8211; the ID of that nearest feature.\u00a0 If I know which feature from REC1 is nearest to its REC2 counterpart, I should be able to join the two together with a table join, et voila!<\/p>\n<p>The theory sounds good &#8211; let&#8217;s try it.\u00a0 The next few images will need some explanation.\u00a0 You&#8217;ll see both versions &#8211; REC1 is in green and REC2 is in blue, as above.\u00a0 I&#8217;ve already run the Near tool on the REC2 layer so you&#8217;ll see the NEAR_FID value which has the FID (Feature ID) of the nearest REC1 reach.\u00a0 For this first example, it seems to have worked well:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3755\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v3A.jpg\" alt=\"\" width=\"1459\" height=\"917\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v3A.jpg 1459w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v3A-300x189.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v3A-1024x644.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v3A-768x483.jpg 768w\" sizes=\"auto, (max-width: 1459px) 100vw, 1459px\" \/><\/p>\n<p>No problem here.\u00a0 I&#8217;m doing a bit of spot checking to give me confidence that the output is doing what I need to do.\u00a0 On checking one of the other ones, it didn&#8217;t look so hot:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3756\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v4.jpg\" alt=\"\" width=\"1452\" height=\"916\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v4.jpg 1452w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v4-300x189.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v4-1024x646.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v4-768x484.jpg 768w\" sizes=\"auto, (max-width: 1452px) 100vw, 1452px\" \/><\/p>\n<p>This one hasn&#8217;t worked so well &#8211; Near has identified a feature that&#8217;s nearby, but not the right one.\u00a0 I&#8217;ve got almost 600,000 reaches here and this makes me\u00a0think I can&#8217;t rely on this working for every single reach.\u00a0 I was assuming (hoping) that the tool works off the <em>centre<\/em> of each feature but based on this\u00a0I think it&#8217;s working off the first point that got created on these features.\u00a0 Quite likely this won&#8217;t work extensively, so back to the drawing board.<\/p>\n<p>That idea of the feature centre got me thinking.\u00a0 If I convert my reach lines to points, maybe I could use <em>those<\/em>\u00a0features with the Near tool.\u00a0 It&#8217;s an easy thing to do with the <a href=\"https:\/\/pro.arcgis.com\/en\/pro-app\/2.8\/tool-reference\/data-management\/feature-to-point.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Feature to Point<\/a> tool &#8211; and the point is at the geometric centre of the feature (which sometimes that means it&#8217;s not on the line).\u00a0 For the map extent above, my points look like this:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3757\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v5.jpg\" alt=\"\" width=\"1461\" height=\"634\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v5.jpg 1461w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v5-300x130.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v5-1024x444.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v5-768x333.jpg 768w\" sizes=\"auto, (max-width: 1461px) 100vw, 1461px\" \/><\/p>\n<p>It&#8217;s not perfect, but I think I&#8217;ll get some more robust results out of this.\u00a0 So, rerunning the Near tool gives me the linkage between REC2 and REC1 on the point layers:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3758\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/V6.jpg\" alt=\"\" width=\"1453\" height=\"912\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/V6.jpg 1453w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/V6-300x188.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/V6-1024x643.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/V6-768x482.jpg 768w\" sizes=\"auto, (max-width: 1453px) 100vw, 1453px\" \/><\/p>\n<p>Next to last thing to do is a table join to bring the REC1 Climate and Src_of_Flow attributes together with the REC2 reaches (right-click on the REC2_points layer &gt; Joins and Relates &gt; Add Join):<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3760\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v7.jpg\" alt=\"\" width=\"416\" height=\"538\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v7.jpg 416w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v7-232x300.jpg 232w\" sizes=\"auto, (max-width: 416px) 100vw, 416px\" \/><\/p>\n<p>(Don&#8217;t worry about the warning triangles &#8211; everything&#8217;s under control.\u00a0 <em>Ed. Yeah, right<\/em>)<\/p>\n<p>It looks like we&#8217;ve now brought the REC1 attributes into the REC2 table &#8211; which should make my colleague very happy:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3761\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v8.jpg\" alt=\"\" width=\"1258\" height=\"507\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v8.jpg 1258w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v8-300x121.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v8-1024x413.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v8-768x310.jpg 768w\" sizes=\"auto, (max-width: 1258px) 100vw, 1258px\" \/><\/p>\n<p>Last step.\u00a0 My colleague is not a GIS user.\u00a0 He&#8217;s much more of an R guy, but we still get along well.\u00a0 I know that he&#8217;d like to have a CSV (comma separated values) file to work with &#8211; easy peasy.<\/p>\n<p>With the table open, click on the three horizontal bars at upper right and choose Export:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3762\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v9.jpg\" alt=\"\" width=\"430\" height=\"591\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v9.jpg 430w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v9-218x300.jpg 218w\" sizes=\"auto, (max-width: 430px) 100vw, 430px\" \/><\/p>\n<p>Then save the output to the project folder (not the geodatabase) with a &#8220;.csv&#8221; on the end:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3763\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v10.jpg\" alt=\"\" width=\"602\" height=\"392\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v10.jpg 602w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v10-300x195.jpg 300w\" sizes=\"auto, (max-width: 602px) 100vw, 602px\" \/><\/p>\n<p>Which gives me this to email off to him (with a bit of simplifying) and then sit back and bask in the glory:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3764\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v11.jpg\" alt=\"\" width=\"654\" height=\"529\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v11.jpg 654w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2022\/09\/v11-300x243.jpg 300w\" sizes=\"auto, (max-width: 654px) 100vw, 654px\" \/><\/p>\n<p>Job done.\u00a0 I have to say that when I first got wind of\u00a0this job, I thought I was in for a whole lot of pain, perhaps even needing a Python script.\u00a0 Happily, a simple tool ended up doing the job quite nicely, or at the very least, making it much easier to do.\u00a0 Sometimes, simple is best.\u00a0 I&#8217;d venture to go a step further and say that almost <em>all<\/em> of the time, simple is best.\u00a0 Or at least as simple as possible.<\/p>\n<p>C<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When faced with a potentially challenging task, a simple tool made it all possible. Sometimes using a simple tool can make all the difference.\u00a0 While working on a recent project, one of my colleagues needed some data from the River Environment Classification\u00a0(REC) dataset, developed by our good friends at NIWA.\u00a0 This is a really useful [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":3766,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3747","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\/3747","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=3747"}],"version-history":[{"count":2,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/posts\/3747\/revisions"}],"predecessor-version":[{"id":4053,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/posts\/3747\/revisions\/4053"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/media\/3766"}],"wp:attachment":[{"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/media?parent=3747"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/categories?post=3747"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/tags?post=3747"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}