Calculate values of coordinates in more system coordinates in same time, using unique tool

729
1
01-16-2017 08:25 AM
SamuelAbati
New Contributor III

I have a table with several points. The attributes contain 3 "types" of coordinates in the SIRGAS2000 datum (decimal, DMS and UTM). I want to calculate these coordinates with a tool, because it is annoying to select zones(fuso) before calculating in UTM.

PS: The answer can be in the model builder or python. If it's in python, explain in detail (I'm still learning python)

PS2: the format in longitude/latitude GMS(DMS) can be a little different.

0 Kudos
1 Reply
DarrenWiens2
MVP Honored Contributor

Here is a quick way to switch between coordinate reference systems based on a field.

Notes:

- my zone field is an integer (values are 9 or 10, indicating which NAD83 UTM Zone the point is in). Yours is text, but you can convert it to integer like below (takes zone text value, minus the last character, and converts to integer):

cur_wkid = int(wkid_shift + int(row[1][:-1]))

- the script relies on the wkid number being related to the zone number. In my example, I add 26900 to the zone number to get the wkid number. So, zone 9 becomes wkid = 26909 (the correct wkid for NAD83 UTM Zone 9). In your case, you need to add 31960 to the zone number. So, zone 22 becomes wkid = 31982, and zone 21 becomes wkid = 31981.

- change the values for fc, zone_field, x_field, y_field, and wkid_shift to match your data.

- you should probably make a back-up copy, just in case things go wrong.

Script:

>>> fc = 'merge' # your feature class
... fc_sr = arcpy.Describe(fc).spatialReference # get the spatial reference
... zone_field = 'UTM_Zone' # change to your zone field
... x_field = 'Easting' # change to your x field
... y_field = 'Northing' # change to your y field
... wkid_shift = 26900 # change to 31960
... with arcpy.da.UpdateCursor(fc,['SHAPE@',zone_field,x_field,y_field],spatial_reference=fc_sr) as cursor: # loop through features
...     for row in cursor:
...         cur_wkid = int(wkid_shift + row[1]) # calculate new wkid for the feature
...         proj_point = row[0].projectAs(arcpy.SpatialReference(cur_wkid)).centroid # project a new point
...         row[2] = proj_point.X # get the x value of the new point
...         row[3] = proj_point.Y # get the y value of the new point
...         cursor.updateRow(row) # write the new values to the feature‍‍‍‍‍‍‍‍‍‍‍‍‍