Skip to main content
Solved

FMEObjects FMEAggregate index range ?

  • October 18, 2016
  • 6 replies
  • 7 views

lifalin2016
Supporter
Forum|alt.badge.img+39

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

6 replies

takashi
Celebrity
  • 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
Supporter
Forum|alt.badge.img+39
  • Author
  • Supporter
  • 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)
Hmm, I thought it was simpler (and better) to ask rather than make a whole program for it :-)

 

 


david_r
Celebrity
  • 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
Celebrity
  • October 18, 2016
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
Celebrity
  • 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+18
  • Supporter
  • October 18, 2016

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