<?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: Intersections - Biggest Overlap Methods - Query in ArcGIS API for Python Questions</title>
    <link>https://community.esri.com/t5/arcgis-api-for-python-questions/intersections-biggest-overlap-methods-query/m-p/1648404#M11619</link>
    <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/772915"&gt;@benedictmueller&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;This should get you on your way. The result is a dictionary with the key as the target oid and the value as the source oid. Code is comment, hopefully easy to follow.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.geometry import Geometry

################################################################################
## USER INPUTS #################################################################

## the target polygon feature layer url
ply_fl_1_url = "FEATURE_LAYER_URL"

## the source polygon feature layer
## this is the one that has multiple overlaps with the one above
ply_fl_2_url = "FEATURE_LAYER_URL"

################################################################################
## REQUIRED OBJECTS ############################################################

## we will store the target and source object ids in here
results_dict = {}

################################################################################
## ACCESS ARCGIS ONLINE ########################################################

agol = GIS("home")

################################################################################
## CREATE FEATURE LAYER OBJECTS ################################################

## get the target polygon feature layer as a FeatureLayer object
ply_fl_1 = FeatureLayer(
    url = ply_fl_1_url,
    gis = agol
)

## get the source polygon feature layer as a FeatureLayer object
ply_fl_2 = FeatureLayer(
    url = ply_fl_2_url,
    gis = agol
)

################################################################################
## GET OID FIELDS ##############################################################

## get the target polygon feature layer oid field
ply_1_oid = ply_fl_1.properties.objectIdField

## get the source polygon feature layer oid field
ply_2_oid = ply_fl_2.properties.objectIdField

################################################################################
## CREATE FEATURE SET OBJECT ###################################################

## get the target polygon feature layer as a feature set
ply_1_fset = ply_fl_1.query(out_fields=[ply_1_oid]).features

## get the source polygon feature layer oid field
ply_2_fset = ply_fl_2.query(out_fields=[ply_2_oid]).features

################################################################################
## GET THE ID WITH BIGGEST OVERLAPS ############################################

## for each polygon in the target feature layer
for ply_1_f in ply_1_fset:
    ## create a Geometry object
    ply_1_geom = Geometry(ply_1_f.geometry)
    ## set overlap area to zero and id to None
    max_overlap_area = 0
    max_overlap_id = None

    ## for each polygon in the source feature layer
    for ply_2_f in ply_2_fset:
        ## create a Geometry object
        ply_2_geom = Geometry(ply_2_f.geometry)
        ## if the target geometry overlaps
        if ply_1_geom.overlaps(ply_2_geom):
            ## then get the area of intersection
            overlap_area = ply_1_geom.intersect(second_geometry = ply_2_geom, dimension = 4).area
            ## if the overlap area is greater than previous
            if overlap_area &amp;gt; max_overlap_area:
                ## set the overlap area as the max
                max_overlap_area = overlap_area
                ## set the source id as the id with biggest overlap
                max_overlap_id = ply_2_f.attributes[ply_2_oid]

    ## if a max_overlap_id was found
    if max_overlap_id:
        ## add to the results dictionary {target_id : source_id}
        results_dict[ply_1_f.attributes[ply_1_oid]] = max_overlap_id

################################################################################
## PRINT RESULTS ###############################################################

