{"id":2012,"date":"2018-04-27T11:47:11","date_gmt":"2018-04-26T23:47:11","guid":{"rendered":"http:\/\/blogs.lincoln.ac.nz\/gis\/?p=2012"},"modified":"2023-05-07T03:34:26","modified_gmt":"2023-05-07T03:34:26","slug":"an-embarassment-of-contours","status":"publish","type":"post","link":"https:\/\/blogs.lincoln.ac.nz\/gis\/an-embarassment-of-contours\/","title":{"rendered":"An Embarrassment of Contours"},"content":{"rendered":"<p><em>This post discusses how a large collection of contour shapefiles were merged together, dissolved and then a subset of contours were selected and exported.<br \/>\n<\/em><\/p>\n<p>Here&#8217;s an example of a relatively quick and easy GIS job that frequently comes across my desktop.\u00a0 Woody from SOLA contacted me with a question about some data he had.\u00a0 It was 0.5 m contour data (i.e. the vertical distance between contours was 0.5 m) but he was only interested in the 5 m contours.\u00a0 0.5 m contour data is not that easy to come by, let alone 5 m, and this sounded like a nice dataset.<\/p>\n<p>Once I got a copy of the data (which he got from a surveyor) I could see that he had 43 shapefiles, each roughly between 1 and 5 Mb in size, with a contour interval of 0.5 m &#8211; sweet.\u00a0 Sounds like an easy job &#8211; just enough to keep me out of trouble for a little while.\u00a0 I looked over the attribute tables to ensure they all had the same attributes and also checked to see that they were all in the same coordinate system.\u00a0 Here&#8217;s what they looked like added to a map:<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/AllLayers.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2013\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/AllLayers.jpg\" alt=\"\" width=\"1344\" height=\"631\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/AllLayers.jpg 1344w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/AllLayers-300x141.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/AllLayers-1024x481.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/AllLayers-768x361.jpg 768w\" sizes=\"auto, (max-width: 1344px) 100vw, 1344px\" \/><\/a><\/p>\n<p>The data cover an area of around 4,000 hectares in the Canterbury high country.<\/p>\n<p>Before we go too far, note the coordinates at lower right: <a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Coords.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2016\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Coords.jpg\" alt=\"\" width=\"174\" height=\"16\" \/><\/a>.\u00a0 These stand out to a NOT being in the standard coordinate system (<a href=\"http:\/\/blogs.lincoln.ac.nz\/gis\/map-projections-3-the-tour-de-topo\/\" target=\"_blank\" rel=\"noopener noreferrer\">New Zealand Transverse Mercator<\/a>) and I suspected the data are in one of the <a href=\"https:\/\/www.linz.govt.nz\/data\/geodetic-system\/datums-projections-and-heights\/projections\/nzgd2000-meridional-circuits\" target=\"_blank\" rel=\"noopener noreferrer\">surveyor&#8217;s circuit<\/a> coordinate systems, probably the <a href=\"https:\/\/data.linz.govt.nz\/layer\/50817-nz-meridional-circuit-boundaries-nzgd2000\/\" target=\"_blank\" rel=\"noopener noreferrer\">Timaru<\/a> one.\u00a0 How did I know that they weren&#8217;t NZTM?\u00a0 Sadly, lots of time spent working with those coordinate values&#8230;\u00a0 No major problem for what we&#8217;re wanting, but it could be an issue later on he wants to use these data with other layers and this fits with one key GIS principle: Spatial Analyst, know thy data.<\/p>\n<p>So, first things first &#8211; I really don&#8217;t want to have to work with 43 separate files so I used the <a href=\"http:\/\/pro.arcgis.com\/en\/pro-app\/tool-reference\/data-management\/merge.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Merge<\/a> tool to, well, merge them all into one layer.\u00a0\u00a0 Here&#8217;s the output:<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Merged.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2017\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Merged.jpg\" alt=\"\" width=\"1346\" height=\"631\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Merged.jpg 1346w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Merged-300x141.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Merged-1024x480.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Merged-768x360.jpg 768w\" sizes=\"auto, (max-width: 1346px) 100vw, 1346px\" \/><\/a><\/p>\n<p>Now I&#8217;ve just got one layer to worry about.\u00a0 Here&#8217;s a quick look at the table to see what we&#8217;re working with:<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Table.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2018 alignleft\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Table.jpg\" alt=\"\" width=\"381\" height=\"614\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Table.jpg 381w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Table-186x300.jpg 186w\" sizes=\"auto, (max-width: 381px) 100vw, 381px\" \/><\/a>Now this is interesting.<\/p>\n<p>I&#8217;ve got my ELEVATION attribute which is important &#8211; this holds the raw data that make contours useful.\u00a0 We&#8217;ve also got this LAYER attribute which looks it might be useful for mapping &#8211; this might be an easy way to <a href=\"http:\/\/blogs.lincoln.ac.nz\/gis\/index-contours-made-easy\/\" target=\"_blank\" rel=\"noopener noreferrer\">symbolise the index and minor contours<\/a>.<\/p>\n<p>Given that I&#8217;ve got 37,391 contour features, I&#8217;m wondering if there&#8217;s a way I can simplify this layer and when I sort the ELEVATION values in ascending order, I noted that each elevation value has multiple features with the same value. For example, there are 33 features with a value of 530.5.<\/p>\n<p>This layer is a prime candidate for a <a href=\"http:\/\/pro.arcgis.com\/en\/pro-app\/tool-reference\/data-management\/dissolve.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Dissolve<\/a><\/p>\n<p>The Dissolve tool will collapse all features with the same attribute value into one feature.\u00a0 So instead of having 33 features with a value of 530.5 we&#8217;ll end up with one.\u00a0 The only potential downside of this is that all those individual features will be treated as one feature, so if I select any one of the contours on the map, all 33 pieces of it will get selected.\u00a0 Probably okay in this case, but something to be aware of.<\/p>\n<p>Here&#8217;s how I set up the tool:<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/DissolveTool2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2021\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/DissolveTool2.jpg\" alt=\"\" width=\"448\" height=\"373\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/DissolveTool2.jpg 448w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/DissolveTool2-300x250.jpg 300w\" sizes=\"auto, (max-width: 448px) 100vw, 448px\" \/><\/a><\/p>\n<p>By ticking both LAYER and ELEVATION, the tool will compress all those features with the same value into one feature.\u00a0 After running the tool, here&#8217;s my table:<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Table2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2022 alignright\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Table2.jpg\" alt=\"\" width=\"382\" height=\"468\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Table2.jpg 382w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Table2-245x300.jpg 245w\" sizes=\"auto, (max-width: 382px) 100vw, 382px\" \/><\/a>We&#8217;ve now got only 569 records and each one has a unique value.<\/p>\n<p>With a bit more inspection, it turns out the the &#8220;Major&#8221; value in the LAYER is exactly what I need &#8211; all of the &#8220;Major&#8221; values are divisible by 5.<\/p>\n<p>So that thoughtful surveyor has added an attribute that suddenly makes this job a lot easier.<\/p>\n<p>All I really have to do is run a query (<a href=\"http:\/\/desktop.arcgis.com\/en\/arcmap\/10.3\/map\/working-with-layers\/using-select-by-attributes.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Select by Attribute<\/a>) to find all the records where the LAYER attribute is equal to &#8220;Major&#8221;<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Select.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-2023 alignnone\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Select.jpg\" alt=\"\" width=\"392\" height=\"511\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Select.jpg 392w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/Select-230x300.jpg 230w\" sizes=\"auto, (max-width: 392px) 100vw, 392px\" \/><\/a><\/p>\n<p>Then I can export these records to a new shapefile by right-clicking on the layer name and going to Data &gt; Export Data.\u00a0 This results in a new shapefile with just the 5 m contours in it.\u00a0 A key idea here is that if I&#8217;ve got any records selected when I run most geoprocessing tools, it will only work on those selected records &#8211; that&#8217;s an important factor that should <em><strong>always<\/strong> <\/em>be borne in mind.\u00a0 Here are those features overlain on the original data (5 m contours in black):<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/FinalContours.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2025\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/FinalContours.jpg\" alt=\"\" width=\"1028\" height=\"703\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/FinalContours.jpg 1028w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/FinalContours-300x205.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/FinalContours-1024x700.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/04\/FinalContours-768x525.jpg 768w\" sizes=\"auto, (max-width: 1028px) 100vw, 1028px\" \/><\/a><\/p>\n<p>So just to summarise, I started with 43 separate shapefiles, all with the same attributes and coordinates system.\u00a0 Then I merged them together and dissolved the features based on the elevation values and type of contour.\u00a0 To get just the 5 m contours I used a query to select them and the exported those selected features.\u00a0 Here&#8217;s a flow diagram that summarises this process graphically:<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/05\/FlowD2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2060\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/05\/FlowD2.jpg\" alt=\"\" width=\"1397\" height=\"153\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/05\/FlowD2.jpg 1397w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/05\/FlowD2-300x33.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/05\/FlowD2-1024x112.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2018\/05\/FlowD2-768x84.jpg 768w\" sizes=\"auto, (max-width: 1397px) 100vw, 1397px\" \/><\/a><\/p>\n<p>Job done.\u00a0 Now I can go off and see what other sorts of spatial trouble I can get myself into.\u00a0 It usually seems to find me&#8230;<\/p>\n<p>C<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post discusses how a large collection of contour shapefiles were merged together, dissolved and then a subset of contours were selected and exported. Here&#8217;s an example of a relatively quick and easy GIS job that frequently comes across my desktop.\u00a0 Woody from SOLA contacted me with a question about some data he had.\u00a0 It [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2012","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/posts\/2012","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=2012"}],"version-history":[{"count":1,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/posts\/2012\/revisions"}],"predecessor-version":[{"id":4122,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/posts\/2012\/revisions\/4122"}],"wp:attachment":[{"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/media?parent=2012"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/categories?post=2012"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/tags?post=2012"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}