I have a list of points and a list of polygons both in a separate shape files. I am trying to write a ArcPy script to loop through the points, and then the polygons respectively and tell me when a point is within a polygon. I have tried both the contains and touches methods on polygons but haven't had any luck. Any help would be appreciated. So far I have the following:
pointFeatureClass = "C:\\Data\\POINTS2.dbf"
pointFieldList = arcpy.ListFields(pointFeatureClass)
for field in pointFieldList:
curField = field.name
arcpy.AddMessage(curField)
ptRows = arcpy.SearchCursor("C:\\Data\\POINTS2.dbf", "", "", "CID;Shape","CID;Shape")
for ptRow in ptRows:
#Now loop through poly's testing for intersect
shpRows = arcpy.SearchCursor("C:\\Data\\counties.shp", "", "", "NAME;Shape","NAME;Shape")
for shpRow in shpRows:
#arcpy.AddMessage("Checking for point "+ str(ptRow.CID) +" in: " + shpRow.NAME)
if shpRow.Shape.touches(ptRow.Shape):
arcpy.AddMessage("Got it: " + shpRow.NAME)
pointFeatureClass
refers to a .dbf file, not a shapefile, so Arcpy will not read theShape
field as geometry.contains
method, and it worked fine.