Can I place a line on a point using an attribute for the angle?

4537
4
07-24-2015 12:59 PM
KristineMuma
New Contributor II

I have a set of points that I need to label in another software that has very limited labeling capabilities. We really need to be able to rotate the label by an attribute that we store. We came up with the desire to be able to place a line on that point of a predefined length and set the direction of the line to be in the angle of the rotation field. Has anyone ever attempted this?

0 Kudos
4 Replies
WesMiller
Regular Contributor III
0 Kudos
KristineMuma
New Contributor II

Unfortunately Annotation is not an option. And using the annotation polygon isn't working because anything that is a single digit is labeling incorrectly or not at all in this third party software. We are extremely disappointed that this was not going to work! Thanks

0 Kudos
DarrenWiens2
MVP Honored Contributor

Here's a script that should do what you're after:

>>> newLines = []
... points = "grid_label"
... angleField = "OID"
... lineLength = 300
... sr = arcpy.Describe(points).spatialReference
... with arcpy.da.SearchCursor(points,["SHAPE@",angleField],spatial_reference=sr) as cursor:
...     for row in cursor:
...         x1 = row[0].centroid.X + (math.sin(math.radians(row[1]))*(lineLength/2))
...         y1 = row[0].centroid.Y + (math.cos(math.radians(row[1]))*(lineLength/2))
...         x2 = row[0].centroid.X - (math.sin(math.radians(row[1]))*(lineLength/2))
...         y2 = row[0].centroid.Y - (math.cos(math.radians(row[1]))*(lineLength/2))
...         newLine = arcpy.Polyline(arcpy.Array([arcpy.Point(x1,y1),arcpy.Point(x2,y2)]),sr)
...         newLines.append(newLine)
... arcpy.CopyFeatures_management(newLines,r'in_memory\lines')

KristineMuma
New Contributor II

Thanks Darren! I am so new to Python I knew I didn't have time to attempt to figure it out on my own. I can't wait to try this....

>>> Darren Wiens <geonet@esri.com> 7/24/2015 4:29 PM >>>

GeoNet

( https://community.esri.com/?et=watches.email.thread)

Can I place a line on a point using an attribute for the angle?

reply from Darren Wiens

( https://community.esri.com/people/dkwiens?et=watches.email.thread) in Developers - View the full discussion

( https://community.esri.com/message/538527?et=watches.email.thread#538527)

Here's a script that should do what you're after:

>>> newLines = []

... points = "grid_label"

... angleField = "OID"

... lineLength = 300

... sr = arcpy.Describe(points).spatialReference

... with arcpy.da.SearchCursor(points,["SHAPE@",angleField]) as cursor:

... for row in cursor:

... x1 = row[0].centroid.X + (math.sin(math.radians(row[1]))*(lineLength/2))

... y1 = row[0].centroid.Y + (math.cos(math.radians(row[1]))*(lineLength/2))

... x2 = row[0].centroid.X - (math.sin(math.radians(row[1]))*(lineLength/2))

... y2 = row[0].centroid.Y - (math.cos(math.radians(row[1]))*(lineLength/2))

... newLine = arcpy.Polyline(arcpy.Array())

... newLines.append(newLine)

... arcpy.CopyFeatures_management(newLines,r'in_memory\lines')

https://community.esri.com/servlet/JiveServlet/downloadImage/2-538527-118816/pastedImage_0.png

( https://community.esri.com/servlet/JiveServlet/showImage/2-538527-118816/pastedImage_0.png)

Reply to this message by replying to this email, or go to the message on GeoNet

( https://community.esri.com/message/538527?et=watches.email.thread#538527)

Start a new discussion in Developers by email

( mailto:discussions-community-developers@mail.geonet.esri.com) or at GeoNet

( https://community.esri.com/choose-container.jspa?contentType=1&containerType=14&container=2030&et=watches.email.thread)

Following Can I place a line on a point using an attribute for the angle?

( https://community.esri.com/message/538527?et=watches.email.thread#538527) in these streams: Inbox

This email was sent by GeoNet because you are a registered user.

You may unsubscribe

( https://community.esri.com/unsubscribe.jspa?email=kmuma%40peterborough.ca&token=ddc1f5090c4eb13f98ad6c7c0516de919c7f5c29e1486eca3c3d526bae9eca83) instantly from GeoNet, or adjust email frequency in your email preferences

( https://community.esri.com/user-preferences!input.jspa)

0 Kudos