Skip to main content
Solved

feature.getGeometryType() returning MultiGeometry instead of direct type

  • October 2, 2024
  • 2 replies
  • 52 views

salah.elfarissi
Contributor
Forum|alt.badge.img+3

Hello there,
I’m looking into finding how to decide on the actual geometry type of a MultiGeometry feature using python API.

How to know which OGC type it is ? MultiPoint, MulitLineString or MultiPolygon.
I need this for reporting on ingested data types.
 

class FeatureProcessor(object):
"""Template Class Interface:
When using this class, make sure its name is set as the value of the 'Class to Process Features'
transformer parameter.
"""

def input(self, feature: fmeobjects.FMEFeature):
"""This method is called for each feature which enters the PythonCaller.
Processed input features can be emitted from this method using self.pyoutput().
If knowledge of all input features is required for processing, then input features should be
cached to a list instance variable and processed using group processing or in the close() method.
"""

feature_type_name = feature.getAttribute("fme_feature_type")

if feature_type_name not in self.feature_types:
self.feature_types[feature_type_name] = {
"count": 0,
"geometry_type": self.geom_type_mapping[feature.getGeometryType()],
}

self.feature_types[feature_type_name]["count"] += 1

feature.setAttribute(
"geometry_type", self.feature_types[feature_type_name]["geometry_type"]
)

self.pyoutput(feature)



Thank you

Best answer by bwn

Suggest use in combination with FMEFeature.numParts()

https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_feature/fmeobjects.FMEFeature.numParts.html

Eg, if feature.numParts(0,0)>1 then is a multi.

 

A variation is to just use the string prefix output from FMEFeature.exportGeometryToOGCWKT()

https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_feature/fmeobjects.FMEFeature.exportGeometryToOGCWKT.html

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

2 replies

bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • 562 replies
  • Best Answer
  • October 2, 2024

Suggest use in combination with FMEFeature.numParts()

https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_feature/fmeobjects.FMEFeature.numParts.html

Eg, if feature.numParts(0,0)>1 then is a multi.

 

A variation is to just use the string prefix output from FMEFeature.exportGeometryToOGCWKT()

https://docs.safe.com/fme/html/fmepython/api/fmeobjects/_feature/fmeobjects.FMEFeature.exportGeometryToOGCWKT.html


salah.elfarissi
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 8 replies
  • October 16, 2024

Thank you
This worked for me

 

if feature_type_name not in self.feature_types:
geom_type = (
f"Multi{self.geom_type_mapping[feature.getGeometryType()]}"
if feature.numParts(False, False) > 1
else self.geom_type_mapping[feature.getGeometryType()]
)