# Find Overlapping Features

17856
15
03-28-2017 02:06 AM
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.
Tags (3)
1 Solution

Accepted Solutions
by
MVP Esteemed Contributor

Take a look at the Find Overlapping Features tool

15 Replies
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.

MVP Frequent Contributor

But, then again....

Would you want each overlap poly referring back to others.

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.

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.

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:
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), "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 :

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

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.

Occasional Contributor

Thanks GSCUser85

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

Occasional Contributor

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

Occasional Contributor III

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).