Currently I am making a script that allows the user to draw a line, the line is then created into end points with lat/long available.
From this lat/long, I have to run some math equations to figure out where the next coordinates should be. I have gotten it to create the points based on a line, calculate the bearing, and used ArcPy to place the next point into the shapefile using my math equation as a test.
I am using Arcmap 10.4 for testing. I have access to Pro and 10.7, but I am using 10.4 just to learn.
My question is how do I read the attributes of a file so that I can use the X/Y of a point to run my equations on?
I have (light) experience using Pandas, working with CSV's etc just very new to ArcPy. Below is a list of what I am doing to make it easy.
- Create line. Use COGO to add bearing.
- Create points from lines.
- Read attribute table. Read X/Y. (This is what I need help with).
- Run equation on X/Y to get the next 4 points.
- Add points to point shapefile.
When I have it figured out I can provide an update to share the code with for future use.
-
You could just use the make XY event layer tool which makes an in-memory layer object which you can either process directly or save out to a permanent dataset which you process (e.g. add new fields to).Hornbydd– Hornbydd2021年03月24日 19:07:11 +00:00Commented Mar 24, 2021 at 19:07
-
I will take a look at using this option. That sounds like it would be useful for this.Brian Hamilton– Brian Hamilton2021年03月24日 20:09:17 +00:00Commented Mar 24, 2021 at 20:09
1 Answer 1
Try the da.SearchCursor:
SearchCursor establishes read-only access to the records returned from a feature class or table.
With the SHAPE@XY token:
import arcpy
fc = r'C:\path\to\data.gdb\featureclass'
with arcpy.da.SearchCursor(fc, 'SHAPE@XY') as cursor:
for row in cursor:
x, y = row[0]
Explore related questions
See similar questions with these tags.