11

I'm trying to create a line feature from a single point, using a set distance and angle using ArcGIS and Python (ArcPy).

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.

My data are projected in Maryland State Plane South - Meters.

13

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).

  • I am a bit confused. if sin(theta aka 15 degrees) = y/r and y = r*sin(15 degrees) shouldnt the formulas for the x and y displacements be switched? – ziggy Dec 13 '16 at 16:44
  • @Ziggy Your formulas are not the correct ones for an angle that is measured east of north. You are trying to apply formulas for an angle north of east. – whuber Dec 13 '16 at 17:34
  • how were you able to discern that the location and angle are east of north? this might be outside the scope of these comments but do you have any resource recommendations of where to learn and apply basic trig concepts to GIS questions like this one? – ziggy Dec 13 '16 at 18:13
  • 1
    @Ziggy Conventionally, geographers measure angles in degrees east of north, but there are many other ways. That is why I took care to establish what I meant by the "angle" and how it is measured. People using other conventions need only make the usual adjustments to apply this solution. I'm no expert on resources for learning trig: I learned it long ago from a high school algebra text, which was more than adequate to address any GIS questions. You don't need to know much trig anyway. – whuber Dec 13 '16 at 18:49
13

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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