<?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: simple Raster Calculator question in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/simple-raster-calculator-question/m-p/112882#M8805</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It took me a while to get the syntax of the new map algebra figured out too.... Here's some examples of building some more complex expressions (see the last half):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Process: Set some envr variables - Note: ExtractByMask tool takes care of this for us
inDem = root + "\\dem"
arcpy.env.extent = areaIdPolyFC
arcpy.env.cellSize = inDem
cellSize = float(arcpy.env.cellSize)

#Process: Extract the input DEM
demGrd = areaIdFolderPath + "\\dem"
demTmp = arcpy.sa.ExtractByMask(inDem, areaIdPolyFC); showGpMessage()
demTmp.save(demGrd)

#Process: Run a Fill
fillTmp = arcpy.sa.Fill(demTmp, ""); showGpMessage()
fillGrd = areaIdFolderPath + "\\fill"
fillTmp.save(fillGrd)

#Process: FlowDir
flowDirTmp = arcpy.sa.FlowDirection(fillTmp, "", ""); showGpMessage()
flowDirGrd = areaIdFolderPath + "\\flowdir"
flowDirTmp.save(flowDirGrd)

#Process: Delete fillTmp since we don't need it anymore&amp;nbsp;&amp;nbsp;&amp;nbsp; 
arcpy.Delete_management(fillTmp); showGpMessage()

#Process: FlowAcc
flowAccTmp = arcpy.sa.FlowAccumulation(flowDirTmp, "", "INTEGER"); showGpMessage()
flowAccGrd = areaIdFolderPath + "\\flowacc"
flowAccTmp.save(flowAccGrd)&amp;nbsp;&amp;nbsp;&amp;nbsp; 

#Process: Create a streamlink
acreThreshold = .25
acreThresholdInPixels = int(43560 * acreThreshold / cellSize ** 2)
streamLinkTmp = arcpy.sa.StreamLink(arcpy.sa.Con(flowAccTmp &amp;gt; acreThresholdInPixels, 1), flowDirTmp); showGpMessage()
streamLinkGrd = areaIdFolderPath + "\\streamlink"
streamLinkTmp.save(streamLinkGrd)
if streamLinkTmp.hasRAT == False:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.BuildRasterAttributeTable_management(streamLinkTmp, ""); showGpMessage()&amp;nbsp;&amp;nbsp; 

#Process: Zonal stats for elev and delete elev since we don't need it anymore 
elevationZoneStatTbl = fgdbPath + "\\elevation_zn_stats"
arcpy.sa.ZonalStatisticsAsTable(streamLinkTmp, "VALUE", demTmp, elevationZoneStatTbl, "DATA", "MIN_MAX_MEAN"); showGpMessage()

