<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Raster ExtractByMask with python in Geoprocessing Questions</title>
    <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212274#M7262</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Python paths use a single forward slash /&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or double back slash \\&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;not double forward slash //&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;as you have in several places&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Mon, 19 Jul 2010 05:48:48 GMT</pubDate>
    <dc:creator>DanPatterson_Retired</dc:creator>
    <dc:date>2010-07-19T05:48:48Z</dc:date>
    <item>
      <title>Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212266#M7254</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I am trying to clip a raster with a polygon shapefile.The shapefile contains several polygons representing administrative regions. The method is to temporarily export each polygon to a new shapefile and to extract the coresponding piece of raster.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The problem is that the output of &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;gp.ExtractByMask_sa(raster, shapefile, newRaster) &lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;is always just one band of the original RGB raster. Do you know how to extract all the 3 bands? &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The original raster is .img&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jun 2010 09:39:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212266#M7254</guid>
      <dc:creator>bogdanpalade1</dc:creator>
      <dc:date>2010-06-29T09:39:24Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212267#M7255</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Check out the Clip_managment tool (&lt;/SPAN&gt;&lt;SPAN style="text-decoration:underline;"&gt;not&lt;/SPAN&gt;&lt;SPAN&gt; the Clip_analysis one). Be sure to set the snap raster in the Envr. Settings, otherwise the pixel allignment may differ from the original.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 29 Jun 2010 16:30:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212267#M7255</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-06-29T16:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212268#M7256</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hello chris,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Sorry for the late reply. Clip_management asks for a rectangle to do the clip...instead I want to use a shapefile to do the clip with.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jul 2010 20:05:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212268#M7256</guid>
      <dc:creator>bogdanpalade1</dc:creator>
      <dc:date>2010-07-07T20:05:48Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212269#M7257</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z0000002n000000.htm"&gt;http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//009z0000002n000000.htm&lt;/A&gt;&lt;BR /&gt;&lt;SPAN&gt;indicates that a grid stack is the default output, I am not using 10 so I don't know what other output options there, so check those options&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 07 Jul 2010 20:23:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212269#M7257</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2010-07-07T20:23:36Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212270#M7258</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dan,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for the reply but this works only in ArcGIS 10 environment (by the way, congrats to esri team for that although I still don't understand why only 3 bands can be extracted and not all of them since I guess that not all the people are working with RGB or pan images). I'm using 9.1 and 9.3 at the time so...I have to deal with it for the time being. &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;In the end I think I will have to do it separatly band by band and run some kind of layer stack afterwards....It will be soooo....slow!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Bogdan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 11:34:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212270#M7258</guid>
      <dc:creator>bogdanpalade1</dc:creator>
      <dc:date>2010-07-08T11:34:40Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212271#M7259</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;In v9.3.1 ArcInfo level, the Clip_managment tool does indeed have an option for using a vector featureclass as a psudo-mask (see the "in_template_dataset" parameter). This is tool to use when you have a multi-band image, since the output can be any ESRI-supported format (not just GRID like the ExtractByMask tool). Check it out...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 08 Jul 2010 15:47:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212271#M7259</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-07-08T15:47:36Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212272#M7260</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thank you Chris,&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I will check it out now...&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 09 Jul 2010 06:37:06 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212272#M7260</guid>
      <dc:creator>bogdanpalade1</dc:creator>
      <dc:date>2010-07-09T06:37:06Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212273#M7261</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Ok, so the clip_management allows me to use a feature class extent to clip the raster but it's still necessary to introduce the rectangle parameters (I thought that I could find something to substitute the rectangle by a feature class). &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Well, the initial purpose was to cut some rasters with a polygon feature class (administrative boundaries). The approach was first to extract single polygons to new feature classes and to use these to cut the rasters located in a specific folder. When I thought all was great I ran into an error: after extracting the single polygons to new shapefiles the clipping process is interupted by the following message: &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;ERROR 000732: Output Extent: Dataset 1.shp does not exist or is not supported&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Failed to execute (Clip).&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;I attached a print screen of the error message.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The script is the following:&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcgisscripting, os, string
gp = arcgisscripting.create()
gp.AddToolbox("C:/Program Files/ArcGIS/ArcToolbox/Toolboxes/Data Management Tools.tbx")
gp.SetProduct("ArcInfo")


