<?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 Using Raster Calculator in Python Scripts in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/using-raster-calculator-in-python-scripts/m-p/730146#M56635</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a question regarding the using &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//009z000000z7000000"&gt;Raster Calculator&lt;/A&gt; expressions (+, -, *, /, log, sin) in &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Creating_a_new_Python_script/002100000020000000/"&gt;Python Scripts&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I generated a model in &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//002w00000001000000"&gt;Model Builder&lt;/A&gt; and exported them into Python Script. Then I implemented my script as a new &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//003q00000017000000.htm"&gt;tool in a toolbox&lt;/A&gt;. However, because in some steps in my model I used Raster calculator the tool does not work. I have an &lt;A href="http://support.esri.com/ja/knowledgebase/techarticles/detail/41859"&gt;ERROR 000539&lt;/A&gt;: Error running expression: rcexec() As I have found in the error link, the problem is that Python Scripts are not using Raster Calculation Expressions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anybody know if there is some way (other than this in the error link) to implement Raster Calculator expressions to Python Scripts?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below are examples of expressions which I want to use in Python Script:&lt;/P&gt;&lt;P&gt;arcpy.gp.RasterCalculator_sa("(\"%2.tif%\") - (\"%3.tif%\")", v4_tif)&lt;/P&gt;&lt;P&gt;arcpy.gp.RasterCalculator_sa("Cos(\"%5.tif%\")", v6_tif)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 02 Jul 2015 11:02:36 GMT</pubDate>
    <dc:creator>KarolinaKorzeniowska</dc:creator>
    <dc:date>2015-07-02T11:02:36Z</dc:date>
    <item>
      <title>Using Raster Calculator in Python Scripts</title>
      <link>https://community.esri.com/t5/python-questions/using-raster-calculator-in-python-scripts/m-p/730146#M56635</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I have a question regarding the using &lt;A href="http://resources.arcgis.com/en/help/main/10.2/index.html#//009z000000z7000000"&gt;Raster Calculator&lt;/A&gt; expressions (+, -, *, /, log, sin) in &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#/Creating_a_new_Python_script/002100000020000000/"&gt;Python Scripts&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I generated a model in &lt;A href="http://resources.arcgis.com/en/help/main/10.1/index.html#//002w00000001000000"&gt;Model Builder&lt;/A&gt; and exported them into Python Script. Then I implemented my script as a new &lt;A href="http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//003q00000017000000.htm"&gt;tool in a toolbox&lt;/A&gt;. However, because in some steps in my model I used Raster calculator the tool does not work. I have an &lt;A href="http://support.esri.com/ja/knowledgebase/techarticles/detail/41859"&gt;ERROR 000539&lt;/A&gt;: Error running expression: rcexec() As I have found in the error link, the problem is that Python Scripts are not using Raster Calculation Expressions.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Does anybody know if there is some way (other than this in the error link) to implement Raster Calculator expressions to Python Scripts?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Below are examples of expressions which I want to use in Python Script:&lt;/P&gt;&lt;P&gt;arcpy.gp.RasterCalculator_sa("(\"%2.tif%\") - (\"%3.tif%\")", v4_tif)&lt;/P&gt;&lt;P&gt;arcpy.gp.RasterCalculator_sa("Cos(\"%5.tif%\")", v6_tif)&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 02 Jul 2015 11:02:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-raster-calculator-in-python-scripts/m-p/730146#M56635</guid>
      <dc:creator>KarolinaKorzeniowska</dc:creator>
      <dc:date>2015-07-02T11:02:36Z</dc:date>
    </item>
    <item>
      <title>Re: Using Raster Calculator in Python Scripts</title>
      <link>https://community.esri.com/t5/python-questions/using-raster-calculator-in-python-scripts/m-p/730147#M56636</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi Karonlina,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Take a look at the following link:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;A href="http://desktop.arcgis.com/en/desktop/latest/guide-books/extensions/spatial-analyst/map-algebra/a-quick-tour-of-using-map-algebra.htm" title="http://desktop.arcgis.com/en/desktop/latest/guide-books/extensions/spatial-analyst/map-algebra/a-quick-tour-of-using-map-algebra.htm" rel="nofollow noopener noreferrer" target="_blank"&gt;A quick tour of using Map Algebra—ArcGIS Help | ArcGIS for Desktop&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;When using Map Algebra with Python, you will need to perform the raster calculations a little different.&amp;nbsp; For example, to run a Cos on a raster you would use something similar as below:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE class="lia-code-sample line-numbers language-none"&gt;&lt;CODE&gt;&lt;SPAN class="kn"&gt;import&lt;/SPAN&gt; &lt;SPAN class="nn"&gt;arcpy&lt;/SPAN&gt;
&lt;SPAN class="kn"&gt;from&lt;/SPAN&gt; &lt;SPAN class="nn"&gt;arcpy&lt;/SPAN&gt; &lt;SPAN class="kn"&gt;import&lt;/SPAN&gt; &lt;SPAN class="n"&gt;env&lt;/SPAN&gt;
&lt;SPAN class="kn"&gt;from&lt;/SPAN&gt; &lt;SPAN class="nn"&gt;arcpy.sa&lt;/SPAN&gt; &lt;SPAN class="kn"&gt;import&lt;/SPAN&gt; &lt;SPAN class="o"&gt;*&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;env&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;workspace&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="s"&gt;"C:/sapyexamples/data"&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;outCos&lt;/SPAN&gt; &lt;SPAN class="o"&gt;=&lt;/SPAN&gt; &lt;SPAN class="n"&gt;Cos&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;"degs"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
&lt;SPAN class="n"&gt;outCos&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;save&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s"&gt;"C:/sapyexamples/output/outcos"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;/CODE&gt;&lt;/PRE&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sun, 12 Dec 2021 07:10:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/using-raster-calculator-in-python-scripts/m-p/730147#M56636</guid>
      <dc:creator>JakeSkinner</dc:creator>
      <dc:date>2021-12-12T07:10:27Z</dc:date>
    </item>
  </channel>
</rss>

