# Updating Shape Field from Lat/Long Fields

4839
10
12-19-2017 07:31 PM
New Contributor II

I'm trying to update the SHAPE field of some points by using field calculator to update the SHAPE field based on X, Y fields in the attribute table. Can this be done? I'm trying the below calculation, and the points are changing location, but not to a location that is near either the X, Y fields I'm asking it to. I'm not sure where I'm going wrong here.

Tags (1)
1 Solution

Accepted Solutions
Esri Esteemed Contributor

The actual reason why the calculation wasn't working is since you return a Point object when the geometry is in fact a PointGeometry.object.  See the field calculator expression below:

So you create a point object with the new X and Y and then use the point object to create the point geometry.. What you did in your second example is providing the point geometry to the function and modify the point X and Y properties using the first part, and returning the point geometry object again

CC Jayanta Poddar , it is possible to modify the geometry using the field calculator as the result below shows. The red dots were moved with coordinates from my X and Y fields:

10 Replies
MVP Legendary Contributor

some sample values might help... if they are supposed to be in longitude and latitude, make sure longitude is the X and latitude is the Y (a common error) and in the western hemisphere, longitude is negative..

New Contributor II

Dan,

Here are my values I'm trying to put in the shape field.

But after I run the calc, and then pull the values out of the shape field, they resemble nothing of the X, Y fields. It changes it to the following. I don't get it.

MVP Legendary Contributor

I would suggest adding the table to arcmap as an event layer then save/export it as a shapefile or featureclass in a geodatabase... there is no point messing with the shapefile since something is amiss.  You will have all your attributes and the file will be clean.  As shown the top field does have the correct X and Y values with Longitude in the -121 and lat at 42.

New Contributor II

Shoot, I had the script wrong. I needed the Shape as a parameter. This works. Thanks Dan.

Esri Esteemed Contributor

The actual reason why the calculation wasn't working is since you return a Point object when the geometry is in fact a PointGeometry.object.  See the field calculator expression below:

So you create a point object with the new X and Y and then use the point object to create the point geometry.. What you did in your second example is providing the point geometry to the function and modify the point X and Y properties using the first part, and returning the point geometry object again

CC Jayanta Poddar , it is possible to modify the geometry using the field calculator as the result below shows. The red dots were moved with coordinates from my X and Y fields:

Esri Esteemed Contributor

Rethinking it I realize that you don't have to specify the spatial reference, since the featureclass already has this defined. You could use this to make thing more simple:

Occasional Contributor III

I'm using ArcPro, and the Python might be different. Can you tell me why my code isn't working, please?

MVP Regular Contributor

The function parameters in the code block should not have exclamation marks, that's only for the field names in the expression. Get rid of all ! characters in the code block.

MVP Esteemed Contributor

In ArcGIS, Shape* is a system-managed field that is used to store the Geometry-type of the Features. It is Read-only, and you cannot edit it.

Think Location