<?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 Search by location analog with ArcGIS Python API in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/search-by-location-analog-with-arcgis-python-api/m-p/1372416#M9549</link>
    <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following script uses Search by Location on a polygon feature class to select points within a given threshold. The selected points then record the name of the polygon feature in a field called "Assoc_Polygon".&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def update_points_association(point_fc, polygon_fc, distance_threshold, field_name):
    # Iterate through each polygon feature
    with arcpy.da.SearchCursor(polygon_fc, ["Name", "SHAPE@"]) as polygon_cursor:
        for polygon_row in polygon_cursor:
            polygon_name = polygon_row[0]
            polygon_geometry = polygon_row[1]

            # Use SelectLayerByLocation to select points within the specified distance of the current polygon feature
            arcpy.SelectLayerByLocation_management(point_fc, "WITHIN_A_DISTANCE", polygon_geometry, distance_threshold)

            # Update the specified field in the selected points with the current polygon name
            with arcpy.da.UpdateCursor(point_fc, ["SHAPE@", field_name]) as point_cursor:
                for point_row in point_cursor:
                    point_row[1] = polygon_name
                    point_cursor.updateRow(point_row)

            # Remove the selection
            arcpy.SelectLayerByAttribute_management(point_fc, "CLEAR_SELECTION")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I can buffer polygons and then spatial join, but that seems cumbersome and uses credits. Is there any other way? Thanks!&lt;/P&gt;</description>
    <pubDate>Fri, 19 Jan 2024 18:44:51 GMT</pubDate>
    <dc:creator>Have_You_Seen_My_Rabbit</dc:creator>
    <dc:date>2024-01-19T18:44:51Z</dc:date>
    <item>
      <title>Search by location analog with ArcGIS Python API</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/search-by-location-analog-with-arcgis-python-api/m-p/1372416#M9549</link>
      <description>&lt;P&gt;Hello everyone,&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following script uses Search by Location on a polygon feature class to select points within a given threshold. The selected points then record the name of the polygon feature in a field called "Assoc_Polygon".&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def update_points_association(point_fc, polygon_fc, distance_threshold, field_name):
    # Iterate through each polygon feature
    with arcpy.da.SearchCursor(polygon_fc, ["Name", "SHAPE@"]) as polygon_cursor:
        for polygon_row in polygon_cursor:
            polygon_name = polygon_row[0]
            polygon_geometry = polygon_row[1]

            # Use SelectLayerByLocation to select points within the specified distance of the current polygon feature
            arcpy.SelectLayerByLocation_management(point_fc, "WITHIN_A_DISTANCE", polygon_geometry, distance_threshold)

            # Update the specified field in the selected points with the current polygon name
            with arcpy.da.UpdateCursor(point_fc, ["SHAPE@", field_name]) as point_cursor:
                for point_row in point_cursor:
                    point_row[1] = polygon_name
                    point_cursor.updateRow(point_row)

            # Remove the selection
            arcpy.SelectLayerByAttribute_management(point_fc, "CLEAR_SELECTION")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I know I can buffer polygons and then spatial join, but that seems cumbersome and uses credits. Is there any other way? Thanks!&lt;/P&gt;</description>
      <pubDate>Fri, 19 Jan 2024 18:44:51 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/search-by-location-analog-with-arcgis-python-api/m-p/1372416#M9549</guid>
      <dc:creator>Have_You_Seen_My_Rabbit</dc:creator>
      <dc:date>2024-01-19T18:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: Search by location analog with ArcGIS Python API</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/search-by-location-analog-with-arcgis-python-api/m-p/1372718#M9560</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/745094"&gt;@Have_You_Seen_My_Rabbit&lt;/a&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;You are using ArcPy in this example and not the ArcGIS API for Python, as such there is no credit consumption as ArcGIS Pro (or ArcMap) is performing the geoprocessing and not ArcGIS Online.&lt;/P&gt;</description>
      <pubDate>Sun, 21 Jan 2024 08:29:56 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/search-by-location-analog-with-arcgis-python-api/m-p/1372718#M9560</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2024-01-21T08:29:56Z</dc:date>
    </item>
  </channel>
</rss>

