I am trying to create a polyline geometry from point coordinates using Arcpy (ArcGIS 10.1). I can do that if the length of lines are not short (>100 ft). However, my script creates an empt geometry when I try to create a line of length ~10s of feet. E.g, creating a line for the start points (32.297159, -90.211997) and end point (32.297179, -90.211997) does not work. I wonder if its a decimal problem or some kind of geometry creation issue. I would appreciate any help!
Thanks,
sachi
Sounds like you are working with decimal degree data and trying to produce a polyline in meters (or feet). I would suggest working with projected coordinates. I would also suggest including your script here so it can be examined for potential script errors
Hi Dan,
Thanks for your reply. Please see part of my script below that intends to create the line layer.
#-----------------------------
import arcpy
arcpy.env.overwriteOutput = True
output = "C:\\temp\\line.shp"
createLine = arcpy.CreateFeatureclass_management("in_memory", "createLine", "POLYLINE", "", "DISABLED", "DISABLED", polygon)
cursor = arcpy.da.InsertCursor(createLine, ["SHAPE@"])
#Read the coordinates
x1 = -90.211997
y1 = 32.297159
x2 = -90.211997
y2 = 32.297179
array = arcpy.Array([arcpy.Point(x1, y1), arcpy.Point(x2, y2)])
array_line = arcpy.Polyline(array)
cursor.insertRow((array_line,))
del cursor
arcpy.CopyFeatures_management(createLine, output)
arcpy.Delete_management(createLine)
#-------------------------
I have some vague recollection that the spatial reference had to be set otherwise you got errors in geometry creation. I have included a small demo script...you can add to the list of values to calculate for...values are calculated from the origin...just copy and paste the code into a script window...tab spacing is 2 spaces
'''
import math
import arcpy
pnt = arcpy.Point()
polylines = []
vals = [0.001, 0.1, 10.0, math.sqrt(2.0), 2.0]
for a_val in vals:
polylines.append( [[0.0,0.0],[a_val,0.0]] ) #positive out
polylines.append( [[0.0,0.0],[-a_val,0.0]] ) #negative out
polylines.append( [[a_val,0.0],[0.0,0.0]] ) #positive in
polylines.append( [[-a_val,0.0],[0.0,0.0]] ) #negative in
array = arcpy.Array()
polys = []
for i in range(len(polylines)):
a_poly = polylines
print "\n", "Coordinates: ", a_poly
for pair in a_poly:
pnt.X = pair[0]
pnt.Y = pair[1]
array.add(pnt)
#print " X: %20.16f Y: %20.16f" % (pnt.X, pnt.Y)
'''
add an empty spatial reference when creating the
geometry to go from low to high precision
'''
poly = arcpy.Polyline(array,arcpy.SpatialReference())
cal_leng = poly.length
centroidX = poly.centroid.X
centroidY = poly.centroid.Y
print "Polyline properties:"
print " length: %20.16f" % (cal_leng)
print " centroid (x,y: %20.16f, %10.16f" % (centroidX, centroidY)
array.removeAll()
polys.append(poly) #for further use