Based on another post, I wrote a Python script that reads coordinates, creates points, and then connects them. Here is the code:

import arcpy

in_rows = arcpy.SearchCursor(r"C:\Users\cchen\Documents\temp\test.gdb\linetest")

point = arcpy.Point()
array = arcpy.Array()

featureList = []
cursor = arcpy.InsertCursor(r"C:\Users\cchen\Documents\temp\test.gdb\newlines")
feat = cursor.newRow()

for in_row in in_rows:
    # Set X and Y for start and end points
    point.X = in_row.sx
    point.Y = in_row.sy
    point.X = in_row.ex
    point.Y = in_row.ey
    # Create a Polyline object based on the array of points
    polyline = arcpy.Polyline(array)
    # Clear the array for future use
    # Append to the list of Polyline objects
    # Insert the feature
    feat.shape = polyline
del feat
del cursor

It gives me this error message: Runtime error Traceback (most recent call last): File "", line 14, in File "c:\program files (x86)\arcgis\desktop10.4\arcpy\arcpy\arcobjects_base.py", line 89, in _set return setattr(self._arc_object, attr_name, cval(val)) RuntimeError: Point: Input value is not numeric

Since the field is numeric(double), I am confused on why this does not work.

  • You need to create more than one Point (inside the loop), since this code just moves one point around and attempts to create a line with only one (repeating) vertex. You should use a DA cursor for an order of magnitude performance benefit, and the Polyline constructor shoild include a SpatialReference. – Vince May 17 '17 at 15:00
  • 1
    try converting "in_row.sx", "in_row.sy","in_row.ex","in_row.ey" to float. i.e. float(in_row.sx). That error is probably becasue the ex,ey,sx, and sy values are strings. – PMK May 17 '17 at 15:13
  • You might be able to use "XY to Line" to create your 2 point lines. – klewis May 17 '17 at 17:23

Your Answer

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

Browse other questions tagged or ask your own question.