Skip to main content
Question

change vertex z value through python caller

  • February 10, 2014
  • 3 replies
  • 24 views

venu
Contributor
Forum|alt.badge.img+5
  • Contributor
Hi,

 

 

I have a polygon in that i need to change z value for 3 and 4 vertex.

 

 

Please can any one help me how to do in python

 

 

Thanks in advance

3 replies

david_r
Celebrity
  • February 10, 2014
Hi,

 

 

have a look at the Python API documentation, it is installed with FME under <FME>/fmeobjects/python/apidoc/index.html

 

 

You can do something like:

 

 

coords = feature.getAllCoordinates()

 

if feature.hasGeometry() and len(coords) >= 4 and feature.getGeometry().is3D():

 

    coords[2] = (coords[2][0], coords[2][1], new_z_value1)

 

    coords[3] = (coords[3][0], coords[3][1], new_z_value2)

 

    feature.resetCoords()

 

    feature.addCoordinates(coords)

 

 

Be careful if you have multipart and/or aggregate geometries, though.

 

 

David

venu
Contributor
Forum|alt.badge.img+5
  • Author
  • Contributor
  • February 12, 2014
Please can Explain how to compare the vertex z value.I don't know python codes, but i can understand if you explain.

takashi
Influencer
  • February 12, 2014
Hi Venu,

 

 

Assume that dimension of input polygon was 3D and you have retrieved coordinates list with this expression as David suggested.

 

-----

 

coords = feature.getAllCoordinates()

 

-----

 

"coords[i]" (i is 0-based index of vertices) represents a tuple which contains (x, y, z) of vertex(i).

 

Therefore "coords[i][2]" represents z value of vertex(i), you can compare it to other value in the script.

 

Just be aware that element index of Python list and tuple is 0-based. e.g. index of the 3rd element of list or tuple is 2 (not 3).

 

 

Takashi

Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings