How can i use a python script to join points to form polylines

1411
4
10-11-2012 03:43 PM
OLANIYANOLAKUNLE
Occasional Contributor II
How can i use a python script to join points to form polylines i.e 4 points to form 4 polylines, i believe it would be an array but i need your suggestions. Thanks
Tags (2)
0 Kudos
4 Replies
T__WayneWhitley
Frequent Contributor
I think you mean 4 points connected to make 1 line?  ...unless you didn't divulge other necessary info.
Anyway, yes, you can define an array object into which you load point objects and use that with python to define geometry...either line or polygon, depending on the geom type you are attempting to load into.  There are details well-documented online, see geometry methods, working w/ geometry and the insert cursor.  Also, there is an interesting 'Create Features From Text File' which I think is deprecated, not sure, but you should be able to find that code and gives pretty good insight on how python geom methods work.
0 Kudos
OLANIYANOLAKUNLE
Occasional Contributor II
Thanks, what i want is to be able to join point features to form a polyline 2 points each for a polyline segment.
0 Kudos
T__WayneWhitley
Frequent Contributor
I don't know your specifics such as what ArcGIS version you are using, how comfortable you are already w/ Python cursor and geometry access, or how your point data is housed.  I'll just jump in referring you to some sample code from the web help, which is a classic script adaptation using a 'coordinate text file':

Writing Geometries
http://resources.arcgis.com/en/help/main/10.1/index.html#/Writing_geometries/002z0000001v000000/

Just a couple of comments:
- The sample I refer to is the last sample on the page and begins with the comment, "Create a new line feature class using a text file of coordinates."
- In the actual code, the coords are already fed into a hard-coded python list...no text file, although it's easy to 'see' the mechanism opening/reading/loading from txt.
- 10.1 uses a new da module to enhance performance of cursors?  (I'm still at 10.0)
- If you're reading directly from points instead of the coord file, you'll need to read the geom via a search cursor, feed the points you want to form the polyline into the array object, and in turn feed the array into the insert cursor (you'll need the 'shape@' token).  Also, since not 'constructing' point geometry with the point object, I think simply 'transferring' geometry will involve directly reading/loading point geoms from the search cursor row object with shape@ token into the array.

Then, it seems you'll also need the previous web help topic:
http://resources.arcgis.com/en/help/main/10.1/index.html#/Reading_geometries/002z0000001t000000/
0 Kudos
T__WayneWhitley
Frequent Contributor
Thanks, what i want is to be able to join point features to form a polyline 2 points each for a polyline segment.


Instead of SHAPE@, may have to use the SHAPE@XY token to return the tuple to construct the point objects needed for loading the array, whichever works best....I'd like to test this later.
0 Kudos