Field calculator problem

818
8
10-11-2011 02:10 PM
BamJam
by
New Contributor III
I'm trying to do a very simple action using the field calculator. I have a shp file that I want to calculate the start and finish xy coordinates. I have added the new fields and gone into the field calculator throught toolbox and entered:

!shape.firstpoint.x! for the begin_x field but I get the following error:

Executing (CalculateField_28): CalculateField ROUTEM_1_Intersect begin_x !shape.firstpoint.x! PYTHON # ROUTEM_1_Intersect
Start Time: Tue Oct 11 17:08:08 2011
Invalid property firstpoint.x. Valid properties: type, extent, centroid, label, firstpoint, lastpoint, area, length, ismultipart, partcount
Failed to execute (CalculateField_28).
End Time: Tue Oct 11 17:08:08 2011 (Elapsed Time: 0.00 seconds)

Any ideas on what I'm doing wrong?

Thanks
Tags (2)
0 Kudos
8 Replies
DanPatterson_Retired
MVP Emeritus
try capitalizing the x (ie X), if memory serves the properties within python are case-sensitive (also check the shape syntax/capitalization
0 Kudos
BamJam
by
New Contributor III
I tried using the syntax: !SHAPE.firstpoint.X! and got this error:

Executing (CalculateField_1): CalculateField "J:\Work\North System\ROUTEM_1_Intersect.shp" begin_x !SHAPE.firstpoint.X! PYTHON # "J:\Work\North System\ROUTEM_1_Intersect.shp"
Start Time: Wed Oct 12 08:22:15 2011
Invalid property firstpoint.X. Valid properties: type, extent, centroid, label, firstpoint, lastpoint, area, length, ismultipart, partcount
(DAO.TableDefs) Item not found in this collection.
Failed to execute (CalculateField_1).
End Time: Wed Oct 12 08:22:15 2011 (Elapsed Time: 0.00 seconds)

I then tried !shape.firstpoint.X! and got this error:

Executing (CalculateField_2): CalculateField "J:\Work\North System\ROUTEM_1_Intersect.shp" begin_x !shape.firstpoint.X! PYTHON # "J:\Work\North System\ROUTEM_1_Intersect.shp"
Start Time: Wed Oct 12 08:24:19 2011
Invalid property firstpoint.X. Valid properties: type, extent, centroid, label, firstpoint, lastpoint, area, length, ismultipart, partcount
Failed to execute (CalculateField_2).
End Time: Wed Oct 12 08:24:20 2011 (Elapsed Time: 1.00 seconds)

I then tried !SHAPE.firstpoint.x! and got:

Executing (CalculateField_3): CalculateField "J:\Work\North System\ROUTEM_1_Intersect.shp" begin_x !SHAPE.firstpoint.x! PYTHON # "J:\Work\North System\ROUTEM_1_Intersect.shp"
Start Time: Wed Oct 12 08:25:43 2011
Invalid property firstpoint.x. Valid properties: type, extent, centroid, label, firstpoint, lastpoint, area, length, ismultipart, partcount
Failed to execute (CalculateField_3).
End Time: Wed Oct 12 08:25:44 2011 (Elapsed Time: 1.00 seconds)

Then !SHAPE.FIRSTPOINT.X! and got:

Executing (CalculateField_4): CalculateField "J:\Work\North System\ROUTEM_1_Intersect.shp" begin_x !SHAPE.FIRSTPOINT.X! PYTHON # "J:\Work\North System\ROUTEM_1_Intersect.shp"
Start Time: Wed Oct 12 08:26:22 2011
Invalid property FIRSTPOINT.X. Valid properties: type, extent, centroid, label, firstpoint, lastpoint, area, length, ismultipart, partcount
Failed to execute (CalculateField_4).
End Time: Wed Oct 12 08:26:22 2011 (Elapsed Time: 0.00 seconds)

Any other suggestions?
0 Kudos
RuthEmerick
New Contributor II
Try this:

arcpy.CalculateField_management(test_shapefile_path, "test_field", "!shape.firstpoint.x!", "PYTHON_9.3", "")


For some reason, this does not work if the mode is set to "PYTHON." See related post, http://forums.arcgis.com/threads/11476-Calculate-Field-Management-%28x-y%29-using-Python-in-ArcGIS-1....
0 Kudos
MarcNakleh
New Contributor III
The problem here is that
!Shape.firstpoint.X!

should be
!Shape!.firstpoint.X
(notice the '!' placement)
The exclamation marks delineate a field, which is SHAPE here. Once you're looking at the right field, you can access its members' attributes or methods, using the dot notation.

Worked like a charm on my PC.

Best of luck!
0 Kudos
BamJam
by
New Contributor III
I've tried all of the suggestions without any luck.  The only way that I can get it to extract the data is if I use:

!shape.firstpoint!

What's worse is that I have to have the field type set to text!  So, I end up with: 

-92.298060755811 41.6208860260915 in my destination field. 

I have been able to populate my desired fields from these fields and convert it to a double, but it has been a real pain.

I'm running ArcInfo 9.2 does that make a difference on the syntax?

Thanks
0 Kudos
RichardFairhurst
MVP Honored Contributor
I've tried all of the suggestions without any luck.  The only way that I can get it to extract the data is if I use:

!shape.firstpoint!

What's worse is that I have to have the field type set to text!  So, I end up with: 

-92.298060755811 41.6208860260915 in my destination field. 

I have been able to populate my desired fields from these fields and convert it to a double, but it has been a real pain.

I'm running ArcInfo 9.2 does that make a difference on the syntax?

Thanks


At 9.2 you could not use a method to access the X or Y component of the coordinate directly.  That capability first appeared at 9.3.  You had to parse the coordinates to get each desired coordinate separated and cast them to a float for directly calculating them to a pair of double fields.  That avoids first saving the whole string to a text field.  I don't have access to 9.2 anymore, but as I recall the syntax works something like:

float(!shape.firstpoint![0]) # for X coordinate.  float(!shape.firstpoint![1]) for Y coordinate.
0 Kudos
curtvprice
MVP Esteemed Contributor
Try:

arcpy.CalculateField_management(test_shapefile_path, "LONDD", "float(!shape.firstpoint!.split()[0])", "PYTHON")
arcpy.CalculateField_management(test_shapefile_path, "LATDD", "float(!shape.firstpoint!.split()[1])", "PYTHON")
0 Kudos
BamJam
by
New Contributor III
Good to know that 9.2 doesn't support a method to access xy coordinates directly  (maybe one day we will upgrade).  I was able to get the data populated, but will try these other methods in the future.

Thanks for all your help!
0 Kudos