Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

What I'm trying to do is create a line feature from a single point, using a set distance and angle. Using ArcGIS and Python (I hope). Here's the scenario:

Say I have a point at these coordinates: X = 400460.99, Y = 135836.76 From this point, I want to create a 800 Meter long line at a 15 degree angle from that point. I do not know what the resulting endpoint will be, which is frustrating. (My data are projected in Maryland State Plane South - Meters)

Thanks for any help and suggestions.

James

share|improve this question
    
Hi, First off thanks so much for the script. I had the exact same question and this will hopefully save me a lot of time. However, I am very new to the Python part of ArcGIS and I tried to run this script in my python terminal in ArcMap and got the error Runtime error <type 'exceptions.AttributeError'>: 'module' object has no attribute 'createFeatureClass_management' What do I need to do to fix this? Many thanks, –  user2298 Mar 12 '11 at 19:38
    
Try arcpy.CreateFeatureclass_management instead of arcpy.createFeatureclass_management (small c replace with uppercase) You also need ArcMap 10. –  Dan Patterson Mar 12 '11 at 20:09
    
The edits appear to have been made today. –  Dan Patterson Mar 13 '11 at 17:29
    
@NJA - for this particular script, you would need ArcGIS 10 (because it imports and uses the arcpy site package). However it can be modified to work in 9.3 - just import the arcgisscripting module, then add arcgisscripting.create() on the next line. –  J Graham Mar 14 '11 at 14:49
    
...doing it this way, you won't have to change the case of CreateFeatureClass_management –  J Graham Mar 14 '11 at 14:51

2 Answers 2

up vote 10 down vote accepted

The endpoint is displaced from the origin by 800 meters, of course. The displacement in the direction of the x-coordinate is proportional to the sine of the angle (east of north) and the displacement in the direction of the y-coordinate is proportional to the cosine of the angle.

Thus, from sin(15 degrees) = sin(0.261799) = 0.258819 and cos(15 degrees) = 0.965926 we obtain

x-displacement = 800 sin(15 degrees) = 800 * 0.258819 = 207.055 

y-displacement = 800 cos(15 degrees) = 800* 0.965926 = 772.741.

Therefore the endpoint coordinates are (400460.99 + 207.055, 135836.76 + 772.741) = (400668.05, 136609.49).

share|improve this answer
    
whuber, thank you for this answer. More often, I'm finding myself lacking in the basic trig knowledge that would make this a little easier to understand. I stumbled across your post here link. Any suggestions for further reading? –  J Graham Mar 3 '11 at 3:49
1  
@J You really don't need much more trigonometry knowledge than contained right here! As I hinted in that other post, trig is overused in GIS. However, now that you've seen its utility, you might be motivated to go back and review whatever materials you used in high school/college (and probably didn't appreciate at the time). Knowing how something will be applied, and therefore being genuinely interested in it, can make it surprisingly easy to learn. –  whuber Mar 3 '11 at 4:02

Building on whuber's answer, if you wanted to implement this in Python, you'd calculate the displacement as stated, then create an output as a collection of points like so:

import arcpy
from math import radians, sin, cos

origin_x, origin_y = (400460.99, 135836.7)
distance = 800
angle = 15 # in degrees

# calculate offsets with light trig
(disp_x, disp_y) = (distance * sin(radians(angle)),\
                    distance * cos(radians(angle)))
(end_x, end_y) = (origin_x + disp_x, origin_y + disp_y)

output = "offset-line.shp"
arcpy.CreateFeatureClass_management("c:\workspace", output, "Polyline")
cur = arcpy.InsertCursor(output)
lineArray = arcpy.Array()

# start point
start = arcpy.Point()
(start.ID, start.X, start.Y) = (1, origin_x, origin_y)
lineArray.add(start)

# end point
end = arcpy.Point()
(end.ID, end.X, end.Y) = (2, end_x, end_y)
lineArray.add(end)

# write our fancy feature to the shapefile
feat = cur.newRow()
feat.shape = lineArray
cur.insertRow(feat)

# yes, this shouldn't really be necessary...
lineArray.removeAll()
del cur
share|improve this answer
    
+1 Many thanks for the Python code. –  whuber Mar 3 '11 at 3:58
    
I really appreciate this. It's great to see this in action (and save me some time along the way!) –  J Graham Mar 3 '11 at 14:47
    
Check arcpy.createFeatureclass_management since it should be case-sensitive and should read: arcpy.CreateFeatureclass_management –  Dan Patterson Mar 12 '11 at 20:11
    
Fixed the command, thanks Dan –  scw Mar 13 '11 at 23:09

protected by whuber Apr 10 at 18:34

Thank you for your interest in this question. Because it has attracted low-quality answers, posting an answer now requires 10 reputation on this site.

Would you like to answer one of these unanswered questions instead?

Not the answer you're looking for? Browse other questions tagged or ask your own question.