0

I'm trying to learn how to create a polyline object from a set of XY pairs. I need to create an empty point object and an empty array object, place the coordinates in a list, and use a for loop to iterate through the list and populate the point object. From there I'm pretty sure I can create the polyline from the array, which is the last step.

How do I go from the list of points to the point object using a for loop? I've been trying to use the .add or .append functions to no avail.

# Import module
import arcpy

# Create empty objects:
#
# Point
point = arcpy.Point()
# Array
array = arcpy.Array()

# Create a list of coordinates (X, Y)
coordinates = [[260, 320], [450, 420], [360, 680], [600, 1000], [900, 190]]

# For loop iteration through coordinates
for pair in coordinates:
  point.x = pair[0]
  point.y = pair[1]

  # What else goes here to populate the point object?

print point # to test if loop is functioning correctly

closed as unclear what you're asking by Midavalo, Dan C, Mapperz Sep 25 '16 at 22:51

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • It's wise to create and use a SpatialReference object in the Polyline constructor. – Vince Sep 25 '16 at 3:15
  • I appreciate that. This, however, is not going to be used for anything and I'm just trying to learn these concepts for a course. – Alex R Sep 25 '16 at 3:55
  • 2
    Then why ask a question that is featured prominently in the documentation at all? – Vince Sep 25 '16 at 4:15
3

There is a Code Sample in the Help that appears to do this:

Polyline example

Create a polyline feature class from scratch.

Not the answer you're looking for? Browse other questions tagged or ask your own question.