Select to view content in your preferred language

Check each row geometry is inside a perimeter with Python - how?

899
1
12-14-2012 12:01 AM
JamesMorrison1
Frequent Contributor
Hello Everyone

Software version: 9.3.1 / python 2.5

Problem: I have a polygon feature class "FC1" with 1000 records and wish to find the ones laying outside of a given perimeter (in the form of 1 record in another feature class "PERI1").

I know about the gp.erase option but I wish to report to the user that OBJECTID x lies outside PERI1 - so I thought I could loop through FC1 and compare each row geometry withe the PERI1 feature class and report back true/false it is contained or not.

Can anyone point me in the right direction? Currently struggling to find an example. Much appreciated.
Tags (2)
0 Kudos
1 Reply
MattSayler
Frequent Contributor
Unless there is some reason to use the geometry directly, I think the simplest way would be to use Select by Location using the "completely within" and "switch selection" options. Something like:
#Make Layers
arcpy.MakeFeatureLayer_management(perimeterFC, "perimeterLayer")
arcpy.MakeFeatureLayer_management(myFC, "myFCLayer")

#Perform Selection
arcpy.SelectLayerByLocation_management("myFCLayer", "COMPLETELY_WITHIN", "perimeterLayer", None, "SWITCH_SELECTION")


You could then loop through that selection (i.e. print the OID's) or export out to a new table/feature class.
0 Kudos