clip = "D:/hyperspectralImages/torrejon/torrejon_ALI/clip/clip.shp"&amp;nbsp;&amp;nbsp; #the polygon feature class
rows = gp.SearchCursor(clip)
row = rows.Next()
while row:&amp;nbsp; # here I am extracting each polygon to an individual feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; FID = row.GetValue("FID")
&amp;nbsp;&amp;nbsp;&amp;nbsp; hoja = row.GetValue("hoja")
&amp;nbsp;&amp;nbsp;&amp;nbsp; Expression = '\"FID\" = ' + str(FID)
&amp;nbsp;&amp;nbsp;&amp;nbsp; outFeatures = "D://hyperspectralImages//torrejon//torrejon_ALI//outClips//"+str(hoja)+".shp" #the single fc's will be named after the field "hoja"
&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Extracting sheet number "+str(hoja)&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; #like 1.shp, 2.shp...etc
&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.Select_analysis(clip,outFeatures,Expression)
&amp;nbsp;&amp;nbsp;&amp;nbsp; row=rows.Next()
print "Finished extracting individual sheets.Begining to clip..."

inputFolder= "D:/hyperspectralImages/torrejon/torrejon_ALI/rasters" #the folder where all the rasters to be clipped are located
gp.Workspace = inputFolder
rasters = gp.ListRasters()
rasters.Reset()
raster = rasters.Next()

clipFeatures = "D://hyperspectralImages//torrejon//torrejon_ALI//outClips//" #the folder where the polygon feature classes used for clipping are located

while raster: # the loop to clip each raster by each polygon feature class
&amp;nbsp;&amp;nbsp;&amp;nbsp; for feature in os.listdir(clipFeatures):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if feature.endswith(".shp"):
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; outRaster = "D://hyperspectralImages//torrejon//torrejon_ALI//output//"+feature[0:-3]+".tif"
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Clipping "+raster+" with sheet number "+feature[0:-3]
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; gp.clip_management(raster,"446716,298473 4425996,437405 499153,348855 4492682,68626",outRaster,feature,"255","ClippingGeometry")
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 
print "Done"&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;The 1.shp, 2.shp ..and so on do exist in the right folder...&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Do you have any idea of what's happening?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Bogdan&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 10:26:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212273#M7261</guid>
      <dc:creator>bogdanpalade1</dc:creator>
      <dc:date>2021-12-11T10:26:12Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212274#M7262</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Python paths use a single forward slash /&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;or double back slash \\&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;not double forward slash //&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;as you have in several places&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 19 Jul 2010 05:48:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212274#M7262</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2010-07-19T05:48:48Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212275#M7263</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Dan, &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Thank you for your advice. I changed the paths accordingly but the problem remains the same.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jul 2010 14:00:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212275#M7263</guid>
      <dc:creator>bogdanpalade1</dc:creator>
      <dc:date>2010-07-21T14:00:43Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212276#M7264</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Try naming your shapefile something else than a number (1.shp). Generally it is a bad idea to name a layer or field with a number as the 1st character.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 21 Jul 2010 16:00:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212276#M7264</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-07-21T16:00:13Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212277#M7265</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Tried changing the shapefile name but still the same error....&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Aug 2010 08:05:34 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212277#M7265</guid>
      <dc:creator>bogdanpalade1</dc:creator>
      <dc:date>2010-08-03T08:05:34Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212278#M7266</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Not sure what's wrong... Take look at the sample code: &lt;/SPAN&gt;&lt;A href="http://forums.arcgis.com/threads/9512-Rectangle-for-Clip_management-tool-in-arcpy"&gt;http://forums.arcgis.com/threads/9512-Rectangle-for-Clip_management-tool-in-arcpy&lt;/A&gt;&lt;SPAN&gt; (my post Aug 2nd @10:25).&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Are you sure that your raster and shapefile are using the same projection?&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 03 Aug 2010 16:18:02 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212278#M7266</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2010-08-03T16:18:02Z</dc:date>
    </item>
    <item>
      <title>Re: Raster ExtractByMask with python</title>
      <link>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212279#M7267</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I had the same problem. I solved it by adding the full file path to the feature name.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;eg. pathFeature = "R:\\folderContainingShpFile\\" + str(feature)&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;gp.clip_management(raster,"446716,298473 4425996,437405 499153,348855 4492682,68626",outRaster,pathFeature,"255","ClippingGeometry")&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 05 Nov 2010 10:53:48 GMT</pubDate>
      <guid>https://community.esri.com/t5/geoprocessing-questions/raster-extractbymask-with-python/m-p/212279#M7267</guid>
      <dc:creator>JamieWilliams</dc:creator>
      <dc:date>2010-11-05T10:53:48Z</dc:date>
    </item>
  </channel>
</rss>

