Polyline Creation in Python

881
3
02-22-2013 09:59 AM
jamesborris
New Contributor III
Hi, I have a spreadsheet with a Line ID, a Begining point X,Y,Z and End Point X,Y,Z and even a distance plus other attributes. How do I create a polyline in python from this data and keep my attributes.


Thanks
Tags (2)
0 Kudos
3 Replies
T__WayneWhitley
Frequent Contributor
Probably you could use this ready-made tool, but looks like this doesn't include Z?:

XY To Line (Data Management)
Desktop » Geoprocessing » Tool reference » Data Management toolbox
http://resources.arcgis.com/en/help/main/10.1/index.html#/XY_To_Line/0017000000tv000000/

...even has a parameter to write an ID field -- the doc suggests that is what it is for, your expressed purpose of 'joining' your other attributes to the features.  After you join, or if you use join fields, at any rate you can 'preserve' the joined output in a newly exported fc.  Or, if you want that automated further, it would be easy for you to work out with what sounds like a 3 step process.

I suppose in order to include the Z component as you mentioned, you could use the Make XY Event instead - it isn't immediately apparent but can accommodate Z, check the webhelp link below:

The syntax (Z is the last parameter):
MakeXYEventLayer_management (table, in_x_field, in_y_field, out_layer, {spatial_reference}, {in_z_field})

Make XY Event Layer (Data Management)
Desktop » Geoprocessing » Tool reference » Data Management toolbox
http://resources.arcgis.com/en/help/main/10.1/index.html#/Make_XY_Event_Layer/00170000006z000000/


Hope that helps.

-Wayne


EDIT:  I guess I didn't finish my train of thought there ------ so with the Make XY Event Layer (including your Z component), I think you could do the line processing with the Points To Line tool (then use a join process or cursor operation to get your other field vals).

Points To Line (Data Management)
Desktop » Geoprocessing » Tool reference » Data Management toolbox
http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000003s000000
0 Kudos
T__WayneWhitley
Frequent Contributor
I thought it was warranted to respond further esp since this involved an easy modification of a script I posted here:

http://forums.arcgis.com/threads/76719-finding-the-centroid-between-two-points#9


I'll attach a zip file containing a py (python script), a file gdb this script writes output to, and an xlsx which this script reads input from...pretty self-explanatory I think, esp with the notes from the other 'finding the centroid...' post, with the exception that this doesn't write multipoint output or multiple fcs and this has nothing to do with projecting data.  All it includes is XYZ input from 2 xlsx sheets plotted into a pre-made fc, FL east state plane proj with Z enabled w/ vertical datum NAVD_1988.

All that needs to be done to execute is to run the script (created w/ 10.0) from whereever it is unzipped - all 3 (xlsx, gdb, and py) must be in same relative location.  Once you see how it runs, you can modify your input sheets with your named range and run accordingly...


Enjoy,
Wayne
0 Kudos
MathewCoyle
Frequent Contributor
The built in PointsToLine tool supports Z values. You just need to create a point layer/featureclass as input.
0 Kudos