Skip to main content

Hi,

A simple question:

Is the index range in an FMEObjects FMEAggregate geometry parts list 0-based or 1-based ?

The documentation doesn't say anything about this either way.

It's for code in a PythonCaller.

Cheers

 

Lars I.

Hi @lifalin2016, you can check it yourself. e.g.

# PythonCaller Script Example
# Check whether part index of FMEAggregate is 0-based or 1-based.
import fme
import fmeobjects
class FeatureProcessor(object):
    def __init__(self):
        self.logger = fmeobjects.FMELogFile()
        
    def input(self,feature):
        geom = feature.getGeometry()
        if not isinstance(geom, fmeobjects.FMEAggregate):
            self.logger.logMessageString('NOT Aggregate', fmeobjects.FME_WARN)
        elif geom.getPartAt(0) != None:
            self.logger.logMessageString('0-based', fmeobjects.FME_WARN)
        elif geom.getPartAt(geom.numParts()) != None:
            self.logger.logMessageString('1-based', fmeobjects.FME_WARN)

Hi @lifalin2016, you can check it yourself. e.g.

# PythonCaller Script Example
# Check whether part index of FMEAggregate is 0-based or 1-based.
import fme
import fmeobjects
class FeatureProcessor(object):
    def __init__(self):
        self.logger = fmeobjects.FMELogFile()
        
    def input(self,feature):
        geom = feature.getGeometry()
        if not isinstance(geom, fmeobjects.FMEAggregate):
            self.logger.logMessageString('NOT Aggregate', fmeobjects.FME_WARN)
        elif geom.getPartAt(0) != None:
            self.logger.logMessageString('0-based', fmeobjects.FME_WARN)
        elif geom.getPartAt(geom.numParts()) != None:
            self.logger.logMessageString('1-based', fmeobjects.FME_WARN)
Hmm, I thought it was simpler (and better) to ask rather than make a whole program for it :-)

 

 


Indexes in Python should always be 0-based.

http://python-history.blogspot.ch/2013/10/why-python-uses-0-based-indexing.html (Written by Guido van Rossum himself)

If getPartAt() is 1-based, I'd flag it as a bug.


Hmm, I thought it was simpler (and better) to ask rather than make a whole program for it :-)

 

 

Sorry for joking. Just "0-based" was toooo simple.

 


When working with FME - including Python scripting, you can almost always suppose that list indexing is 0-based. However, also note that there are some exceptions according to external language specifications. For example, as far as I know, XQuery and R use 1-based indexing.


As far as I know all lists in FME always start with 0


Reply