Hello,
In the last few days I've been working on a Python script that enables me to draw lines in a feature class.
The script gets 3 params - starting point coordinates, angle (degree) and length in km.
After a few hours of investigating for possible implementations, I've decided to drop the mathematical approach and use the pre-made tool called BearingDistanceToLine_management.
My current implementation actually works but the designed is ridiculous! The tool requires two special tables!
I have one table that holds the parameters - I actually do an InsertCursor into a table just for the tool to run!
I have another table, which gets the output when the tool is finished.
When the tool is done, I run a searchCursor on the output table, take the output shape data and adds it into a THIRD and final table where I can add my own other columns.
Can anyone recommends a better solution? I have found many articles with a lot of math lessons but no clear solid answer how to do it. I can't waste my time on learning trigonometry for this and pretty surprised ESRI doesn't have a simple pre-made function for that.
Thanks,
Shay.
Solved! Go to Solution.
The Bearing Distance to Line tool is designed to work on sets of data like most geoprocessing tools. As Dan points out, if you are up for a little scripting, the ArcPy Geometry classes have a pointFromAngleAndDistance() method that can used to create a line.
def lineFromAngleAndDistance(geometry, angle, distance, method="GEODESIC"):
SR = geometry.spatialReference
pt1 = geometry.firstPoint
pt2 = geometry.pointFromAngleAndDistance(
angle, distance, method
).firstPoint
polyline = arcpy.Polyline(arcpy.Array([pt1, pt2]), SR)
return polyline
If you have a few to do, then this can be done in an edit session If the data are not in a table, then the edit session is the way to go. But if you have lots and a table, then the existing tool is best otherwise, roll out your own using python or numpy. If you create functions or use someone elses, then you can reuse the code again. It is a matter of skill, preference, and data structure and amount which method you choose
Thank you Dan. I have only few lines to draw. Nothing big.
Do you know if those COGO tools are available in Python? I could see how I can use it in my script.
I'm sure people have functions for that already. I thought maybe someone will care to share some knowledge
At first, I started writing the calculation but it's a lot of trigonometry and the mistakes I might do will cost more than my wasted time.
Shay,
I found a nice link on Stack Exchange (hey whuber!) with an arcpy geometry example too!
Remember if you create arcpy geometry objects GP can read them as a dataset, so, for example, you can convert them to features using Copy Features.
Using geometry objects with geoprocessing tools—Help | ArcGIS Desktop
Thanks a lot! I'll check it out
The Bearing Distance to Line tool is designed to work on sets of data like most geoprocessing tools. As Dan points out, if you are up for a little scripting, the ArcPy Geometry classes have a pointFromAngleAndDistance() method that can used to create a line.
def lineFromAngleAndDistance(geometry, angle, distance, method="GEODESIC"):
SR = geometry.spatialReference
pt1 = geometry.firstPoint
pt2 = geometry.pointFromAngleAndDistance(
angle, distance, method
).firstPoint
polyline = arcpy.Polyline(arcpy.Array([pt1, pt2]), SR)
return polyline
That's perfect thank you! I guess I misunderstood Dan but this snippet helps a lot thank you.