Question

Help with attributum setting

  • 11 April 2019
  • 2 replies
  • 0 views

Hello,

I have an external code in PythonCaller that generates a segment_id for each feature. and I would like to understand what it is doing exactly and what does the  if (feat_i*self.sampinv) % self.count==0.0 expression mean. 

It looks like

def close(self):     
        group=0
        for feat_i in range(len(self.feat_list)):
            if (feat_i*self.sampinv) % self.count==0.0:
                group+=1
            self.feat_list[feat_i].setAttribute('segment_id',group)
            self.pyoutput(self.feat_list[feat_i])

2 replies

Userlevel 4

Since only a part of the code has been posted it is difficult to say for sure, but my guess is

  • The number of features (self.count) is split into the number of groups defined in self.sampinv
  • Each feature gets a new attribute segment_id which contains the group number, starting with 1

For example, if you have 12 features and self.sampinv = 3, you will end up with 3 groups of 4 features each. The resulting first 4 features will have segment_id = 1, the next 4 features will have segment_id = 2, and the last 4 features will have segment_id = 3.

Does that match what you're observing?

Thanks, yes I got the point :)

Reply