Calculating offset coordinates of points

3412
2
12-22-2013 02:12 AM
GrljAles
Occasional Contributor
Hello!

I have the following problem; I have points feature class that i created from polygons with their coordinates. I would like to calculate for each point the coordinates of the second point at certain distance and at certain angle from the original point. I managed to calculate the offset values for X and Y but I cannot add those values to original coordinates. I was able to do that in ArcMap 10.1 in edit session using calculate field in table however I cannot get python to do the same thing. Python just rounds up the result despite fact that all fields are float.
Here is picture of attribute table where I calculated end_X field with field calculator in ArcMap (that's how I would like the result to loke like) and end_Y field that was calculated using python.
[ATTACH=CONFIG]30065[/ATTACH]

First I tried to do this using cursors (commented out region), after that I opened edit sesion and used calculate field but that also didn't gave the desired result. Here is the relevant part of code:

rows = arcpy.UpdateCursor(depressionsLocation + centerName, "", depressionsLocation + depressionsName.replace('.shp', '.prj'))
for row in rows:
    row.disp_X = (sin(float(row.MBG_Orient))*row.MBG_Length)
    rows.updateRow(row)
del row, rows
rows = arcpy.UpdateCursor(depressionsLocation + centerName, "", depressionsLocation + depressionsName.replace('.shp', '.prj'))
for row in rows:
    row.disp_Y = (cos(float(row.MBG_Orient))*row.MBG_Length)
    rows.updateRow(row)
del row, rows

##rows = arcpy.UpdateCursor(depressionsLocation + centerName, "", depressionsLocation + depressionsName.replace('.shp', '.prj'))
##for row in rows:
##    row.end_X = (float(row.X)+float(row.disp_X))
##    rows.updateRow(row)
##del row, rows
##rows = arcpy.UpdateCursor(depressionsLocation + centerName, "", depressionsLocation + depressionsName.replace('.shp', '.prj'))
##for row in rows:
##    row.end_Y = (float(row.Y)+float(row.disp_Y))
##    rows.updateRow(row)
##del row, rows

edit = arcpy.da.Editor(depressionsLocation)

# Edit session is started without an undo/redo stack for versioned data
#  (for second argument, use False for unversioned data)
edit.startEditing(False, True)

# Start an edit operation
edit.startOperation()

arcpy.CalculateField_management(centerName, "end_X", '!X! + !disp_X!', "PYTHON")

# Stop the edit operation.
edit.stopOperation()

# Stop the edit session and save the changes
edit.stopEditing(True)
Tags (2)
0 Kudos
2 Replies
GrljAles
Occasional Contributor
Just figured that out, also when I close the edit session in ArcMap and save results the decimal places in table disappear...
0 Kudos
GrljAles
Occasional Contributor
Nevermind....figured it out myself but I don't understand why this happens. I only changed the line that creates all six fields and set scale and precision values from 10 to "" and the results are correct. However it is interesting that disp_X and Y fields were calculated correctly even before the change was made.
0 Kudos