#Process: Curvature and zonal stats
curvePlanGrd = areaIdFolderPath + "\\curve_plan"
curveTmp = arcpy.sa.Curvature(demTmp, "", "", curvePlanGrd)
arcpy.Delete_management(curveTmp); showGpMessage()
curvePlanTmp = arcpy.sa.Raster(curvePlanGrd)
curvePlan3Tmp = arcpy.sa.FocalStatistics(curvePlanTmp, arcpy.sa.NbrRectangle(3, 3, "CELL"), "MEAN", "DATA"); showGpMessage()
arcpy.Delete_management(curvePlanTmp); showGpMessage()
curvePlan3Grd = areaIdFolderPath + "\\curve3_plan"
curvePlan3Tmp.save(curvePlan3Grd)
curvePlan3ZoneStatTbl = fgdbPath + "\\curve_plan3_zn_stats"
arcpy.sa.ZonalStatisticsAsTable(streamLinkTmp, "VALUE", curvePlan3Tmp, curvePlan3ZoneStatTbl, "DATA", "MEAN"); showGpMessage()
arcpy.Delete_management(curvePlan3Tmp); showGpMessage()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sat, 11 Dec 2021 06:44:32 GMT</pubDate>
    <dc:creator>ChrisSnyder</dc:creator>
    <dc:date>2021-12-11T06:44:32Z</dc:date>
    <item>
      <title>simple Raster Calculator question</title>
      <link>https://community.esri.com/t5/python-questions/simple-raster-calculator-question/m-p/112879#M8802</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;hi, I'm completely new to Python and I'm just trying to run a basic Raster Calculator operation, just pulling out cells below a certain elevation.&amp;nbsp;&amp;nbsp; The code appears to run just fine but in my output, all the cells have a zero value, i.e. there are no cells with a value of "1" that satisfy the selection.&amp;nbsp; I know this is not the case.&amp;nbsp; Just trying to figure out what's wrong.&amp;nbsp; Really appreciate any help...here's my code:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;&amp;gt;&amp;gt;&amp;gt; import arcpy &amp;gt;&amp;gt;&amp;gt; from arcpy import env &amp;gt;&amp;gt;&amp;gt; from arcpy.sa import * &amp;gt;&amp;gt;&amp;gt; arcpy.CheckOutExtension("Spatial") &amp;gt;&amp;gt;&amp;gt; env.workspace = "c:/stuff/SeaLevelRiseAdaptation/10YearStepRasters/Hampton" &amp;gt;&amp;gt;&amp;gt; env.cellSize = 3.28 &amp;gt;&amp;gt;&amp;gt; env.extent = "MyElevation" &amp;gt;&amp;gt;&amp;gt; env.mask = "MyElevation" &amp;gt;&amp;gt;&amp;gt; arcpy.gp.RasterCalculator_sa("MyElevation" &amp;lt; 2.22,"C:/stuff/SeaLevelRiseAdaptation/10YearStepRasters/Hampton/Highest/2052_zone1") &amp;lt;geoprocessing server result object object at 0x257BFF20&amp;gt;&lt;/PRE&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;SPAN&gt;Thanks much!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 May 2013 13:04:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-raster-calculator-question/m-p/112879#M8802</guid>
      <dc:creator>DanielSchatt</dc:creator>
      <dc:date>2013-05-01T13:04:58Z</dc:date>
    </item>
    <item>
      <title>Re: simple Raster Calculator question</title>
      <link>https://community.esri.com/t5/python-questions/simple-raster-calculator-question/m-p/112880#M8803</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;How about:&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="plain" name="code"&gt;import arcpy arcpy.CheckOutExtension("Spatial") arcpy.env.workspace = "c:/stuff/SeaLevelRiseAdaptation/10YearStepRasters/Hampton" arcpy.env.cellSize = 3.28 arcpy.env.extent = "myelevation" #the raster 'myelevation' exists in arcpy.env.workspace, correct? arcpy.env.mask = "myelevation" input1 = arcpy.Raster("myelevation") #you must define your input rasters as a "raster object" in order to use them in the new raster algebra (next line) result1 =&amp;nbsp; input1 &amp;lt; 2.22 #once they are raster objects, Python "just knows" what to do... result1.save("my_result") #run a .save() to permanently save the result to disk, otherwise the 'result1' raster object gets a funny scratch name and poofs away when you close python&lt;/PRE&gt;&lt;DIV style="display:none;"&gt; &lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 01 May 2013 15:38:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-raster-calculator-question/m-p/112880#M8803</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2013-05-01T15:38:11Z</dc:date>
    </item>
    <item>
      <title>Re: simple Raster Calculator question</title>
      <link>https://community.esri.com/t5/python-questions/simple-raster-calculator-question/m-p/112881#M8804</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;thanks Chris!&lt;/SPAN&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 May 2013 12:58:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-raster-calculator-question/m-p/112881#M8804</guid>
      <dc:creator>DanielSchatt</dc:creator>
      <dc:date>2013-05-02T12:58:19Z</dc:date>
    </item>
    <item>
      <title>Re: simple Raster Calculator question</title>
      <link>https://community.esri.com/t5/python-questions/simple-raster-calculator-question/m-p/112882#M8805</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;SPAN&gt;It took me a while to get the syntax of the new map algebra figured out too.... Here's some examples of building some more complex expressions (see the last half):&lt;/SPAN&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;#Process: Set some envr variables - Note: ExtractByMask tool takes care of this for us
