I am running ArcMap 10.2 on Windows 7.
I have a point feature class that has a designated field for X and Y coordinate values. I am looking to automate the generation of these values within a model that I already use for multiple processes. I have tried many different attempts with Python code within the Calculate Field tool in Model Builder with no success.
Here are the options that I have tried thus far: (the formatting is awkward and I couldn't figure out how to fix it. The code is there, though.
1 - !shape.extent.XMax! (I think this is the wrong direction since our target layer is of point type)
2 - '=========================
'point_Get_X.cal
'Author: Ianko Tchoukanski
'http://www.ian-ko.com
'=========================
On Error Resume Next
Dim pMxDoc As IMxDocument
Dim pMap As IMap
Dim pPoint As IPoint
Dim dX As Double
Dim bSrefFromMap As Boolean
'=======================
'Adjust the parameter below
'True ==> the coordinates will be calculated in the projection of the Map
'False ==> the coordinates will be calculated in the projection of the data
bSrefFromMap = True
'=======================
If (Not IsNull([Shape])) Then
Set pPoint = [Shape]
If (bSrefFromMap) Then
Set pMxDoc = ThisDocument
Set pMap = pMxDoc.FocusMap
pPoint.Project pMap.SpatialReference
End If
dX = pPoint.X
else
dX = 0
End If
3 - !shape.firstpoint.X!
4 – Dim dblX As Double
Dim pPoint As IPoint
Set pPoint = [Shape]
dblX = pPoint.X