Hi, I'm hopping for some help as I work through the process of writing a piece of code to produce an output of polygon intersects. My shape file contains many polygons which I would like to determine if any of them intersect and if they do add that intersect results to a new shape file. The code I used is below. I'm getting and error which is shown in a pic below.
Ultimately I'd like to have a single output shape file containing all intersect results. If you know a more efficient way or know how to make what I have work I am all ears!
I have attached a sample of the polygons. Many thanks for your attention!
I'm limited to using ArcMap 10.7 and python 2.7
```
import arcpy
from arcpy import env
import os
##Set working directory and workspace
wk_dir = os.getcwd()
env.workspace = wk_dir
##Assign feature class and working fields
fc = wk_dir + '\\CBT_Composite.gdb\\example_polys'
fields = ['RecordID', 'SHAPE@']
##Assign output file path and name
out = wk_dir + '\\output.gdb\\A'
##print fc_path + fc
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
record = '{0}'.format(row[0]).split('.')[0]
polygon = row[1]
for row2 in cursor:
if row2 != row:
arcpy.Intersect_arc(row2[1], polygon, out +record)
```
Solved! Go to Solution.
Hi Kathy Gillis,
If you change the variables and run the following code you should get the intersected shapes, all in one feature class:
arcpy.env.workspace = r"workspace path"
arcpy.analysis.Intersect("example_polys #", "example_polys_Intersect", "ALL", None, "INPUT")
Hi Kathy Gillis,
If you change the variables and run the following code you should get the intersected shapes, all in one feature class:
arcpy.env.workspace = r"workspace path"
arcpy.analysis.Intersect("example_polys #", "example_polys_Intersect", "ALL", None, "INPUT")
Thank you for your response Mehdi Pira!
Can you clarify what ' #' stands for in the Intersect statement?
Thank you Again - Kathy
Not a problem, Kathy Gillis
This sign # is for Priority Ranks. Refer to the link below for more info:
Thank you! @mehdi Pira It worked perfectly. Smiling really big!