Adding XY Fields to an Attribute Table

14059
7
Jump to solution
01-16-2015 05:57 AM
KONPETROV
Occasional Contributor III

Hello i have a point.shapefile with fields: FID:0123..., Shape:Points, CONTOUR:400, 401 etc, X, Y. I want to add x,y coordinates to attribute table from a mosaic, how can i do that?

I tried from field calculator the following script for X and Y fields at 'show codeblock':

Dim dblX As Double

Dim pPoint As IPoint

Set pPoint = [Shape]

dblX = pPoint.X

X=

dblX

but i have always an error 999999. I am using ArcGis 10.2.2. any suggestion?

1 Solution

Accepted Solutions
TedKowal
Occasional Contributor III

As Jake mentioned there are numerous different Geoprocessing tools that will do this depending on your own unique conditions....

Have you tried the most simple direct way?  Right click on the field you want to populate on your attribute table and choose calculate geometry?

CalcGeometry.pngc.png

View solution in original post

7 Replies
JakeSkinner
Esri Esteemed Contributor

Hi Konstantinos,

There is a Geoprocessing tool that will do this for you:

ArcGIS Help (10.2, 10.2.1, and 10.2.2)

TedKowal
Occasional Contributor III

As Jake mentioned there are numerous different Geoprocessing tools that will do this depending on your own unique conditions....

Have you tried the most simple direct way?  Right click on the field you want to populate on your attribute table and choose calculate geometry?

CalcGeometry.pngc.png

KONPETROV
Occasional Contributor III

thank you very much sir, it helped me a lot

0 Kudos
JoshuaBixby
MVP Esteemed Contributor

The code you provide above is from the Making Field Calculations help from ArcGIS 9.3/9.3.1, and therein lies your problem.  The code Esri provided was VB/VBA and involved accessing ArcObjects.  Starting with ArcGIS 10.0, Esri moved to a VBScript parser instead of a fuller-featured VB/VBA.  Although some VB code still works in the code block for the field calculator, the specific code you used doesn't because you can't acess ArcObjects through VBScript.

Even if the code you posted worked, VB support has been on life support for a long time, and you should really consider moving to Python.  If you simply change the parser to Python, the following code will work in the expression box (you don't need a code block): !shape.extent.XMax! . Since it seems you are working with points, and single points at that, the extent of the geometry will be the geometry itself.  You could also use !shape.firstPoint.X! as well.

XanderBakker
Esri Esteemed Contributor

You can also do it automatically with Python as I showed in this post: Automatic X and Y in Attribute Table

KONPETROV
Occasional Contributor III

can i also use compute geometry for that? for each field (x,y )separate?

0 Kudos
XanderBakker
Esri Esteemed Contributor

Not sure to which answer you are replying:

  • Jake showed you a tool that in a single run will add the fields POINT_X and POINT_Y to you featureclass
  • Ted showed that you can calculate the fields using Calculate Geometry (use X coordinate of Point for X and Y Coordinate of Point for Y)
  • Joshua offered a method to use a python syntax to fill the fields using the field calculator (!shape.firstPoint.X! for X and !shape.firstPoint.Y! for the Y field).
  • My suggestion has the ability to loop through all the featureclasses in a workspace and add the fields to each of them

You will have to decide which method suits your specific needs best.