{"id":214,"date":"2013-05-07T23:45:25","date_gmt":"2013-05-07T23:45:25","guid":{"rendered":"http:\/\/www.lincoln.ac.nz\/conversation\/gis\/?p=214"},"modified":"2023-05-07T00:20:18","modified_gmt":"2023-05-07T00:20:18","slug":"how-do-i-clip-raster-data","status":"publish","type":"post","link":"https:\/\/blogs.lincoln.ac.nz\/gis\/how-do-i-clip-raster-data\/","title":{"rendered":"How do I clip raster data?"},"content":{"rendered":"<p><em>This post covers how to clip out portions of <strong>raster grids <\/strong><strong>(updated May 2021 for Pro)<\/strong>. <\/em><\/p>\n<p>A previous post covered how to <a title=\"How do I Clip Data?\" href=\"http:\/\/blogs.lincoln.ac.nz\/gis\/how-do-i-clip-data\/\" target=\"_blank\" rel=\"noopener noreferrer\">clip vector data<\/a> (feature classes and shapefiles). \u00a0Another key skill is being able to clip out portions of raster grids, such as a DEM, or perhaps a TIF image. \u00a0We&#8217;ve got three options really &#8211; use a <a href=\"https:\/\/pro.arcgis.com\/en\/pro-app\/latest\/tool-reference\/data-management\/clip.htm\" target=\"_blank\" rel=\"noopener noreferrer\">raster Clip<\/a> tool, use the <a href=\"https:\/\/pro.arcgis.com\/en\/pro-app\/latest\/tool-reference\/spatial-analyst\/extract-by-mask.htm\" target=\"_blank\" rel=\"noopener noreferrer\">Extract by Mask<\/a> tool, or carry it out as a raster calculation. \u00a0I&#8217;ll cover all three methods in this post. \u00a0Let&#8217;s use the example of clipping out the Lyttelton Harbour Basin from the DEM of the South Island (this is the one I used for the post on <a href=\"http:\/\/www.lincoln.ac.nz\/conversation\/gis\/data-with-a-view-2\/\">viewsheds<\/a>). \u00a0Here&#8217;s a map with the DEM on it (added as J:\\Data\\Digital_Elevation_Models\\sidem):<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3001\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM.jpg\" alt=\"\" width=\"1631\" height=\"887\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM.jpg 1631w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM-300x163.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM-1024x557.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM-768x418.jpg 768w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM-1536x835.jpg 1536w\" sizes=\"auto, (max-width: 1631px) 100vw, 1631px\" \/><\/a><\/p>\n<p>(Note that you can always click on the image for a bigger view of it.) \u00a0As with any clip operation, a boundary is needed and more often than not, it&#8217;s a vector polygon. \u00a0I <a title=\"How do I create a new feature class\/shapefile?\" href=\"http:\/\/blogs.lincoln.ac.nz\/gis\/how-do-i-create-a-new-feature-classshapefile\/\" target=\"_blank\" rel=\"noopener noreferrer\">created a polygon layer<\/a> that defined the boundary of the area I wanted to clip.<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/DEMwithClip-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3002\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/DEMwithClip-1.jpg\" alt=\"\" width=\"1629\" height=\"879\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/DEMwithClip-1.jpg 1629w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/DEMwithClip-1-300x162.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/DEMwithClip-1-1024x553.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/DEMwithClip-1-768x414.jpg 768w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/DEMwithClip-1-1536x829.jpg 1536w\" sizes=\"auto, (max-width: 1629px) 100vw, 1629px\" \/><\/a><\/p>\n<p>Now I&#8217;ve got the choice of using a raster clip tool or doing a raster calculation. \u00a0We&#8217;ll look at both now.<\/p>\n<h4><strong>Raster Clip Tool<\/strong><\/h4>\n<p>One quick way to see if there&#8217;s anything that might suit in ArcToolbox is to do a Search on the available tools. \u00a0You could click on the Search button at the top of the Geoprocessing pane &#8211; type &#8220;clip raster&#8221; into the search window and click the Tools link to get this result:<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/Search-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3003\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/Search-1.jpg\" alt=\"\" width=\"282\" height=\"463\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/Search-1.jpg 282w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/Search-1-183x300.jpg 183w\" sizes=\"auto, (max-width: 282px) 100vw, 282px\" \/><\/a><\/p>\n<p>The tool at the top looks like it might do the trick. \u00a0It will ultimately, but we need to be a bit careful about how we set it up. \u00a0Opening the tool brings up this window:<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipTool2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3005\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipTool2.jpg\" alt=\"\" width=\"282\" height=\"396\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipTool2.jpg 282w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipTool2-214x300.jpg 214w\" sizes=\"auto, (max-width: 282px) 100vw, 282px\" \/><\/a><\/p>\n<p>I&#8217;ve set my DEM as the Input Raster, LyttClip as the Output Extent and saved the output somewhere safe. \u00a0I haven&#8217;t worried about the NoData Value but <strong>*importantly*<\/strong> note that I&#8217;ve ticked the &#8220;Use Input Features for Clipping Geometry&#8221; box. \u00a0This means that my output raster will be clipped to the extent of my polygon. \u00a0If I don&#8217;t tick this the output is going to be a rectangle that is the smallest one that contains the polygon (I&#8217;ll show you what I mean later&#8230;).\u00a0 Just to be safe I also tick the &#8220;Maintain Clipping Extent&#8221; box.\u00a0 Executing the tool gets me this (with the DEM turned off and a different colour ramp so you can see the result better):<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithTool-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3006\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithTool-1.jpg\" alt=\"\" width=\"1634\" height=\"879\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithTool-1.jpg 1634w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithTool-1-300x161.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithTool-1-1024x551.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithTool-1-768x413.jpg 768w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithTool-1-1536x826.jpg 1536w\" sizes=\"auto, (max-width: 1634px) 100vw, 1634px\" \/><\/a><\/p>\n<p>If I hadn&#8217;t ticked that box, here&#8217;s what it would have looked like:<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithToolUnticked-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3007\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithToolUnticked-1.jpg\" alt=\"\" width=\"1631\" height=\"876\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithToolUnticked-1.jpg 1631w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithToolUnticked-1-300x161.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithToolUnticked-1-1024x550.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithToolUnticked-1-768x412.jpg 768w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ClipwithToolUnticked-1-1536x825.jpg 1536w\" sizes=\"auto, (max-width: 1631px) 100vw, 1631px\" \/><\/a><\/p>\n<p>So with this output I&#8217;ve got all the data within the polygon, but I&#8217;ve also got some areas of essentially no data in the bounding rectangle (or at least data that aren&#8217;t correct.) \u00a0Ticking the box makes for a cleaner output that should match other data clipped to the same boundary.<\/p>\n<p><strong>Extract by Mask Tool<\/strong><\/p>\n<p>Another tool we could use is in <span style=\"color: #0000ff\">ArcToolbox &gt; Spatial Analyst Tools &gt; Extraction &gt; Extract by Mask<\/span>. \u00a0This is a pretty straightforward tool to use and produces the same output as shown above:<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ExtractByMask-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3008\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/ExtractByMask-1.jpg\" alt=\"\" width=\"280\" height=\"246\" \/><\/a><\/p>\n<p><strong>Raster Calculation<\/strong><\/p>\n<p>We can also do our clip as a raster calculation, using the same clip polygon. \u00a0It&#8217;s a bit more complicated but achieves the same end. \u00a0Open up the Raster Calculator from <span style=\"color: #0000ff\">ArcToolbox &gt; Spatial Analyst Tools &gt; Map Algebra &gt; Raster Calculator.<\/span><\/p>\n<h1><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/Calculator-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3009\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/Calculator-1.jpg\" alt=\"\" width=\"283\" height=\"421\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/Calculator-1.jpg 283w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/Calculator-1-202x300.jpg 202w\" sizes=\"auto, (max-width: 283px) 100vw, 283px\" \/><\/a><\/h1>\n<p>Here I&#8217;ve double-clicked on the grid I want to clip, sidem, and set my Output Raster name. \u00a0Before we do the calculation, click the <span style=\"color: #0000ff\">Environments<\/span> button.\u00a0 We can set a lot of tool parameters here but we&#8217;re most interested in what&#8217;s in the Raster Analysis specifically the Mask setting.\u00a0 Here I set it to my clip layer:<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/Environments-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3010\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/Environments-1.jpg\" alt=\"\" width=\"286\" height=\"673\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/Environments-1.jpg 286w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/Environments-1-127x300.jpg 127w\" sizes=\"auto, (max-width: 286px) 100vw, 286px\" \/><\/a><\/p>\n<p>The Cell Size should automatically be picked up by the resolution of your input grid. \u00a0Here&#8217;s the output:<\/p>\n<p><a href=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-3011\" src=\"https:\/\/d-blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM-1.jpg\" alt=\"\" width=\"1635\" height=\"874\" srcset=\"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM-1.jpg 1635w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM-1-300x160.jpg 300w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM-1-1024x547.jpg 1024w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM-1-768x411.jpg 768w, https:\/\/blogs.lincoln.ac.nz\/gis\/wp-content\/uploads\/sites\/3\/2013\/05\/NewDEM-1-1536x821.jpg 1536w\" sizes=\"auto, (max-width: 1635px) 100vw, 1635px\" \/><\/a><\/p>\n<p>It should be exactly the same. \u00a0Two things to note, the raster calculation takes a bit longer to execute (actually a lot longer), and the Mask needs to be reset everytime you carry out a calculation &#8211; otherwise you&#8217;ll just get a copy of the whole grid.<\/p>\n<p>To be honest, I&#8217;ve almost always used the raster calculation method, but having just gone through both, I think I&#8217;ll start using the Clip Raster tool instead &#8211; it&#8217;s faster and a bit less fiddly.<\/p>\n<p>Now that I&#8217;ve clipped my DEM I could use it to derive slope or aspect or create a hillshade from and it will be far quicker than if I had used the whole DEM and will take up less space on my local drive.<\/p>\n<p>We can use these tools on just about any grid, with the exception of multi-band grids, like JPGs or some satellite imagery. \u00a0Most grids and images (e.g. TIFs) contain one &#8220;band&#8221; of information. \u00a0JPGs are actually composed of three bands, one each for red, green and blue colours. \u00a0Some satellite imagery has up to six or seven bands! \u00a0Clipping out portions of these grids is a much more complicated process and warrants a separate post (my list of those is getting longer and longer&#8230;)<\/p>\n<p><span style=\"font-size: small\">C<\/span><\/p>\n<p><span style=\"font-size: small\">\u00a0<\/span><\/p>\n<p><span style=\"font-size: small\"><span style=\"line-height: 24px\">\u00a0<\/span><\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>This post covers how to clip out portions of raster grids (updated May 2021 for Pro). A previous post covered how to clip vector data (feature classes and shapefiles). \u00a0Another key skill is being able to clip out portions of raster grids, such as a DEM, or perhaps a TIF image. \u00a0We&#8217;ve got three options [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-214","post","type-post","status-publish","format-standard","hentry","category-common-how-to-questions"],"_links":{"self":[{"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/posts\/214","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=214"}],"version-history":[{"count":1,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/posts\/214\/revisions"}],"predecessor-version":[{"id":3986,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/posts\/214\/revisions\/3986"}],"wp:attachment":[{"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/media?parent=214"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/categories?post=214"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.lincoln.ac.nz\/gis\/wp-json\/wp\/v2\/tags?post=214"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}