<?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: Clip Raster based on Shp with same name in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/clip-raster-based-on-shp-with-same-name/m-p/132541#M10284</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's my script.&amp;nbsp; I converted it to a toolbox.&amp;nbsp; To import to a toolbox, save it as a file (example:&amp;nbsp; AdvanceClip.py [make sure the .py is on the file name]) Right click a toolbox and Add Script, then set 3 parameters 1) Input GRIDs 2) Input Polygons 3) Output Directory.&amp;nbsp; Set them all as workspaces. This script assumes your polygons are named exactly the same as the grid files you will be clipping.&amp;nbsp; If your output directory is a folder, your file names can't be longer than 13 characters.&amp;nbsp; It's best to output to a geodatabase.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy


# Set the current workspace
arcpy.env.workspace = arcpy.GetParameterAsText(0) #"D:\\Test2\\Grids.gdb"


#Polygon Shapefiles Workspace
clipFeatures = arcpy.GetParameterAsText(1) #"D:\\Test2\\Shps\\"


#Output Directory
outDirectory = arcpy.GetParameterAsText(2) #"C:\\Users\\sgraf\\Documents\\ArcGISData\\Test2\\Outs.gdb\\"


# Get and print a list of GRIDs from the workspace
rasters = arcpy.ListRasters("*", "GRID")


for raster in rasters:


&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Clipping " + raster + " with " + raster + ".shp")


&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(clipFeatures + "\\" + raster + ".shp")&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; extent = desc.extent&amp;nbsp; 
&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_management(
&amp;nbsp;&amp;nbsp;&amp;nbsp; raster, str(extent), outDirectory + "\\" + raster, clipFeatures + "\\" + raster + ".shp", "#", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Steven&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 07:25:46 GMT</pubDate>
    <dc:creator>StevenGraf1</dc:creator>
    <dc:date>2021-12-11T07:25:46Z</dc:date>
    <item>
      <title>Clip Raster based on Shp with same name</title>
      <link>https://community.esri.com/t5/python-questions/clip-raster-based-on-shp-with-same-name/m-p/132539#M10282</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Does anyone know of a script that will iterate rasters and grab its associated shapefile (same name as raster) and clip using the two inputs?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Basically I have:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Raster1, Shapefile1&lt;/P&gt;&lt;P&gt;Raster2, Shapefile2&lt;/P&gt;&lt;P&gt;Raster3, Shapefile3&lt;/P&gt;&lt;P&gt;......&lt;/P&gt;&lt;P&gt;Raster250, Shapefile250&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I've seen some basic clip scripts that use ListRasters to iterate through rasters.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://gis.stackexchange.com/questions/84989/batch-clip-in-modelbuilder-of-arcgis-for-desktop" title="http://gis.stackexchange.com/questions/84989/batch-clip-in-modelbuilder-of-arcgis-for-desktop"&gt;Batch Clip in ModelBuilder of ArcGIS for Desktop? - Geographic Information Systems Stack Exchange&lt;/A&gt; &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I figured this most likely can't be done in Model Builder or can it?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Steven&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jul 2016 15:49:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/clip-raster-based-on-shp-with-same-name/m-p/132539#M10282</guid>
      <dc:creator>StevenGraf1</dc:creator>
      <dc:date>2016-07-18T15:49:03Z</dc:date>
    </item>
    <item>
      <title>Re: Clip Raster based on Shp with same name</title>
      <link>https://community.esri.com/t5/python-questions/clip-raster-based-on-shp-with-same-name/m-p/132540#M10283</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I wrote a small script that on first test runs seems to accomplish what I need.&amp;nbsp; I will run a few more tests and post the script.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Steven&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Mon, 18 Jul 2016 21:53:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/clip-raster-based-on-shp-with-same-name/m-p/132540#M10283</guid>
      <dc:creator>StevenGraf1</dc:creator>
      <dc:date>2016-07-18T21:53:33Z</dc:date>
    </item>
    <item>
      <title>Re: Clip Raster based on Shp with same name</title>
      <link>https://community.esri.com/t5/python-questions/clip-raster-based-on-shp-with-same-name/m-p/132541#M10284</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Here's my script.&amp;nbsp; I converted it to a toolbox.&amp;nbsp; To import to a toolbox, save it as a file (example:&amp;nbsp; AdvanceClip.py [make sure the .py is on the file name]) Right click a toolbox and Add Script, then set 3 parameters 1) Input GRIDs 2) Input Polygons 3) Output Directory.&amp;nbsp; Set them all as workspaces. This script assumes your polygons are named exactly the same as the grid files you will be clipping.&amp;nbsp; If your output directory is a folder, your file names can't be longer than 13 characters.&amp;nbsp; It's best to output to a geodatabase.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy


# Set the current workspace
arcpy.env.workspace = arcpy.GetParameterAsText(0) #"D:\\Test2\\Grids.gdb"


#Polygon Shapefiles Workspace
clipFeatures = arcpy.GetParameterAsText(1) #"D:\\Test2\\Shps\\"


#Output Directory
outDirectory = arcpy.GetParameterAsText(2) #"C:\\Users\\sgraf\\Documents\\ArcGISData\\Test2\\Outs.gdb\\"


# Get and print a list of GRIDs from the workspace
rasters = arcpy.ListRasters("*", "GRID")


for raster in rasters:


&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.AddMessage("Clipping " + raster + " with " + raster + ".shp")


&amp;nbsp;&amp;nbsp;&amp;nbsp; desc = arcpy.Describe(clipFeatures + "\\" + raster + ".shp")&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; extent = desc.extent&amp;nbsp; 
&amp;nbsp; 
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.Clip_management(
&amp;nbsp;&amp;nbsp;&amp;nbsp; raster, str(extent), outDirectory + "\\" + raster, clipFeatures + "\\" + raster + ".shp", "#", "ClippingGeometry", "NO_MAINTAIN_EXTENT")
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;-Steven&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 07:25:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/clip-raster-based-on-shp-with-same-name/m-p/132541#M10284</guid>
      <dc:creator>StevenGraf1</dc:creator>
      <dc:date>2021-12-11T07:25:46Z</dc:date>
    </item>
    <item>
      <title>Re: Clip Raster based on Shp with same name</title>
      <link>https://community.esri.com/t5/python-questions/clip-raster-based-on-shp-with-same-name/m-p/132542#M10285</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Do you want me to convert this series of posts to a discussion?&amp;nbsp; There is little point asking and answering since you are the only one that contributed.&amp;nbsp; Let me know&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2016 12:52:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/clip-raster-based-on-shp-with-same-name/m-p/132542#M10285</guid>
      <dc:creator>DanPatterson_Retired</dc:creator>
      <dc:date>2016-07-19T12:52:08Z</dc:date>
    </item>
    <item>
      <title>Re: Clip Raster based on Shp with same name</title>
      <link>https://community.esri.com/t5/python-questions/clip-raster-based-on-shp-with-same-name/m-p/132543#M10286</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Go for it, Thanks!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 19 Jul 2016 13:00:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/clip-raster-based-on-shp-with-same-name/m-p/132543#M10286</guid>
      <dc:creator>StevenGraf1</dc:creator>
      <dc:date>2016-07-19T13:00:54Z</dc:date>
    </item>
  </channel>
</rss>

