<?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: How do I slice a raster into different value ranges and calculate the area of each, doing this for many rasters? in ArcGIS Spatial Analyst Questions</title>
    <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/how-do-i-slice-a-raster-into-different-value/m-p/1170531#M11675</link>
    <description>&lt;P&gt;Thanks Johaness. I will try to see how to manage the codes. I appreciate.&lt;/P&gt;</description>
    <pubDate>Wed, 04 May 2022 09:48:40 GMT</pubDate>
    <dc:creator>Elijah</dc:creator>
    <dc:date>2022-05-04T09:48:40Z</dc:date>
    <item>
      <title>How do I slice a raster into different value ranges and calculate the area of each, doing this for many rasters?</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/how-do-i-slice-a-raster-into-different-value/m-p/1170521#M11673</link>
      <description>&lt;P&gt;I have many rasters: The task is to slice each of the rasters into different value ranges (e.g, 0 -8, 8.0 -12 &amp;amp; 12.0 -15) and calculate the area of each slice. Somehow, I am not python-wise yet. Being a repetitive process I guess python will come in here. Any help in this regard would be appreciated as I can't imagine doing this manually for all the raster.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thank you.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 08:27:27 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/how-do-i-slice-a-raster-into-different-value/m-p/1170521#M11673</guid>
      <dc:creator>Elijah</dc:creator>
      <dc:date>2022-05-04T08:27:27Z</dc:date>
    </item>
    <item>
      <title>Re: How do I slice a raster into different value ranges and calculate the area of each, doing this for many rasters?</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/how-do-i-slice-a-raster-into-different-value/m-p/1170526#M11674</link>
      <description>&lt;P&gt;You can use the arcpy.sa.Raster class, which has a built-in&amp;nbsp;&lt;A href="https://pro.arcgis.com/en/pro-app/latest/help/analysis/spatial-analyst/raster-cell-iterator/what-is-the-raster-cell-iterator.htm" target="_blank" rel="noopener"&gt;raster cell iterator&lt;/A&gt;:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def get_raster_areas(raster_path, upper_bounds):
    """Returns the areas of a raster that are below the given values.

    raster_path: str, path to the raster
    upper_bounds: [float], the upper bounds of your desired value bins

    """
    # get raster object
    raster = arcpy.sa.Raster(raster_path)
    # get cell area
    dimensions = raster.getRasterInfo().getCellSize()
    cell_area = dimensions[0] * dimensions[1]
    # initialize the area list
    upper_bounds.sort()  # it's important that upper_bounds is sorted
    areas = [0 for x in upper_bounds]

    # loop over the raster cells
    for row, col in raster:
        # loop over the upper_bounds
        for i, ub in enumerate(upper_bounds):
            # if raster cell value is below upper bound, 
            # add cell_area to the corresponding element in the areas list
            # and break, so this cell doesn't also get added to the other (higher) bins
            # (that's why we needed to make sure upper_bounds is sorted)
            if raster[row, col] &amp;lt; ub:
                areas[i] += cell_area
                break
    # return the area list
    return areas


rp = r"G:\...\DGM1_2017_HB1.TIF"  # 100x100m raster of elevations in a coastal town
bins = [0, 8, 12, 15]
areas = get_raster_areas(rp, bins)

for b in range(len(bins)):
    print(f"elevation &amp;lt; {bins[b]}m: {areas[b]}m²")
#elevation &amp;lt; 0m: 33.0m²      # below 0m
#elevation &amp;lt; 8m: 997968.0m²  # between 0m and 8m
#elevation &amp;lt; 12m: 0m²        # between 8m and 12m
#elevation &amp;lt; 15m: 0m²        # between 12m and 15m
&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 04 May 2022 09:21:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/how-do-i-slice-a-raster-into-different-value/m-p/1170526#M11674</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-05-04T09:21:49Z</dc:date>
    </item>
    <item>
      <title>Re: How do I slice a raster into different value ranges and calculate the area of each, doing this for many rasters?</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/how-do-i-slice-a-raster-into-different-value/m-p/1170531#M11675</link>
      <description>&lt;P&gt;Thanks Johaness. I will try to see how to manage the codes. I appreciate.&lt;/P&gt;</description>
      <pubDate>Wed, 04 May 2022 09:48:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/how-do-i-slice-a-raster-into-different-value/m-p/1170531#M11675</guid>
      <dc:creator>Elijah</dc:creator>
      <dc:date>2022-05-04T09:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: How do I slice a raster into different value ranges and calculate the area of each, doing this for many rasters?</title>
      <link>https://community.esri.com/t5/arcgis-spatial-analyst-questions/how-do-i-slice-a-raster-into-different-value/m-p/1176446#M11688</link>
      <description>&lt;P&gt;You could also look into the SA &lt;A href="https://pro.arcgis.com/en/pro-app/2.8/tool-reference/spatial-analyst/an-overview-of-the-reclass-tools.htm" target="_self"&gt;Reclassify/Slice&lt;/A&gt; and&amp;nbsp; &lt;A href="https://pro.arcgis.com/en/pro-app/2.8/tool-reference/spatial-analyst/h-how-zonal-geometry-works.htm" target="_self"&gt;Zonal Geometry&lt;/A&gt; tools&lt;/P&gt;&lt;P&gt;You could do this in a model builder environement or if wanting to script, Python samples are available on the respective tool help documents.&lt;/P&gt;&lt;P&gt;Good luck.&lt;/P&gt;</description>
      <pubDate>Mon, 23 May 2022 15:40:35 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-spatial-analyst-questions/how-do-i-slice-a-raster-into-different-value/m-p/1176446#M11688</guid>
      <dc:creator>RyanDeBruyn</dc:creator>
      <dc:date>2022-05-23T15:40:35Z</dc:date>
    </item>
  </channel>
</rss>

