Hi, I have been using this VBA field calculator script in ArcGIS 9.3.1 to shift points spatially according to the X & Y fields from a table join:
Dim pPoint As IPoint
Set pPoint = [Shape]
pPoint.X =
pPoint.Y =
__esri_field_calculator_splitter__
pPoint
However, it does not work in after I upgraded to ArcGIS 10.2.2. Is there anyone who is able to convert this VBA script to Python?
Thank you in advance.
Regards,
Siyang
Solved! Go to Solution.
I found a Python script that does the work, however, it can only shift when the XY fields are within the shapefiles, but does not work when reading from fields of a table join.
Anyone knows how to rectify this?
def pointMove(shape,x_value,y_value):
point = shape.getPart(0)
point.X = x_value
point.Y = y_value
return point
__esri_field_calculator_splitter__
pointMove( !Shape!, !X!, !Y! )
I found a Python script that does the work, however, it can only shift when the XY fields are within the shapefiles, but does not work when reading from fields of a table join.
Anyone knows how to rectify this?
def pointMove(shape,x_value,y_value):
point = shape.getPart(0)
point.X = x_value
point.Y = y_value
return point
__esri_field_calculator_splitter__
pointMove( !Shape!, !X!, !Y! )
> it does not work in after I upgraded to ArcGIS 10.2.2.
You must have updated from 9.3. The field Calculator no longer supports VBA, it now only supports VBScript and Python. You must use Python to access geometry as of ArcGIS 10.0. There are shortcuts that work with the Python syntax (i.e. "SHAPE@" for the shape field). See the examples in the help.
> does not work when reading from fields of a table join.
If the X and Y were joined fields, you'd need to uses prefixes, see below. Is that not working?
If anyone was wondering, the text snippet we've been sharing here is a .cal file such as what you can write from the right click field / calculate field dialog box access from a table view in ArcMap. The "__esri_field_calculator_splitter__" line separates the code block from the Calculate Field expression.
Kind of an 8.x-ish interface ... but it is still supported.
def pointMove(shape,x_value,y_value):
point = shape.getPart(0)
point.X = x_value
point.Y = y_value
return point
__esri_field_calculator_splitter__
pointMove( !SHAPE@!, !jtable.X!, !jtable.Y! )
Hi,
Thanks for the reply.
Can I clarify; let's say my joined field names for X & Y are Temp.X_Point & Temp.Y_Point respectively (Temp being the joined layer/table name). Should the resulting expression be:
pointMove( !SHAPE@!, !jtable.Temp.X_Point!, !jtable.Temp.Y.Point! )
OR
pointMove( !SHAPE@!, !jtable.X_Point!, !jtable.Y.Point! )
I tried both but the field calculator was unable to execute.
Thanks!
jtable was my example table name:
pointMove( !SHAPE@!, !Temp.X_Point!, !Temp.Y_Point! )
Hi Price,
I have changed the join table field names.
However, there was an error message at the geoprocessing results window, saying "Invalid field SHAPE@".
After changing the shape field to the actual field name, another error appeared, saying "invalid syntax (<string>, line 1)".
Wonder how to rectify from here... would you know?
Thanks for spending time with this issue btw.
This thread continues (several months later) here: