Am trying to check if the points in a point shapefile are contained within a polygon shapefile and if so, to populate a field in the point shapefile with the name of the polygon and to populate the field with 'no' if otherwise. Am guessing I have to use the contains method and I have searched but can't find examples of it used with the new data access module. I have put random values in the file paths for confidentiality. This is the code that I have but it returns an error of return convertArcObjectToPythonObject(self._arc_object.Contains(*gp_fixargs([second_geometry])))

here's the code:

import arcpy
for row in cursor:
    for rowb in cursor1:
        if rowb[0].contains(row[0]):
del row
del row1
del cursor
del cursor1

Please help me figure out what's going on.

  • 4
    It would be way more efficient to do a spatial search with the polygons than to test each polygon with each point. – Vince Jun 3 '14 at 0:18

You're re-establishing the cursor on fc1 on each iteration of the cursor on fc. Why not do a spatial join, points to polys, then if you want to populate the points fc, run a secondary operation on the output with a cursor.

  • 1
    I upvoted because I think your Answer has the essence of a more sensible approach. However, I would have liked to see considerable more detail. Perhaps you can use the edit button to flesh it out sometime. – PolyGeo Jun 3 '14 at 2:23
  • @Wayne,I know I could use a spatial join. I just didn't want to deal with the extra fields that are added when you do a spatial join. I just feel that the logic of my code makes sense(unless am missing something) and that it should be able to work and essentially give me the same results as a spatial join but without the extra fields. You said am restablishing the cursor? is that what's causing the code not to work? thanks. – ketar Jun 3 '14 at 4:14
  • I've seen something similar to what am trying to do done here: gis.stackexchange.com/questions/52936/… except I need to do it with arcpy.da – ketar Jun 3 '14 at 4:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.