Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

Geometry object stuff

$
0
0
I have used this stuff before but this afternoon (because of my fading brain) I got stuck again.
This page says that using point geometry objects, you can access the X,Y,Z like this:

http://resources.arcgis.com/en/help/...0000001t000000

Code:

for row in arcpy.da.SearchCursor(infc, ["OID@", "SHAPE@"]):
    # Print the current multipoint's ID
    #
    print("Feature {0}:".format(row[0]))

    # For each point in the multipoint feature,
    #  print the x,y coordinates
    for pnt in row[1]:
        print("{0}, {1}".format(pnt.X, pnt.Y))

If you do this, all you get is this :
Code:

>>> geom1
<PointGeometry object at 0x128e50d0[0x128e51c0]>
>>> geom1.type
u'point'
>>> geom1.X

Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    geom1.X
AttributeError: 'PointGeometry' object has no attribute 'X'
>>>

This had me stuck for about an hour until, from somewhere in my aging cortex, I remembered you had to do this :

Code:

>>> geom1.type
u'point'
>>> geom1.getPart().X
37.85577369550394
>>> geom1.getPart().Y
-5.721226269422574
>>> geom1.getPart().Z
633.8880000000063
>>>

Oh, and if you try to iterate over a geometry object like in the help, that fails as well.

Code:

>>> for p in geom1:
        print p.getPart().X

       

Traceback (most recent call last):
  File "<pyshell#10>", line 1, in <module>
    for p in geom1:
TypeError: 'PointGeometry' object is not iterable
>>>

Dear esri, when is either the attributes of the geometry going to get fixed, or the help files when you want to actually do this stuff?

Thanks,
Neil

Viewing all articles
Browse latest Browse all 2485

Latest Images

Trending Articles



Latest Images