Find Overlapping Features

6818
15
Jump to solution
03-28-2017 02:06 AM
Highlighted
Occasional Contributor
Hi,
Help!
I tried to find an answer to this question but I didn't seem to find what I was looking for. I have a layer with more than 5000 polygons . I would like to know which polygons overlap each other for all 5000 and get the output table like this,
Polygon  Overlap
    1                      2, 3,
    ...
    5000                1, 6, 8

Is this possible? How can I do this?

Thanks.
Reply
0 Kudos
1 Solution

Accepted Solutions
Highlighted
MVP Honored Contributor
15 Replies
Highlighted
MVP Frequent Contributor

Well the start would be a Union in the Analysis / Overlay tool box.

That gives you multiple polygon pieces overlying each other where there was once an overlap.

After that, to get the output you want, I think you would have to do some arcpy / python scripting.

Not too difficult.

Reply
0 Kudos
Highlighted
MVP Frequent Contributor

But, then again....

Would you want each overlap poly referring back to others.

ie in your example...

Poly #1 overlaps with Polys 2 & 3. Therefore Poly # 2 also overlaps 1....

Might be trickier than I think to get what you want.

I have used in the past a fairly simple script just to output the polygon, with a count of the overlaps for that piece.

Reply
0 Kudos
Highlighted
Occasional Contributor

I think the output will be Poly #1 overlaps with Polys 2 & 3. also Poly # 2 also overlaps 1....

Because they are all in the same layer, but if there is a solution for Poly #1 overlaps with Polys 2 & 3. only it will be much better.

Thanks for your response.

Reply
0 Kudos
Highlighted
MVP Frequent Contributor

Well this doesn't quite do what you want, but makes a condensed version of the union output with each poly now recording the count of overlaps and a list of the original polygons that went into them.

import sys, os, arcpy
from arcpy import env

HomeDir = r"path to directory"
scratchFgdb = os.path.join(HomeDir, "scratch.gdb") # input fgdb
fc = "Input_Union" # input polygons (result of a union)

env.workspace = scratchFgdb
env.overwriteOutput = True

# check the sr of the input
desc = arcpy.Describe(fc)
sr = desc.spatialReference

poly_dict = {}
# union has "ORIG_FID" as part of its output
with arcpy.da.SearchCursor(fc, ["ORIG_FID", "SHAPE@", "SHAPE@XY"]) as Cur:
    for row in Cur:
        # read in the data
        origFid = row[0]
        geom = row[01]
        cent = row[2]
        # making a Key variable, just round off the centroid
        x = round(cent[0], 1)
        y = round(cent[1], 1)
        Key = "{:.1f}/{:.1f}".format(x, y)
        if Key in poly_dict:
            poly_dict[Key][1] += 1
            poly_dict[Key][2].append(origFid)
        else:
            poly_dict[Key] = [geom, 1, [origFid]]

# output polygon
outFc = "tmpOverlapPoly"
arcpy.CreateFeatureclass_management("in_memory", outFc, "POLYGON", "", "", "", sr)
arcpy.AddField_management(os.path.join("in_memory", outFc), "Key", "TEXT", "", "", 50)
arcpy.AddField_management(os.path.join("in_memory", outFc), "COUNT", "SHORT")
arcpy.AddField_management(os.path.join("in_memory", outFc), "FidList", "TEXT", "", "", 255)
inCur = arcpy.da.InsertCursor(os.path.join("in_memory", outFc), ["Key", "COUNT", "FidList", "SHAPE@"])
for k, v in poly_dict.items():
    Key = k
    geom = v[0]
    cnt = v[1]
    fids = v[2]
    fidStr = ",".join(str(f) for f in fids)
    data = [Key, cnt, fidStr, geom]
    inCur.insertRow(data)

del inCur

arcpy.CopyFeatures_management(os.path.join("in_memory", outFc), outFc)

Looks like this :

Highlighted
Occasional Contributor

I have not been able to run your script, and got this error

Runtime error
Traceback (most recent call last):
File "<string>", line 12, in <module>
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\__init__.py", line 1246, in Describe
return gp.describe(value)
File "c:\program files (x86)\arcgis\desktop10.3\arcpy\arcpy\geoprocessing\_base.py", line 374, in describe
self._gp.Describe(*gp_fixargs(args, True)))
IOError: "Input_Union" does not exist

Reply
0 Kudos
Highlighted
MVP Frequent Contributor

IOError: "Input_Union"

This line you are supposed to edit to reflect the name of your Union feature class.

Ditto the path for your environment.

Highlighted
Occasional Contributor

Thanks GSCUser85

Do i have to change the output? because now the empty output created with below errors,

Reply
0 Kudos
Highlighted
Occasional Contributor

I have tried intersect, but the problem is the output.

Reply
0 Kudos
Highlighted
Regular Contributor II

Intersect is the right way to get overlapping features. but your problem is output. so

After using Intersect tool for polygon feature class only , you can make Spatial Join to get the table the you want.

Join the Original polygon feature class and the output from Intersect. And Make Join Operation (one to many) and

Match Option (Intersect).