<?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 Adding multiple rasters together from a geodatabase - Getting AttributeError: 'str' object has no attribute 'write' in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/adding-multiple-rasters-together-from-a/m-p/1226901#M61717</link>
    <description>&lt;P&gt;I have written a script for a custom tool that gets all the rasters from a geodatabase and then adds them all together.&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;from arcpy.sa import *&lt;/P&gt;&lt;P&gt;workspace = arcpy.GetParameter(0)&lt;/P&gt;&lt;P&gt;SuitabilityRaster = arcpy.GetParameterAsText(1)&lt;BR /&gt;&lt;BR /&gt;rasters = arcpy.ListRasters()&lt;/P&gt;&lt;P&gt;for inRaster in rasters:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SuitabilityRaster = SuitabilityRaster + inRaster&lt;/P&gt;&lt;P&gt;SuitabilityRaster.write(workspace + "SuitabilityScoringGrid_Raster")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the tool it gives the following error:&amp;nbsp;&amp;nbsp;AttributeError: 'str' object has no attribute 'write'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would be grateful if someone could help explain this and provide a solution? The 'SuitabilityRaster' begins as a constant raster surface with the value of 0 and then 'rasters' is a list of the rasters from the geodatabase that should be sequentially added to the 'SuitabilityRaster' within the for loop.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
    <pubDate>Sun, 30 Oct 2022 16:59:24 GMT</pubDate>
    <dc:creator>GriogairMorrison</dc:creator>
    <dc:date>2022-10-30T16:59:24Z</dc:date>
    <item>
      <title>Adding multiple rasters together from a geodatabase - Getting AttributeError: 'str' object has no attribute 'write'</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/adding-multiple-rasters-together-from-a/m-p/1226901#M61717</link>
      <description>&lt;P&gt;I have written a script for a custom tool that gets all the rasters from a geodatabase and then adds them all together.&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;from arcpy import env&lt;BR /&gt;from arcpy.sa import *&lt;/P&gt;&lt;P&gt;workspace = arcpy.GetParameter(0)&lt;/P&gt;&lt;P&gt;SuitabilityRaster = arcpy.GetParameterAsText(1)&lt;BR /&gt;&lt;BR /&gt;rasters = arcpy.ListRasters()&lt;/P&gt;&lt;P&gt;for inRaster in rasters:&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SuitabilityRaster = SuitabilityRaster + inRaster&lt;/P&gt;&lt;P&gt;SuitabilityRaster.write(workspace + "SuitabilityScoringGrid_Raster")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I run the tool it gives the following error:&amp;nbsp;&amp;nbsp;AttributeError: 'str' object has no attribute 'write'&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Would be grateful if someone could help explain this and provide a solution? The 'SuitabilityRaster' begins as a constant raster surface with the value of 0 and then 'rasters' is a list of the rasters from the geodatabase that should be sequentially added to the 'SuitabilityRaster' within the for loop.&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2022 16:59:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/adding-multiple-rasters-together-from-a/m-p/1226901#M61717</guid>
      <dc:creator>GriogairMorrison</dc:creator>
      <dc:date>2022-10-30T16:59:24Z</dc:date>
    </item>
    <item>
      <title>Re: Adding multiple rasters together from a geodatabase - Getting AttributeError: 'str' object has no attribute 'write'</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/adding-multiple-rasters-together-from-a/m-p/1226907#M61720</link>
      <description>&lt;P&gt;do you want to 'save' the raster? or `print` it?&lt;/P&gt;&lt;P&gt;in either event&amp;nbsp; &amp;nbsp; ...&amp;nbsp;&lt;SPAN&gt;(workspace + r"\SuitabilityScoringGrid_Raster")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;would be needed&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 30 Oct 2022 19:40:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/adding-multiple-rasters-together-from-a/m-p/1226907#M61720</guid>
      <dc:creator>DanPatterson</dc:creator>
      <dc:date>2022-10-30T19:40:41Z</dc:date>
    </item>
    <item>
      <title>Re: Adding multiple rasters together from a geodatabase - Getting AttributeError: 'str' object has no attribute 'write'</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/adding-multiple-rasters-together-from-a/m-p/1226912#M61722</link>
      <description>&lt;P&gt;You're telling &lt;FONT face="courier new,courier"&gt;arcpy&lt;/FONT&gt; to give you the parameter as text i.e. a &lt;FONT face="courier new,courier"&gt;str&lt;/FONT&gt; object when you use&amp;nbsp;&lt;FONT face="courier new,courier"&gt;GetParameter&lt;U&gt;&lt;STRONG&gt;AsText&lt;/STRONG&gt;&lt;/U&gt;&lt;/FONT&gt;.&lt;/P&gt;&lt;P&gt;You need a &lt;FONT face="courier new,courier"&gt;Raster&lt;/FONT&gt; object.&amp;nbsp; Try using either:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;#GetParameter
SuitabilityRaster = arcpy.GetParameter(1)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;or&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;# arcpy.Raster
SuitabilityRaster = arcpy.Raster(arcpy.GetParameterAsText(1))&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You'll also need to set the workspace:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;arcpy.env.workspace = arcpy.GetParameter(0)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And possibly for convert &lt;FONT face="courier new,courier"&gt;inRaster&lt;/FONT&gt; to a Raster object&amp;nbsp;as &lt;FONT face="courier new,courier"&gt;arcpy.ListRasters()&lt;/FONT&gt; returns strings&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;for inRaster in rasters:
    # you may need to convert inRaster to a Raster object
    # as arcpy.ListRasters() returns strings
    SuitabilityRaster = SuitabilityRaster + arcpy.Raster(inRaster)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;So you'll end up with something like:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;workspace = arcpy.GetParameterAsText(0)
SuitabilityRaster = arcpy.Raster(arcpy.GetParameterAsText(1))

rasters = arcpy.ListRasters()

for inRaster in rasters:
    SuitabilityRaster = SuitabilityRaster + arcpy.Raster(inRaster)

SuitabilityRaster.write(workspace + "SuitabilityScoringGrid_Raster")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 31 Oct 2022 07:25:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/adding-multiple-rasters-together-from-a/m-p/1226912#M61722</guid>
      <dc:creator>Luke_Pinner</dc:creator>
      <dc:date>2022-10-31T07:25:42Z</dc:date>
    </item>
  </channel>
</rss>

