<?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 Python Toolbox Raster Parameter Error in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/python-toolbox-raster-parameter-error/m-p/694571#M53856</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey all, I borrowed a simple script I found online to clip a shapefile from the extent of a raster. It works perfectly from the ArcMap built in python command prompt. I modified is slightly to use in a tool. It's having issues accepting the raster (inraster) in: &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;extent = arcpy.Raster(inRaster).extent&lt;/PRE&gt;&lt;SPAN&gt; I get the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; extent = arcpy.Raster(inRaster).extent&lt;BR /&gt;TypeError: expected a raster or layer name&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using "Raster Layer" as my inRaster parameter type. The raster type I am using is an ERDAS IMAGINE .img file. I'm thinking it must be conflicting with the parameter type and the .img input raster, but I can't figure out what it is. As I mentioned, it worked from the command prompt, just not in the tool. Any suggestions are welcome.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

inLines = arcpy.GetParameter(0)
inRaster = arcpy.GetParameter(1)
outRaster = arcpy.GetParameter(2)

pnt_array = arcpy.Array()
extent = arcpy.Raster(inRaster).extent
pnt_array.add(extent.lowerLeft)
pnt_array.add(extent.lowerRight)
pnt_array.add(extent.upperRight)
pnt_array.add(extent.upperLeft)

poly = arcpy.Polygon(pnt_array)

arcpy.Clip_analysis(inLines, poly, outRaster)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 05:13:57 GMT</pubDate>
    <dc:creator>MikeMacRae</dc:creator>
    <dc:date>2021-12-12T05:13:57Z</dc:date>
    <item>
      <title>Python Toolbox Raster Parameter Error</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-raster-parameter-error/m-p/694571#M53856</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Hey all, I borrowed a simple script I found online to clip a shapefile from the extent of a raster. It works perfectly from the ArcMap built in python command prompt. I modified is slightly to use in a tool. It's having issues accepting the raster (inraster) in: &lt;/SPAN&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;extent = arcpy.Raster(inRaster).extent&lt;/PRE&gt;&lt;SPAN&gt; I get the following error:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; extent = arcpy.Raster(inRaster).extent&lt;BR /&gt;TypeError: expected a raster or layer name&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;I'm using "Raster Layer" as my inRaster parameter type. The raster type I am using is an ERDAS IMAGINE .img file. I'm thinking it must be conflicting with the parameter type and the .img input raster, but I can't figure out what it is. As I mentioned, it worked from the command prompt, just not in the tool. Any suggestions are welcome.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Code is as follows:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;import arcpy

inLines = arcpy.GetParameter(0)
inRaster = arcpy.GetParameter(1)
outRaster = arcpy.GetParameter(2)

pnt_array = arcpy.Array()
extent = arcpy.Raster(inRaster).extent
pnt_array.add(extent.lowerLeft)
pnt_array.add(extent.lowerRight)
pnt_array.add(extent.upperRight)
pnt_array.add(extent.upperLeft)

poly = arcpy.Polygon(pnt_array)

arcpy.Clip_analysis(inLines, poly, outRaster)&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Mike&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:13:57 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-raster-parameter-error/m-p/694571#M53856</guid>
      <dc:creator>MikeMacRae</dc:creator>
      <dc:date>2021-12-12T05:13:57Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox Raster Parameter Error</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-raster-parameter-error/m-p/694572#M53857</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Think text is expected input rather than an object, so use GetParameterAsText instead...that is what the raised TypeError means, 'name' is text and GetParameter provided an 'object'.&amp;nbsp; So your suspicion is correct...&amp;nbsp; &lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;That should work, but that looks to me to be some relatively old code and I was also curious if this could be done with arcpy simply passing Extent objects or output extent env setting (rather than creating a new geom obj)?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Enjoy,&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Wayne&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 06 Apr 2013 08:58:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-raster-parameter-error/m-p/694572#M53857</guid>
      <dc:creator>T__WayneWhitley</dc:creator>
      <dc:date>2013-04-06T08:58:43Z</dc:date>
    </item>
    <item>
      <title>Re: Python Toolbox Raster Parameter Error</title>
      <link>https://community.esri.com/t5/python-questions/python-toolbox-raster-parameter-error/m-p/694573#M53858</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;GetParameterAsText() is the more general purpose solution, and it's easier to debug as what you get is text so you can print it!&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;You should use Describe() instead of Raster(), as that will successfully deal with either a raster layer or path to a raster dataset.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also - Clip_analysis will give you features out, not a raster:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy

inLines = arcpy.GetParameterAsText(0)
inRaster = arcpy.GetParameterAsText(1)
outLines = arcpy.GetParameterAsText(2)

pnt_array = arcpy.Array()
extent = arcpy.Describe(inRaster).extent
pnt_array.add(extent.XMin)
pnt_array.add(extent.YMin)
pnt_array.add(extent.XMin)
pnt_array.add(extent.YMin)
poly = arcpy.Polygon(pnt_array)
arcpy.Clip_analysis(inLines, poly, outLines)
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Also this would work just as well, as Wayne mentioned:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
import arcpy
inLines = arcpy.GetParameterAsText(0)
inRaster = arcpy.GetParameterAsText(1)
outLines = arcpy.GetParameterAsText(2)
arcpy.env.extent = inRaster
arcpy.CopyFeatures_management(inLines, outLines)
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:14:00 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/python-toolbox-raster-parameter-error/m-p/694573#M53858</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-12T05:14:00Z</dc:date>
    </item>
  </channel>
</rss>