for key,value in results_dict.items():
    print(f"Target ID: {key}", f"Source ID: {value}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Clubdebambos_0-1757159613369.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/139972i97D2FC954FB608DB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Clubdebambos_0-1757159613369.png" alt="Clubdebambos_0-1757159613369.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Clubdebambos_1-1757159659466.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/139973i8A1063B73F185BAD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Clubdebambos_1-1757159659466.png" alt="Clubdebambos_1-1757159659466.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Glen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 06 Sep 2025 11:55:45 GMT</pubDate>
    <dc:creator>Clubdebambos</dc:creator>
    <dc:date>2025-09-06T11:55:45Z</dc:date>
    <item>
      <title>Intersections - Biggest Overlap Methods - Query</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/intersections-biggest-overlap-methods-query/m-p/1646397#M11601</link>
      <description>&lt;P&gt;Hey there!&lt;/P&gt;&lt;P&gt;In ArcPy you have the option to choose 'biggest overlap' when performing a spatial join.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was wondering if there is any possible way to perform the same operation with the arcgis api. You have different options to perform eg a query on a feature layer with geometry filters, same for sdf.spatial.join() method. But I can only find interesect, touches, within, etc. Is there a possible workaround to maybe interesect first and then compare the geometry to calculate the bigger overlap and then only join the features of the biggest overlap?&lt;/P&gt;&lt;P&gt;I havent figured it out yet and would appreciate any kind of help!&lt;/P&gt;&lt;P&gt;Thank you in advance.&lt;/P&gt;&lt;P&gt;Benni xo&lt;/P&gt;</description>
      <pubDate>Thu, 28 Aug 2025 10:40:12 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/intersections-biggest-overlap-methods-query/m-p/1646397#M11601</guid>
      <dc:creator>benedictmueller</dc:creator>
      <dc:date>2025-08-28T10:40:12Z</dc:date>
    </item>
    <item>
      <title>Re: Intersections - Biggest Overlap Methods - Query</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/intersections-biggest-overlap-methods-query/m-p/1648404#M11619</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/772915"&gt;@benedictmueller&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;This should get you on your way. The result is a dictionary with the key as the target oid and the value as the source oid. Code is comment, hopefully easy to follow.&lt;/P&gt;&lt;LI-CODE lang="python"&gt;from arcgis.gis import GIS
from arcgis.features import FeatureLayer
from arcgis.geometry import Geometry

################################################################################
## USER INPUTS #################################################################

## the target polygon feature layer url
ply_fl_1_url = "FEATURE_LAYER_URL"

## the source polygon feature layer
## this is the one that has multiple overlaps with the one above
ply_fl_2_url = "FEATURE_LAYER_URL"

################################################################################
## REQUIRED OBJECTS ############################################################

## we will store the target and source object ids in here
results_dict = {}

################################################################################
## ACCESS ARCGIS ONLINE ########################################################

agol = GIS("home")

################################################################################
## CREATE FEATURE LAYER OBJECTS ################################################

## get the target polygon feature layer as a FeatureLayer object
ply_fl_1 = FeatureLayer(
    url = ply_fl_1_url,
    gis = agol
)

## get the source polygon feature layer as a FeatureLayer object
ply_fl_2 = FeatureLayer(
    url = ply_fl_2_url,
    gis = agol
)

################################################################################
## GET OID FIELDS ##############################################################

## get the target polygon feature layer oid field
ply_1_oid = ply_fl_1.properties.objectIdField

## get the source polygon feature layer oid field
ply_2_oid = ply_fl_2.properties.objectIdField

################################################################################
## CREATE FEATURE SET OBJECT ###################################################

## get the target polygon feature layer as a feature set
ply_1_fset = ply_fl_1.query(out_fields=[ply_1_oid]).features

## get the source polygon feature layer oid field
ply_2_fset = ply_fl_2.query(out_fields=[ply_2_oid]).features

################################################################################
## GET THE ID WITH BIGGEST OVERLAPS ############################################

## for each polygon in the target feature layer
for ply_1_f in ply_1_fset:
    ## create a Geometry object
    ply_1_geom = Geometry(ply_1_f.geometry)
    ## set overlap area to zero and id to None
    max_overlap_area = 0
    max_overlap_id = None

    ## for each polygon in the source feature layer
    for ply_2_f in ply_2_fset:
        ## create a Geometry object
        ply_2_geom = Geometry(ply_2_f.geometry)
        ## if the target geometry overlaps
        if ply_1_geom.overlaps(ply_2_geom):
            ## then get the area of intersection
            overlap_area = ply_1_geom.intersect(second_geometry = ply_2_geom, dimension = 4).area
            ## if the overlap area is greater than previous
            if overlap_area &amp;gt; max_overlap_area:
                ## set the overlap area as the max
                max_overlap_area = overlap_area
                ## set the source id as the id with biggest overlap
                max_overlap_id = ply_2_f.attributes[ply_2_oid]

    ## if a max_overlap_id was found
    if max_overlap_id:
        ## add to the results dictionary {target_id : source_id}
        results_dict[ply_1_f.attributes[ply_1_oid]] = max_overlap_id

################################################################################
## PRINT RESULTS ###############################################################

for key,value in results_dict.items():
    print(f"Target ID: {key}", f"Source ID: {value}")&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Clubdebambos_0-1757159613369.png" style="width: 999px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/139972i97D2FC954FB608DB/image-size/large?v=v2&amp;amp;px=999" role="button" title="Clubdebambos_0-1757159613369.png" alt="Clubdebambos_0-1757159613369.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Clubdebambos_1-1757159659466.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/139973i8A1063B73F185BAD/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Clubdebambos_1-1757159659466.png" alt="Clubdebambos_1-1757159659466.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;All the best,&lt;/P&gt;&lt;P&gt;Glen&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 06 Sep 2025 11:55:45 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/intersections-biggest-overlap-methods-query/m-p/1648404#M11619</guid>
      <dc:creator>Clubdebambos</dc:creator>
      <dc:date>2025-09-06T11:55:45Z</dc:date>
    </item>
    <item>
      <title>Re: Intersections - Biggest Overlap Methods - Query</title>
      <link>https://community.esri.com/t5/arcgis-api-for-python-questions/intersections-biggest-overlap-methods-query/m-p/1648476#M11621</link>
      <description>&lt;P&gt;Puhhh&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":cowboy_hat_face:"&gt;🤠&lt;/span&gt; Amazing!&lt;/P&gt;&lt;P&gt;Thank you so much. I'll try it out! I love that this community is thriving enough to get answers on those specific questions.&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":blue_heart:"&gt;💙&lt;/span&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 08 Sep 2025 07:27:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-api-for-python-questions/intersections-biggest-overlap-methods-query/m-p/1648476#M11621</guid>
      <dc:creator>benedictmueller</dc:creator>
      <dc:date>2025-09-08T07:27:10Z</dc:date>
    </item>
  </channel>
</rss>

