Is it possible to use the coordinate system from a data frame in the current map document within an update cursor?
I have data in GCS WGS84 and I want to update area/perimeter/length fields across a geodatabase with UTM WGS84 units. I want to acquire a coordinate system for the cursor from the current map data frame coordinate system, not a reference feature class. A piece of my current script is below, which would return useless area/length values from GCS coordinates:
for fc in fcList: fc = fc +"\\" fieldList = arcpy.ListFields(fc, 'lengthSize')#lengthSize field fieldCount = len(fieldList) if (fieldCount > 0): print "perimeterSize field present in: " + fc arcpy.AddMessage ("perimeterSize field present in: " + fc) with arcpy.da.UpdateCursor (fc, ['SHAPE@LENGTH', 'lengthSize']) as cursor: for row in cursor: row = row cursor.updateRow(row) print "Updating 'lengthSize' field in: " + fc arcpy.AddMessage ("Updating 'lengthSize' field in: " + fc) else: print "No lengthSize field in: ", fc arcpy.AddMessage ("No lengthSize field in: " + fc)
Is this possible, or does a "describe" (like that found here: http://pro.arcgis.com/en/pro-app/arcpy/get-started/setting-a-cursor-s-spatial-reference.htm) have to be used?
Thanks Darren, I needed to fix a syntax and I have that working. Now...is it possible for me to assign variables based on the data frame coordinate system? Specifically, if the data frame coordinate system is UTM WGS84, the units are meters. I'd like to establish something like, "if data frame coordinate system units are meters, then variable1 = 'metre', variable2 = 'squareMetre', etc."
I don't know how to 'query' the df.
You get to the df(s) by listing the dfs in a MapDocument:
>>> mxd = arcpy.mapping.MapDocument('CURRENT') ... for df in arcpy.mapping.ListDataFrames(mxd): ... print df.spatialReference.name ... print df.spatialReference.linearUnitName ... NAD_1983_UTM_Zone_11N Meter NAD_1983_UTM_Zone_11N Meter