1

When using an InsertCursor, I can specify a spatial reference per http://resources.arcgis.com/en/help/main/10.1/index.html#//018v0000002z000000.

I'm using da.InsertCursor because that's what everyone tells me to use and I've encountered no problems with it. How do I specify a spatial reference when using a da.InsertCursor?

Spatial reference is not even mentioned on the help page... http://resources.arcgis.com/en/help/main/10.1/index.html#//018w0000000t000000

  • You may be able to change it with the environment setting but I'm not 100% sure the cursor honors it since usually the objects already have a SR. Also although the da version of the search cursor is usually recommended especially for large datasets, but you can still use the old cursor. – landocalrissian Jul 10 '15 at 15:59
  • I'm wondering why you want to specify a spatial reference. You would probably be better off testing and reprojecting the geometry of the incoming rows before you do the insert. – blord-castillo Jul 10 '15 at 20:15
7

I think it is assumed if you are passing in your own geometry, the geometry objects will have a spatial reference:

import arcpy

fc = r'C:\path\some_gdb.gdb\some_fc'
sr = arcpy.SpatialReference(4326)

with arcpy.da.InsertCursor(fc, 'SHAPE@') as rows:
    for pnt in [(-93.2, 41.1), (-92.8, 44.7)]:
        rows.insertRow([arcpy.PointGeometry(arcpy.Point(*pnt), sr)])
  • Hey DenaliHardtail. Yeah, the spatial reference is specified in the feature class or geometry object, not in the da.cursor row. The FC should already have a spatial reference - try arcpy.Describe(fc).spatialReference.name or you can use the Define Projection tool to specify a spatial reference at the FC level. Otherwise you can pass the spatial reference to the geometry object like crmackey has described. – John Jul 11 '15 at 3:10

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.