delapaix

Toolbox Script to Make a Line on the map

Discussion created by delapaix on Apr 26, 2011
Latest reply on Apr 27, 2011 by delapaix
Hey all-
I am trying to place the following script into a toolbox I created. The idea is that it receives user input for x and y origins (decimal degrees), distance and angle. Distance, along with origin_x and origin_y are linear measurements, angle is set as 'any value'- I'm not sure if this is correct, but the idea with angle is that it would be a number from 0 to 360 with North being 0, West being 90, etc. I also want to make sure the script references the map properly, to create a line using the input parameters.

Here is my script so far, when I run it I get the following error:
<type 'exceptions.TypeError'>: unsupported operand type(s) for /: 'unicode' and 'float'
Failed to execute (Script). I would GREATLY appreciate any help

Code is as follows:

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

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 = origin_x/(180/pi)
origin_y = origin_y/(180/pi)

# 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.CreateFeatureClassManagement("G:\Delapaix\line_connect\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()

Outcomes