Skip to main content
Solved

feature.getGeometryType() returning MultiGeometry instead of direct type


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

View original
Did this help you find an answer to your question?

2 replies

bwn
Evangelist
Forum|alt.badge.img+26
  • Evangelist
  • 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

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()]
    )

 


Reply


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