Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

arcpy points in polygon check

$
0
0
Hello,
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:

Code:

import arcpy

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)


Viewing all articles
Browse latest Browse all 2485

Trending Articles