Skip to main content
Solved

FMEObjects FMEAggregate index range ?


lifalin2016
Contributor
Forum|alt.badge.img+29

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.

Best answer by takashi

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)
View original
Did this help you find an answer to your question?

6 replies

takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • Best Answer
  • October 18, 2016

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)

lifalin2016
Contributor
Forum|alt.badge.img+29
  • Author
  • Contributor
  • October 18, 2016
takashi wrote:

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 :-)

 

 


david_r
Evangelist
  • October 18, 2016

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.


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • October 18, 2016
lifalin2016 wrote:
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.

 


takashi
Contributor
Forum|alt.badge.img+19
  • Contributor
  • October 18, 2016

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.


itay
Supporter
Forum|alt.badge.img+16
  • Supporter
  • October 18, 2016

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


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