Hello ArcGIS Forum Users, I have been able to use Python to copy a polyline dataset and add four fields (FROM_X, TO_X, FROM_Y, TO_Y) but am having trouble with populating the fields with the appropriate information. I would like to use Python to populate them in the following manner:
FROM_X = X Coordinate of Line Start TO_X = X Coordinate of Line End FROM_Y = Y Coordinate of Line Start TO_Y = Y Coordinate of Line End
I know it can be done manually by opening the datasets attribute table, right clicking on a field, selecting Calculate Geometry and then the appropriate Property but I would like to have a Python script be able to do this so it can be embedded in a SAS script. The COPY and ADD FIELD Python script works in SAS so I am hoping the CALCULATE FIELD will as well.
I tried using the Data Management - Fields - Calculate Field and its Python option for FROM_X using:
Try this: - put the '!' around the whole expression and fetch the value from the shape field, i.e., "!SHAPE.FIRSTPOINT.X!" - your field name goes where "fieldname" is, i.e., "FROM_X" - no code block, so you don't really need to include the empty string for the 5th param, but this may not matter. - the 'dataset' param is your fc - remember, all parameters are strings, so you need the quotes (unless you use variables)
Try this: - put the '!' around the whole expression and fetch the value from the shape field, i.e., "!SHAPE.FIRSTPOINT.X!" - your field name goes where "fieldname" is, i.e., "FROM_X" - no code block, so you don't really need to include the empty string for the 5th param, but this may not matter. - the 'dataset' param is your fc - remember, all parameters are strings, so you need the quotes (unless you use variables)