1

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
 array.add(point)
 point.X = in_row.ex
 point.Y = in_row.ey
 array.add(point) 
 # Create a Polyline object based on the array of points
 polyline = arcpy.Polyline(array)
 # Clear the array for future use
 array.removeAll()
 # Append to the list of Polyline objects
 featureList.append(polyline)
 # Insert the feature
 feat.shape = polyline
 cursor.insertRow(feat)
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.

Vince
20.5k16 gold badges49 silver badges65 bronze badges
asked May 17, 2017 at 14:48
3
  • 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. Commented May 17, 2017 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. Commented May 17, 2017 at 15:13
  • You might be able to use "XY to Line" to create your 2 point lines. Commented May 17, 2017 at 17:23

1 Answer 1

0

search cursor is declaring all fields by default so in_row is a list of field values. You would need to access the shape by index so I would expect an error, but that the attribute .sx exist is a little confusing, but can modify.

in_rows = arcpy.SearchCursor(r"C:\Users\cchen\Documents\temp\test.gdb\linetest",
 ["SHAPE@XY"])
for in_row in in_rows:
 x, y = in_row[0]
 print("{}, {}".format(x, y))

Then you would need to get at least two unique points into the array to successfully create a polyline.

answered Nov 21, 2024 at 4:54

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.