<?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: Map Algebra in Python Using Variable in ArcGIS Spatial Analyst Questions</title>
    <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420786#M5912</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;What would the syntax of this code look like if i were to make it a python script to import as a script tool with input and output parameters?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The normal way to provide information to an arcpy script tool is to use GetParameterAsText(), setting up the input parameter as a Raster Layer, and the output as a Raster Dataset. Raster() is used to convert the input string to a raster data arcpy map algebra can work with.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy from arcpy.sa import * inRaster = arcpy.GetParameterAsText(0) # input raster layer name or raster dataset path outRaster = arcpy.GetParameterAsText(1) # output: raster dataset&amp;nbsp; ras = Raster(inRaster) range = ras.maximum - ras.minimum mappedras = (ras - ras.minimum) / range mappedras.save(outRaster)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Beyond that, you're kind of out of the scope of this thread.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 25 Jun 2013 18:31:35 GMT</pubDate>
    <dc:creator>curtvprice</dc:creator>
    <dc:date>2013-06-25T18:31:35Z</dc:date>
    <item>
      <title>Map Algebra in Python Using Variable</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420781#M5907</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;I am trying to move from raster calculator to the python window for my spatial analysis and moving from ERDAS Model Maker altogether.&amp;nbsp; I am already struggling on only my first task.&amp;nbsp; Here I am just trying to 'scale' my raster from 0-1&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy from arcpy import env from arcpy.sa import * #Get Max and Min gridMaxResult = arcpy.GetRasterProperties_management("RASTER1", "MAXIMUM") gridMinResult = arcpy.GetRasterProperties_management("RASTER1", "MINIMUM") #Assign output gridMax = gridMaxResult.getOutput(0) gridMin = gridMinResult.getOutput(0)&amp;nbsp; #Rescale or 'normalize' OutRas = (((Raster("RASTER1") - gridMin) * (1 - 0)) / (gridMax - gridMin)) + 0 OutRas.save("NormalizedRas")&lt;/PRE&gt;&lt;BR /&gt;&lt;SPAN&gt;I get:&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;Runtime error &amp;lt;type 'exceptions.RuntimeError'&amp;gt;: ERROR 000732: Input Raster: Dataset 0 does not exist or is not supported&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;It is reading the variable correctly (gridMin is equal to 0) but it seems like it doesnt know it is a number.&amp;nbsp; Any advice would help me with this problem and my syntax going forward.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 11 Jun 2013 14:43:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420781#M5907</guid>
      <dc:creator>RustyRex</dc:creator>
      <dc:date>2013-06-11T14:43:43Z</dc:date>
    </item>
    <item>
      <title>Re: Map Algebra in Python Using Variable</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420782#M5908</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;It is reading the variable correctly (gridMin is equal to 0) but it seems like it doesnt know it is a number&lt;/BLOCKQUOTE&gt;&lt;SPAN&gt;That's because it isn't a number.&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The getOutput method returns a unicode string, see the help for the &lt;/SPAN&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//018z00000046000000" rel="nofollow noopener noreferrer" target="_blank"&gt;result object&lt;/A&gt;&lt;SPAN&gt;.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Cast your gridMax/Min variables to float before using them and the map algebra expression will work.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&amp;gt;&amp;gt;&amp;gt; type(gridMax)
&amp;lt;type 'unicode'&amp;gt;
&amp;gt;&amp;gt;&amp;gt; gridMax = float(gridMaxResult.getOutput(0))
&amp;gt;&amp;gt;&amp;gt; gridMin = float(gridMinResult.getOutput(0))&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:00:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420782#M5908</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2021-12-11T19:00:38Z</dc:date>
    </item>
    <item>
      <title>Re: Map Algebra in Python Using Variable</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420783#M5909</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;I am just trying to 'scale' my raster from 0-1&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Three thoughts:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;1) The Raster object has the properties you want without having to use that tool:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
from arcpy.sa import *
rasPath = "RASTER1"
ras = Raster(rasPath)
print ras.minimum
print ras.maximum
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;2) I think your mapping expression needs some tweaking.&lt;/SPAN&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
range = ras.maximum - ras.minimum
mappedras = (ras - ras.minimum) / range
mappedras.save("RASTER1_MAP") # save as permanent raster
&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;3) The Slice tool can be very handy for this task depending on whether you need the resolution (it outputs integers so there may be some accuracy issues with this approach).&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;
mappedras = Slice(ras, 1001, "EQUAL_INTERVAL", 0) * .001
&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 19:00:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420783#M5909</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2021-12-11T19:00:41Z</dc:date>
    </item>
    <item>
      <title>Re: Map Algebra in Python Using Variable</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420784#M5910</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Perfect, guys.&amp;nbsp; Thanks also for the other tips.&amp;nbsp; I kept my expression more complex than it needed to be so I could keep everything straight and in case I wanted to scale within a range not quite as simple as the 0-1 I have now.&amp;nbsp; But for the code I will def. construct it the way you laid it out.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 13 Jun 2013 21:28:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420784#M5910</guid>
      <dc:creator>RustyRex</dc:creator>
      <dc:date>2013-06-13T21:28:38Z</dc:date>
    </item>
    <item>
      <title>Re: Map Algebra in Python Using Variable</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420785#M5911</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;Thanks for the help.&amp;nbsp; What would the syntax of this code look like if i were to make it a python script to import as a script tool with input and output parameters?&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jun 2013 17:58:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420785#M5911</guid>
      <dc:creator>RustyRex</dc:creator>
      <dc:date>2013-06-25T17:58:23Z</dc:date>
    </item>
    <item>
      <title>Re: Map Algebra in Python Using Variable</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420786#M5912</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;BLOCKQUOTE class="jive-quote"&gt;What would the syntax of this code look like if i were to make it a python script to import as a script tool with input and output parameters?&lt;/BLOCKQUOTE&gt;&lt;BR /&gt;&lt;SPAN&gt; &lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;The normal way to provide information to an arcpy script tool is to use GetParameterAsText(), setting up the input parameter as a Raster Layer, and the output as a Raster Dataset. Raster() is used to convert the input string to a raster data arcpy map algebra can work with.&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy from arcpy.sa import * inRaster = arcpy.GetParameterAsText(0) # input raster layer name or raster dataset path outRaster = arcpy.GetParameterAsText(1) # output: raster dataset&amp;nbsp; ras = Raster(inRaster) range = ras.maximum - ras.minimum mappedras = (ras - ras.minimum) / range mappedras.save(outRaster)&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Beyond that, you're kind of out of the scope of this thread.&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 25 Jun 2013 18:31:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/map-algebra-in-python-using-variable/m-p/420786#M5912</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2013-06-25T18:31:35Z</dc:date>
    </item>
  </channel>
</rss>