inDem = root + "\\dem"
arcpy.env.extent = areaIdPolyFC
arcpy.env.cellSize = inDem
cellSize = float(arcpy.env.cellSize)

#Process: Extract the input DEM
demGrd = areaIdFolderPath + "\\dem"
demTmp = arcpy.sa.ExtractByMask(inDem, areaIdPolyFC); showGpMessage()
demTmp.save(demGrd)

#Process: Run a Fill
fillTmp = arcpy.sa.Fill(demTmp, ""); showGpMessage()
fillGrd = areaIdFolderPath + "\\fill"
fillTmp.save(fillGrd)

#Process: FlowDir
flowDirTmp = arcpy.sa.FlowDirection(fillTmp, "", ""); showGpMessage()
flowDirGrd = areaIdFolderPath + "\\flowdir"
flowDirTmp.save(flowDirGrd)

#Process: Delete fillTmp since we don't need it anymore&amp;nbsp;&amp;nbsp;&amp;nbsp; 
arcpy.Delete_management(fillTmp); showGpMessage()

#Process: FlowAcc
flowAccTmp = arcpy.sa.FlowAccumulation(flowDirTmp, "", "INTEGER"); showGpMessage()
flowAccGrd = areaIdFolderPath + "\\flowacc"
flowAccTmp.save(flowAccGrd)&amp;nbsp;&amp;nbsp;&amp;nbsp; 

#Process: Create a streamlink
acreThreshold = .25
acreThresholdInPixels = int(43560 * acreThreshold / cellSize ** 2)
streamLinkTmp = arcpy.sa.StreamLink(arcpy.sa.Con(flowAccTmp &amp;gt; acreThresholdInPixels, 1), flowDirTmp); showGpMessage()
streamLinkGrd = areaIdFolderPath + "\\streamlink"
streamLinkTmp.save(streamLinkGrd)
if streamLinkTmp.hasRAT == False:
&amp;nbsp;&amp;nbsp;&amp;nbsp; arcpy.BuildRasterAttributeTable_management(streamLinkTmp, ""); showGpMessage()&amp;nbsp;&amp;nbsp; 

#Process: Zonal stats for elev and delete elev since we don't need it anymore 
elevationZoneStatTbl = fgdbPath + "\\elevation_zn_stats"
arcpy.sa.ZonalStatisticsAsTable(streamLinkTmp, "VALUE", demTmp, elevationZoneStatTbl, "DATA", "MIN_MAX_MEAN"); showGpMessage()

#Process: Curvature and zonal stats
curvePlanGrd = areaIdFolderPath + "\\curve_plan"
curveTmp = arcpy.sa.Curvature(demTmp, "", "", curvePlanGrd)
arcpy.Delete_management(curveTmp); showGpMessage()
curvePlanTmp = arcpy.sa.Raster(curvePlanGrd)
curvePlan3Tmp = arcpy.sa.FocalStatistics(curvePlanTmp, arcpy.sa.NbrRectangle(3, 3, "CELL"), "MEAN", "DATA"); showGpMessage()
arcpy.Delete_management(curvePlanTmp); showGpMessage()
curvePlan3Grd = areaIdFolderPath + "\\curve3_plan"
curvePlan3Tmp.save(curvePlan3Grd)
curvePlan3ZoneStatTbl = fgdbPath + "\\curve_plan3_zn_stats"
arcpy.sa.ZonalStatisticsAsTable(streamLinkTmp, "VALUE", curvePlan3Tmp, curvePlan3ZoneStatTbl, "DATA", "MEAN"); showGpMessage()
arcpy.Delete_management(curvePlan3Tmp); showGpMessage()&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 11 Dec 2021 06:44:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/simple-raster-calculator-question/m-p/112882#M8805</guid>
      <dc:creator>ChrisSnyder</dc:creator>
      <dc:date>2021-12-11T06:44:32Z</dc:date>
    </item>
  </channel>
</rss>

