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.

I have some code others have provided, which I modified in order to run a Python script in a toolbox in ArcMap which accepts user input for a starting point, distance, and angle to create a shapefile for a line. The script works OK except the starting point (origin_x, origin_y), which I am entering in decimal degrees, is always wrong when I place the shapefile in a map dataframe. How can I correct this code so that the math can work correctly to produce the right starting point location? It seems converting origin_x and origin_y into radians is the wrong way to go about it, but I'm not sure...

import arcpy
from arcpy import env
from math import radians, sin, cos, pi

#Set workspace
env.workspace = "G:\\Delapaix\\Geog_586_FinalProject\\line_connect"

origin_x   = arcpy.GetParameterAsText(0)
origin_y  = arcpy.GetParameterAsText(1)
distance  = arcpy.GetParameterAsText(2)
angle  = arcpy.GetParameterAsText(3)

# convert latitude and longitude to radians 
origin_x = float(origin_x)/(180/pi)
origin_y = float(origin_y)/(180/pi)

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

output = "offsetLine.shp"
arcpy.CreateFeatureclass_management("G:\\Delapaix\\Geog_586_FinalProject\\line_connect",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 feature to the shapefile
feat = cur.newRow()
feat.shape = lineArray
cur.insertRow(feat)

# code for buffering the line and including features in buffer zone would go here

# yes, this shouldn't really be necessary
lineArray.removeAll()
share|improve this question
    
Are you expecting the start points to be in projected coordinates? If so, then you need to create the file, project it, then use an update cursor to add the other points. –  Dan Patterson Jun 7 '11 at 17:05
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.