Hi @lavairye
The CityGML surfaces will be converted to triangular meshes by the OBJ writer, but in order to count the resulting vertices, we can do the mesh conversion before writing, with the Triangulator transformer.
After the Triangulator, add a PythonCaller with the following code:
import fme
import fmeobjects
def meshStats(feature):
# extract geometry from feature
geom = feature.getGeometry()
# get number of vertices in Mesh
numVerts = geom.numVertices()
# set number of vertices on feature as attribute
feature.setAttribute("_numVertices", numVerts)
# convert Mesh to MultiSurface
msurf = geom.getAsMultiSurface()
# get number of parts in MultiSurface
numTriangles = msurf.numParts()
# set number of parts on feature as attribute
feature.setAttribute("_numTriangles", numTriangles)
This will create two new attributes on the feature:
- _numVertices will contain the number of vertices in the Mesh
- _numTriangles will contain the number of triangles in the Mesh
Although the geometry in the Python is converted from a Mesh to a MultiSurface to get the number of triangles, that geometry is not written back to the feature, so the feature geometry will be unchanged.
Hi @lavairye
The CityGML surfaces will be converted to triangular meshes by the OBJ writer, but in order to count the resulting vertices, we can do the mesh conversion before writing, with the Triangulator transformer.
After the Triangulator, add a PythonCaller with the following code:
import fme
import fmeobjects
def meshStats(feature):
# extract geometry from feature
geom = feature.getGeometry()
# get number of vertices in Mesh
numVerts = geom.numVertices()
# set number of vertices on feature as attribute
feature.setAttribute("_numVertices", numVerts)
# convert Mesh to MultiSurface
msurf = geom.getAsMultiSurface()
# get number of parts in MultiSurface
numTriangles = msurf.numParts()
# set number of parts on feature as attribute
feature.setAttribute("_numTriangles", numTriangles)
This will create two new attributes on the feature:
- _numVertices will contain the number of vertices in the Mesh
- _numTriangles will contain the number of triangles in the Mesh
Although the geometry in the Python is converted from a Mesh to a MultiSurface to get the number of triangles, that geometry is not written back to the feature, so the feature geometry will be unchanged.
It seems that the FMEMesh.numParts method (inherited from FMESimpleSurface class) can also be used here.
def meshStats(feature):
# extract geometry from feature
geom = feature.getGeometry()
# get number of vertices and parts in Mesh
numVerts = geom.numVertices()
numTriangles = geom.numParts()
# set number of vertices and parts on feature as attributes
feature.setAttribute("_numVertices", numVerts)
feature.setAttribute("_numTriangles", numTriangles)
Thanks a lot. All my workflow works fine now. I shall use more python in the future!