<?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: Pull values from raster within buffer around point in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/pull-values-from-raster-within-buffer-around-point/m-p/1506735#M71088</link>
    <description>&lt;P&gt;Here is a superior method that can be done in three tools that will process hundreds of points in a few seconds. I present it as a model so its easier to understand, and you can convert this to python if you so wish.&lt;/P&gt;&lt;P&gt;As a side note reviewing your code&lt;EM&gt;&amp;nbsp;thisbuffdist&lt;/EM&gt; never changes within the loop so your buffer distance is constant for the points, my logic follows this logic.&lt;/P&gt;&lt;P&gt;So here is some sample data, a green sample point and the background raster labelled with its cell values. The circle is showing a radius, in this case 100m to depict the neighbourhood.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="DuncanHornby_0-1721320270179.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/110060iDEF55836220C0476/image-size/large?v=v2&amp;amp;px=999" role="button" title="DuncanHornby_0-1721320270179.png" alt="DuncanHornby_0-1721320270179.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The three step model is this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="DuncanHornby_1-1721320487250.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/110061iB58908139173244C/image-size/large?v=v2&amp;amp;px=999" role="button" title="DuncanHornby_1-1721320487250.png" alt="DuncanHornby_1-1721320487250.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The focal statistics tool is set to create a circular neighbourhood and extract the RANGE within that neighbourhood. This range value is passed through to the points and then I simply select all points with a range &amp;gt; 1.&lt;/P&gt;&lt;P&gt;Here is a screenshot showing 3 points selected whilst 1 remains unselected (dark blue) to prove that the logic works.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="DuncanHornby_2-1721320825764.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/110062i1225D3FDFC2AB8AE/image-size/large?v=v2&amp;amp;px=999" role="button" title="DuncanHornby_2-1721320825764.png" alt="DuncanHornby_2-1721320825764.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 18 Jul 2024 16:40:42 GMT</pubDate>
    <dc:creator>DuncanHornby</dc:creator>
    <dc:date>2024-07-18T16:40:42Z</dc:date>
    <item>
      <title>Pull values from raster within buffer around point</title>
      <link>https://community.esri.com/t5/python-questions/pull-values-from-raster-within-buffer-around-point/m-p/1504302#M71058</link>
      <description>&lt;P&gt;I have a set of points.&amp;nbsp; For each point, I want the values from a raster within a buffer radius around the point.&amp;nbsp; The radius of the buffer can vary.&amp;nbsp; Once I have these values, I compare them to a value from the point attributes.&amp;nbsp; I'm checking to see if at least one value from the raster is +/- 1.0 from the point's value.&amp;nbsp; I have figured out how to do this with ArcPy, however I have thousands of points and it takes about 30 seconds to run just 10 points.&amp;nbsp; Is there a faster way to do this?&lt;/P&gt;&lt;P&gt;I'm running Python 3.11:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;with arcpy.da.UpdateCursor(TestPts, fields, wclause) as cursor:
    for row in cursor:
        # Create a buffer polygon geometry around this point
        geom = row[0]
        buff = geom.buffer(thisbuffdist)
        # Set the extent to just the buffer polygon
        arcpy.env.extent = buff.extent
        # Extract raster cells within the buffer
        OutRasEBM = ExtractByMask(Ras, buff, 'INSIDE')
        # Convert extracted Raster to numpy array
        arr = arcpy.RasterToNumPyArray(OutRasEBM)
        # Clear buff and OutRasEBM from memory
        del buff, OutRasEBM
        # Find if a value in the array is within 1 foot of pointvalue
        pointvalue = row[1]
        diffarr = arr - pointvalue
        for rw in diffarr:
            for x in rw:
                if x &amp;gt; -1.0 and x &amp;lt; 1.0:
                    row[2] = 'P'
                    break
        cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 16:40:52 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pull-values-from-raster-within-buffer-around-point/m-p/1504302#M71058</guid>
      <dc:creator>ZoeZaloudek</dc:creator>
      <dc:date>2024-07-11T16:40:52Z</dc:date>
    </item>
    <item>
      <title>Re: Pull values from raster within buffer around point</title>
      <link>https://community.esri.com/t5/python-questions/pull-values-from-raster-within-buffer-around-point/m-p/1504431#M71059</link>
      <description>&lt;P&gt;Try&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;with arcpy.da.UpdateCursor(TestPts, fields, wclause) as cursor:
    for row in cursor:
        geom = row[0]
        buff = geom.buffer(thisbuffdist)
        arcpy.env.extent = buff.extent

        # Extract raster cells within the buffer based on attribute condition
        expression = f"VALUE &amp;gt;= {row[1] - 1.0} AND VALUE &amp;lt;= {row[1] + 1.0}"
        OutRasEBM = ExtractByAttributes(Ras, expression)

        # Convert extracted Raster to numpy array
        arr = arcpy.RasterToNumPyArray(OutRasEBM)

        # Check if any value in the array meets the condition
        if (arr &amp;gt; row[1] - 1.0).any() and (arr &amp;lt; row[1] + 1.0).any():
            row[2] = 'P'

        cursor.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 11 Jul 2024 19:42:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pull-values-from-raster-within-buffer-around-point/m-p/1504431#M71059</guid>
      <dc:creator>TonyAlmeida</dc:creator>
      <dc:date>2024-07-11T19:42:46Z</dc:date>
    </item>
    <item>
      <title>Re: Pull values from raster within buffer around point</title>
      <link>https://community.esri.com/t5/python-questions/pull-values-from-raster-within-buffer-around-point/m-p/1506735#M71088</link>
      <description>&lt;P&gt;Here is a superior method that can be done in three tools that will process hundreds of points in a few seconds. I present it as a model so its easier to understand, and you can convert this to python if you so wish.&lt;/P&gt;&lt;P&gt;As a side note reviewing your code&lt;EM&gt;&amp;nbsp;thisbuffdist&lt;/EM&gt; never changes within the loop so your buffer distance is constant for the points, my logic follows this logic.&lt;/P&gt;&lt;P&gt;So here is some sample data, a green sample point and the background raster labelled with its cell values. The circle is showing a radius, in this case 100m to depict the neighbourhood.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="DuncanHornby_0-1721320270179.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/110060iDEF55836220C0476/image-size/large?v=v2&amp;amp;px=999" role="button" title="DuncanHornby_0-1721320270179.png" alt="DuncanHornby_0-1721320270179.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;The three step model is this:&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="DuncanHornby_1-1721320487250.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/110061iB58908139173244C/image-size/large?v=v2&amp;amp;px=999" role="button" title="DuncanHornby_1-1721320487250.png" alt="DuncanHornby_1-1721320487250.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;The focal statistics tool is set to create a circular neighbourhood and extract the RANGE within that neighbourhood. This range value is passed through to the points and then I simply select all points with a range &amp;gt; 1.&lt;/P&gt;&lt;P&gt;Here is a screenshot showing 3 points selected whilst 1 remains unselected (dark blue) to prove that the logic works.&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="DuncanHornby_2-1721320825764.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/110062i1225D3FDFC2AB8AE/image-size/large?v=v2&amp;amp;px=999" role="button" title="DuncanHornby_2-1721320825764.png" alt="DuncanHornby_2-1721320825764.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 18 Jul 2024 16:40:42 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/pull-values-from-raster-within-buffer-around-point/m-p/1506735#M71088</guid>
      <dc:creator>DuncanHornby</dc:creator>
      <dc:date>2024-07-18T16:40:42Z</dc:date>
    </item>
  </channel>
</rss>

