2

Working with ArcGIS Pro 2.2, I have to create a 3D polyline from array of XYZ coordinates.

When I try this code snippet :

array = arcpy.Array([arcpy.Point(0, 0, 0),arcpy.Point(0, 100, -1000)])
polyline = arcpy.Polyline(array, has_z=True)

I get an error saying that has_z is read-only:

AttributeError: DescribeGeometry: Read-only attribute has_z

From the docs it really does not seem so.

When I try not to specify the has_z parameter:

array = arcpy.Array([arcpy.Point(0, 0, 0),arcpy.Point(0, 100, -1000)])
polyline = arcpy.Polyline(array)

I receive no errors but the Polyline defaults to hasz=False as it has to.

Doing polyline.firstPoint confirms this:

<Point (0.0, 0.0, #, #)>

Is there another legit way to do it?

It seems wrong to me that has_z parameter is read-only.

1 Answer 1

6

Ok, I made it myself. I think this is a bug probably.

Using positional parameters rather than name parameters, there's no error. This is the code I succesfully used to create a 3D polyline, hope it helps. I'll probably report this to Esri.

array = arcpy.Array([arcpy.Point(0, 0, 0),arcpy.Point(0, 100, -1000)])
polyline = arcpy.Polyline(array, None, True)
polyline.firstPoint
>>> <Point (0.0, 0.0, 0.0, #)> #CORRECT!

EDIT

Here is the link to the GeoNet thread I opened.

1
  • I agree its a bug in arcpy shipped with pro v2.50. In arcpy.arcobjects.mixins.py, GeometrySpecializationMixin.__init() first constructs an _arc_object based on positional *args only, and then if any keyword arguments (*kwargs) are present they are added as attributes, but has_z is already set!
    – intotecho
    Apr 3, 2020 at 1:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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