<?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: &amp;amp;quot;Select By Location&amp;amp;quot; and &amp;amp;quot;Update Cursor&amp;amp;quot; functionality in ArcGIS API in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/amp-quot-select-by-location-amp-quot-and-amp-quot/m-p/1477168#M10065</link>
    <description>&lt;P&gt;There's a few different ways you can do this. Here's an example that uses buffers on point data and updates an "IntersectIds" field in a line feature layer to note which points are within 10m of a line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
from arcgis import GIS
from arcgis.geometry import Geometry
from arcgis.features import FeatureLayer

gis = GIS("https://www.arcgis.com", "user", "passwd")

point_url = "https://services3.arcgis.com/ON5SbcAnb3R45678/arcgis/rest/services/point/FeatureServer/0"
point_fl = FeatureLayer(point_url, gis)
point_df = pd.DataFrame.spatial.from_layer(point_fl)

line_url = "https://services3.arcgis.com/ON5SbcAnb3Rdfghj/arcgis/rest/services/ln/FeatureServer/0"
line_fl = FeatureLayer(line_url, gis)
line_df = pd.DataFrame.spatial.from_layer(line_fl)

buffer_df = point_df.copy()
buffer_df["SHAPE"] = buffer_df["SHAPE"].apply(lambda x: x.buffer(10))

joined = line_df.spatial.join(
    buffer_df, 
    how="left", 
    op="intersects", 
    left_tag="left", 
    right_tag="right"
)

intersecting_records = joined[~joined["OBJECTID_right"].isnull()].copy()
intersecting_records["IntersectIds"] = intersecting_records["PointId"].astype(str)

intersecting_records = intersecting_records.copy()[["OBJECTID_left", "IntersectIds"]].rename(columns={"OBJECTID_left" : "OBJECTID"})

final = intersecting_records.groupby("OBJECTID")["IntersectIds"].apply(",".join).reset_index()

fs = final.spatial.to_featureset()
line_fl.edit_features(updates=fs)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 22 May 2024 18:27:13 GMT</pubDate>
    <dc:creator>EarlMedina</dc:creator>
    <dc:date>2024-05-22T18:27:13Z</dc:date>
    <item>
      <title>&amp;quot;Select By Location&amp;quot; and &amp;quot;Update Cursor&amp;quot; functionality in ArcGIS API</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/amp-quot-select-by-location-amp-quot-and-amp-quot/m-p/1476983#M10062</link>
      <description>&lt;P&gt;I'm looking for a process in the ArcGIS API that would essentially function the same as "Select By Location" and "Update Cursor" in arpcy.&lt;/P&gt;&lt;P&gt;Basically, I have a point layer and a line layer, and I want to update attribute information of the line layer anytime the point layer intersects (or comes within 10m) of the line layer.&lt;/P&gt;&lt;P&gt;The best sort of quasi-solution I found so far is arcgis.features.find_locations where I can create a new output feature layer from this point-line intersection, though I don't necessarily want to create anything new - I just want to update what's already there.&lt;/P&gt;&lt;P&gt;I also want to build on this so that "Select By Location" changes per various where clauses, so that different line intersection queries are ran subsequently.&lt;/P&gt;&lt;P&gt;This is a pretty simple and straightforward workflow were I to be doing this in arcpy (&lt;EM&gt;Select By Location&lt;/EM&gt; &lt;EM&gt;with&lt;/EM&gt; &lt;EM&gt;where clause&lt;/EM&gt; &amp;gt; &lt;EM&gt;Update Cursor&lt;/EM&gt; &amp;gt; &lt;EM&gt;next item in list&lt;/EM&gt;), though I can't seem to wrap my head around how I might be able to do this in the ArcGIS API. Any ideas?&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 15:02:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/amp-quot-select-by-location-amp-quot-and-amp-quot/m-p/1476983#M10062</guid>
      <dc:creator>AdamGaudet</dc:creator>
      <dc:date>2024-05-22T15:02:05Z</dc:date>
    </item>
    <item>
      <title>Re: &amp;quot;Select By Location&amp;quot; and &amp;quot;Update Cursor&amp;quot; functionality in ArcGIS API</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/amp-quot-select-by-location-amp-quot-and-amp-quot/m-p/1477124#M10063</link>
      <description>&lt;P&gt;To identify the lines within 10m of a point you'll want to use the FeatureLayer.query() function, it includes a geometry_filter parameter where you can pass a filter object (this will include your point), along with the distance parameter where you set your threshold.&lt;/P&gt;&lt;P&gt;You can push updates to the layer using the FeatureLayer.edit_features() function, it's a little bit different approach than using a cursor however.&amp;nbsp; Iterating through features is something you want to avoid using services, you want to group your edits together into a list and push them through as a bulk edit to optimize performance.&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 17:24:33 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/amp-quot-select-by-location-amp-quot-and-amp-quot/m-p/1477124#M10063</guid>
      <dc:creator>MobiusSnake</dc:creator>
      <dc:date>2024-05-22T17:24:33Z</dc:date>
    </item>
    <item>
      <title>Re: &amp;quot;Select By Location&amp;quot; and &amp;quot;Update Cursor&amp;quot; functionality in ArcGIS API</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/amp-quot-select-by-location-amp-quot-and-amp-quot/m-p/1477168#M10065</link>
      <description>&lt;P&gt;There's a few different ways you can do this. Here's an example that uses buffers on point data and updates an "IntersectIds" field in a line feature layer to note which points are within 10m of a line:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import pandas as pd
from arcgis import GIS
from arcgis.geometry import Geometry
from arcgis.features import FeatureLayer

gis = GIS("https://www.arcgis.com", "user", "passwd")

point_url = "https://services3.arcgis.com/ON5SbcAnb3R45678/arcgis/rest/services/point/FeatureServer/0"
point_fl = FeatureLayer(point_url, gis)
point_df = pd.DataFrame.spatial.from_layer(point_fl)

line_url = "https://services3.arcgis.com/ON5SbcAnb3Rdfghj/arcgis/rest/services/ln/FeatureServer/0"
line_fl = FeatureLayer(line_url, gis)
line_df = pd.DataFrame.spatial.from_layer(line_fl)

buffer_df = point_df.copy()
buffer_df["SHAPE"] = buffer_df["SHAPE"].apply(lambda x: x.buffer(10))

joined = line_df.spatial.join(
    buffer_df, 
    how="left", 
    op="intersects", 
    left_tag="left", 
    right_tag="right"
)

intersecting_records = joined[~joined["OBJECTID_right"].isnull()].copy()
intersecting_records["IntersectIds"] = intersecting_records["PointId"].astype(str)

intersecting_records = intersecting_records.copy()[["OBJECTID_left", "IntersectIds"]].rename(columns={"OBJECTID_left" : "OBJECTID"})

final = intersecting_records.groupby("OBJECTID")["IntersectIds"].apply(",".join).reset_index()

fs = final.spatial.to_featureset()
line_fl.edit_features(updates=fs)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2024 18:27:13 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/amp-quot-select-by-location-amp-quot-and-amp-quot/m-p/1477168#M10065</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2024-05-22T18:27:13Z</dc:date>
    </item>
  </channel>
</rss>

