<?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 Conbining rasters with con/isnull in Python Snippets Questions</title>
    <link>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700027#M1</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A few days ago I was building a cost surface (so maybe this belongs in the Spatial Analyst section).&lt;/P&gt;&lt;P&gt;The input was an extensive roads network, with different classes of roads (HIGHWAY", "MAJOR ROAD", etc).&lt;/P&gt;&lt;P&gt;I separated out each type, and rasterized the vectors, with an "impedance" value. This sort of equates to the speed of the road, or rather the times to pass through each pixel of the raster. So a highway would have less impedance than a street.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I had to combine these all back together to form my cost surface using con/isnull functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was contemplating how to put together a multiple embedded con / isnull when I though I would give this a try.&lt;/P&gt;&lt;P&gt;It worked perfectly, and was very fast. The raster size was +16000 by +14000.&lt;/P&gt;&lt;P&gt;featList is an ordered in priority list of my road classes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;cntFeat = 0
for r in featList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; rName = r[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp; if rName in rasList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cntFeat += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Processing {}".format(rName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if cntFeat == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ras = Float(arcpy.Raster(rName)) / 100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ras2 = Float(arcpy.Raster(rName)) / 100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ras = Con(IsNull(Ras), Ras2, Ras)
Ras = Con(IsNull(Ras), secsPerCellOther, Ras)
Ras.save("Imp_Final")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This iterative approach is a good one to remember.&lt;/P&gt;&lt;P&gt;btw, the individual inputs were turned into LONG (16bit type) after X 100 just to save some space &amp;amp; time.&lt;/P&gt;&lt;P&gt;I could not get feature to raster to output anything other than a 64bit raster if the input variable was a double.&lt;/P&gt;&lt;P&gt;Also could not get env.compression to work either.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Sun, 12 Dec 2021 05:28:14 GMT</pubDate>
    <dc:creator>NeilAyres</dc:creator>
    <dc:date>2021-12-12T05:28:14Z</dc:date>
    <item>
      <title>Conbining rasters with con/isnull</title>
      <link>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700027#M1</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;A few days ago I was building a cost surface (so maybe this belongs in the Spatial Analyst section).&lt;/P&gt;&lt;P&gt;The input was an extensive roads network, with different classes of roads (HIGHWAY", "MAJOR ROAD", etc).&lt;/P&gt;&lt;P&gt;I separated out each type, and rasterized the vectors, with an "impedance" value. This sort of equates to the speed of the road, or rather the times to pass through each pixel of the raster. So a highway would have less impedance than a street.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Then I had to combine these all back together to form my cost surface using con/isnull functions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I was contemplating how to put together a multiple embedded con / isnull when I though I would give this a try.&lt;/P&gt;&lt;P&gt;It worked perfectly, and was very fast. The raster size was +16000 by +14000.&lt;/P&gt;&lt;P&gt;featList is an ordered in priority list of my road classes.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;cntFeat = 0
for r in featList:
&amp;nbsp;&amp;nbsp;&amp;nbsp; rName = r[1]
&amp;nbsp;&amp;nbsp;&amp;nbsp; if rName in rasList:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cntFeat += 1
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; print "Processing {}".format(rName)
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if cntFeat == 1:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ras = Float(arcpy.Raster(rName)) / 100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; else:
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ras2 = Float(arcpy.Raster(rName)) / 100
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Ras = Con(IsNull(Ras), Ras2, Ras)
Ras = Con(IsNull(Ras), secsPerCellOther, Ras)
Ras.save("Imp_Final")&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This iterative approach is a good one to remember.&lt;/P&gt;&lt;P&gt;btw, the individual inputs were turned into LONG (16bit type) after X 100 just to save some space &amp;amp; time.&lt;/P&gt;&lt;P&gt;I could not get feature to raster to output anything other than a 64bit raster if the input variable was a double.&lt;/P&gt;&lt;P&gt;Also could not get env.compression to work either.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 05:28:14 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700027#M1</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2021-12-12T05:28:14Z</dc:date>
    </item>
    <item>
      <title>Re: Conbining rasters with con/isnull</title>
      <link>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700028#M2</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I have seen some discussions on the pixeltype which takes up more space than necessary depending the workspace used (grids vs raster in a fgdb).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;What I have done in the past, when I need to combine a lot of rasters with nodata is to use the &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//009z0000007q000000"&gt;Cell Statistics (Spatial Analyst)&lt;/A&gt; tool. This takes care of the NoData values too.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/migrated-users/5327"&gt;Neil Ayres&lt;/A&gt; , is this a question? If not could you un-mark the discussion as a question?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;H1 style="margin-bottom: 0.2em; font-size: 22px; font-weight: normal; font-family: 'Avenir LT W01 55 Roman', Arial, Helvetica, sans-serif; color: #000000;"&gt;&lt;/H1&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 13:05:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700028#M2</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-04-30T13:05:33Z</dc:date>
    </item>
    <item>
      <title>Re: Conbining rasters with con/isnull</title>
      <link>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700029#M3</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Xander,&lt;/P&gt;&lt;P&gt;no I suppose this is not a question. Just an interesting method. So, I would if I knew how....&lt;/P&gt;&lt;P&gt;Marked it "Assumed answered" instead, so you got the &lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/plus.png" /&gt;.&lt;/P&gt;&lt;P&gt;Don't see how Cell Statistics could help for this data. I wanted each new raster to be added only if the existing raster is null. And in my priority order. As the iteration loop indicates.&lt;/P&gt;&lt;P&gt;I was quite surprised how fast this loop was, each only taking a sec or so. The time consuming bit was the save at the end.&lt;/P&gt;&lt;P&gt;Do you have any insight on how or if the bit depth of the output can be controlled?&lt;/P&gt;&lt;P&gt;Or even why the environment compression setting doesn't seem to be honoured.&lt;/P&gt;&lt;P&gt;My version 10.2.2.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 13:20:18 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700029#M3</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2015-04-30T13:20:18Z</dc:date>
    </item>
    <item>
      <title>Re: Conbining rasters with con/isnull</title>
      <link>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700030#M4</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi &lt;A href="https://community.esri.com/migrated-users/5327"&gt;Neil Ayres&lt;/A&gt; ,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I suppose my procedure was different, but in my case it turned out to be more effective to combine the rasters with the weights using the Cell Statistics tool. Your fast results look promising, will keep it in mind the next time I have a similar challenge.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;There are a number of threads on automatic bit depth promotion. Many refer to this Help topic:&lt;/P&gt;&lt;P&gt;&lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//009t0000002s000000"&gt;Bit depth capacity for raster dataset cells&lt;/A&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 13:33:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700030#M4</guid>
      <dc:creator>XanderBakker</dc:creator>
      <dc:date>2015-04-30T13:33:29Z</dc:date>
    </item>
    <item>
      <title>Re: Conbining rasters with con/isnull</title>
      <link>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700031#M5</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Neil check out &lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/message/401195"&gt;Implementing merge() in ArcPy map algebra&lt;/A&gt;​&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 15:22:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700031#M5</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2015-04-30T15:22:52Z</dc:date>
    </item>
    <item>
      <title>Re: Conbining rasters with con/isnull</title>
      <link>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700032#M6</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;&amp;gt; I couldn't get env.compression to work &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;These settings do not apply to all formats, many only apply to geodatabase rasters.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: arial, helvetica, 'helvetica neue', verdana, sans-serif;"&gt;You also may have better luck getting those raster environments recognized CopyRaster tool instead of the .save() method. (I have learned you can provide a (temp) raster object as input to CopyRaster).&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 30 Apr 2015 15:25:54 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700032#M6</guid>
      <dc:creator>curtvprice</dc:creator>
      <dc:date>2015-04-30T15:25:54Z</dc:date>
    </item>
    <item>
      <title>Re: Conbining rasters with con/isnull</title>
      <link>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700033#M7</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Curtis,&lt;/P&gt;&lt;P&gt;that is what I did afterwards (Copy Raster), to bring the final bit depth down from 64bit to 32bit.&lt;/P&gt;&lt;P&gt;My rasters were in an fgdb.&lt;/P&gt;&lt;P&gt;Maybe it is an idea to have an environment setting for the bit depth?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I see in your 2nd script you pointed to in your link is exactly the same approach.&lt;/P&gt;&lt;P&gt;I am obviously following in the steps of the master...&lt;IMG src="https://community.esri.com/legacyfs/online/emoticons/cool.png" /&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 May 2015 06:13:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-snippets-questions/conbining-rasters-with-con-isnull/m-p/700033#M7</guid>
      <dc:creator>NeilAyres</dc:creator>
      <dc:date>2015-05-01T06:13:20Z</dc:date>
    </item>
  </channel>
</rss>

