<?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 Return all Geometries that Intersect with other Geometries in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/return-all-geometries-that-intersect-with-other/m-p/1353831#M9331</link>
    <description>&lt;P&gt;Hey all,&lt;/P&gt;&lt;P&gt;I need to drop duplicates on geometries within a spatially enabled dataframe. In order to do this, I first need to convert the SHAPE column to a new column using the WKT value:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sdf['SHAPE_WKT'] = sdf['SHAPE'].apply(lambda geom: geom.WKT if geom else None)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, this takes a long time to run. Is there anyway to limit the size of my sdf but only running this on the geometries that intersect with other geometries? I know you can run intersections between different feature layers, but what about within the SHAPE column of the current working sdf?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For anyone curious, I can't drop duplicates on the SHAPE column directly because of the following error that occurs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sdf.drop_duplicates(subset='SHAPE', keep='first')&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
In  [46]:
Line 1:     sdf.drop_duplicates(subset='SHAPE', keep='first')

File C:\Users\Eric\AppData\Local\ESRI\conda\envs\assemblage_env\Lib\site-packages\pandas\util\_decorators.py, in wrapper:
Line 311:   return func(*args, **kwargs)

File C:\Users\Eric\AppData\Local\ESRI\conda\envs\assemblage_env\Lib\site-packages\pandas\core\frame.py, in drop_duplicates:
Line 6125:  duplicated = self.duplicated(subset, keep=keep)

File C:\Users\Eric\AppData\Local\ESRI\conda\envs\assemblage_env\Lib\site-packages\pandas\core\frame.py, in duplicated:
Line 6262:  labels, shape = map(list, zip(*map(f, vals)))

File C:\Users\Eric\AppData\Local\ESRI\conda\envs\assemblage_env\Lib\site-packages\pandas\core\frame.py, in f:
Line 6235:  labels, shape = algorithms.factorize(vals, size_hint=len(self))

File C:\Users\Eric\AppData\Local\ESRI\conda\envs\assemblage_env\Lib\site-packages\pandas\core\algorithms.py, in factorize:
Line 749:   codes, uniques = values.factorize(na_sentinel=na_sentinel)

File C:\Users\Eric\AppData\Local\ESRI\conda\envs\assemblage_env\Lib\site-packages\pandas\core\arrays\base.py, in factorize:
Line 1028:  uniques_ea = self._from_factorized(uniques, self)

TypeError: _from_factorized() takes 2 positional arguments but 3 were given
---------------------------------------------------------------------------&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 27 Nov 2023 21:42:32 GMT</pubDate>
    <dc:creator>ericsamson_tract</dc:creator>
    <dc:date>2023-11-27T21:42:32Z</dc:date>
    <item>
      <title>Return all Geometries that Intersect with other Geometries</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/return-all-geometries-that-intersect-with-other/m-p/1353831#M9331</link>
      <description>&lt;P&gt;Hey all,&lt;/P&gt;&lt;P&gt;I need to drop duplicates on geometries within a spatially enabled dataframe. In order to do this, I first need to convert the SHAPE column to a new column using the WKT value:&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sdf['SHAPE_WKT'] = sdf['SHAPE'].apply(lambda geom: geom.WKT if geom else None)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;However, this takes a long time to run. Is there anyway to limit the size of my sdf but only running this on the geometries that intersect with other geometries? I know you can run intersections between different feature layers, but what about within the SHAPE column of the current working sdf?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;For anyone curious, I can't drop duplicates on the SHAPE column directly because of the following error that occurs:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;sdf.drop_duplicates(subset='SHAPE', keep='first')&lt;/LI-CODE&gt;&lt;LI-CODE lang="python"&gt;---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
In  [46]:
Line 1:     sdf.drop_duplicates(subset='SHAPE', keep='first')

File C:\Users\Eric\AppData\Local\ESRI\conda\envs\assemblage_env\Lib\site-packages\pandas\util\_decorators.py, in wrapper:
Line 311:   return func(*args, **kwargs)

File C:\Users\Eric\AppData\Local\ESRI\conda\envs\assemblage_env\Lib\site-packages\pandas\core\frame.py, in drop_duplicates:
Line 6125:  duplicated = self.duplicated(subset, keep=keep)

File C:\Users\Eric\AppData\Local\ESRI\conda\envs\assemblage_env\Lib\site-packages\pandas\core\frame.py, in duplicated:
Line 6262:  labels, shape = map(list, zip(*map(f, vals)))

File C:\Users\Eric\AppData\Local\ESRI\conda\envs\assemblage_env\Lib\site-packages\pandas\core\frame.py, in f:
Line 6235:  labels, shape = algorithms.factorize(vals, size_hint=len(self))

File C:\Users\Eric\AppData\Local\ESRI\conda\envs\assemblage_env\Lib\site-packages\pandas\core\algorithms.py, in factorize:
Line 749:   codes, uniques = values.factorize(na_sentinel=na_sentinel)

File C:\Users\Eric\AppData\Local\ESRI\conda\envs\assemblage_env\Lib\site-packages\pandas\core\arrays\base.py, in factorize:
Line 1028:  uniques_ea = self._from_factorized(uniques, self)

TypeError: _from_factorized() takes 2 positional arguments but 3 were given
---------------------------------------------------------------------------&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 27 Nov 2023 21:42:32 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/return-all-geometries-that-intersect-with-other/m-p/1353831#M9331</guid>
      <dc:creator>ericsamson_tract</dc:creator>
      <dc:date>2023-11-27T21:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Return all Geometries that Intersect with other Geometries</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/return-all-geometries-that-intersect-with-other/m-p/1355941#M9355</link>
      <description>&lt;P&gt;I believe you can identify which records intersect one another with a spatial join. In my small test case, this works and returns the expected records:&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;from arcgis import GIS
from arcgis.features import FeatureLayer

gis = GIS("https://machine.domain.com/portal", "user", "pass")
fl_url = "https://src.domain.com/server/rest/services/test/FeatureServer/0"
fl = FeatureLayer(fl_url, gis)
df = fl.query(as_df=True)

joined = df.spatial.join(
    df.copy(), 
    how="left", 
    op="intersects", 
    left_tag="left", 
    right_tag="right"
)

intersecting_records = joined.loc[joined.OBJECTID_left != joined.OBJECTID_right]&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope this helps! This was a really good question that I'm sure many will get value from.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 05 Dec 2023 22:46:40 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/return-all-geometries-that-intersect-with-other/m-p/1355941#M9355</guid>
      <dc:creator>EarlMedina</dc:creator>
      <dc:date>2023-12-05T22:46:40Z</dc:date>
    </item>
  </channel>
</rss>

