# ArcGIS PRO: ArcPy: Creating a 3D polyline, visible in Map_3D?

1522
7
08-12-2016 08:21 AM
Regular Contributor

Hi,

I am using this code to create a polylineZM in PRO, but I cannot see it in Map_3D (3d viewport).

I do have x,y,z coordinates..

Could somebody help me with this?

Any input welcome!

Matt

 def write_polyLine(data,outfile):  array = arcpy.Array()  point = arcpy.Point()  features=[]  for feature in data:  for part in feature:  point.X=part[0]  point.Y=part[1]  point.Z=part[2]  array.add(point)  MP=arcpy.Polyline(array,None,True,True)  array.removeAll()  features.append(MP)  arcpy.CopyFeatures_management(features, outfile, "", "0", "0", "0")
7 Replies
Regular Contributor

ps.

this is how I create the target polygon FC first:

arcpy.CreateFeatureclass_management(ws, 'diag', 'POLYGON', has_z = 'ENABLED', spatial_reference = spatialRef)

I noticed the spatial reference sometimes gets created correctly, sometimes not. pretty erratic though.

MVP Esteemed Contributor

Xander Bakker​ has a series of blog posts on creating 3D features which you may be interested.  There are code examples, see Creating a 3D tree with Arcpy for 3D Analysis the bottom example and refer to his other posts for more code samples and examples

Regular Contributor

Hi ..

thanks, this did help.

I came up with this method that works now:

def write_one_line_feature(linePointList, fc, spatialRef):

pnt1 = arcpy.Point(linePointList[0][0], linePointList[0][1], linePointList[0][2])

pnt2 = arcpy.Point(linePointList[1][0], linePointList[1][1], linePointList[1][2])

line = arcpy.Polyline(arcpy.Array([pnt1, pnt2]), spatialRef, True, False)

arcpy.CopyFeatures_management(line, fc)

[[

I'm not perfectly sure what it was, but I think I made 2 errors:

1] I think the FC I created was polygon, not polyline

2] in arcpy.Polyline(), I did not define the spatial reference

either or .. not sure.

]]

huge thanks, also to Xander Bakker

Esri Esteemed Contributor

You are very welcome, although I can't remember doing anything...

What I am curious about is the data format of the linePointList. You use it as a list of lists (each element in linePointList is a list that consists of a list with at least X, Y, and Z elements). Is this always a straight line (so two points)?. And do you always want to write each line to a different featureclass?

Regular Contributor

hi .. basically yes. this was just a quick test method .. I will probably adapt it again.

in your experience, writing n lines individually to an FC compared to sending a list full and write once .. is there a big performance difference?

Esri Esteemed Contributor

Probably the best way is using an arcpy.da.InsertCursor. If you have a list with features and copy them to a featureclass, a single invalid feature will cause the entire process to fail. Using an Insert cursor provides mores options to avoid that. Also the insert cursor will allow you to store attributes. This is not possible with the Copy Feature tool.

Regular Contributor

sounds good, I may actually also need to add some attrs in the workflow. Thanks!!