Hello!
I need to randomly select 7 grids from the grid net including condition that selected grids cannot be self-intersecting and cannot overlap each other. See image below.
Â
How to approach it in the most efficient way?
Hello!
I need to randomly select 7 grids from the grid net including condition that selected grids cannot be self-intersecting and cannot overlap each other. See image below.
Â
How to approach it in the most efficient way?
Use a Sampler to randomly grab one tile, then a SpatialFilter to select all tiles not touching that randomly selected tile. Then use that result set as the input for the next iteration, and so on.
I've done 2 iterations here, you can simply copy & paste the rest, or try and do it through looping in a custom transformer.
Looping transformers in FME are fairly horrible to work with when you've got blocking transformers, but it can be done. This is more or less the same workflow as @redgeographics within the transformer but just handles the looping
Â
Â
And because looping blocking transformers are so horrible to work with an alternative solution using a spatial relator and some python
Â
import fme
import fmeobjects
import random
Â
class chooseSquares(object):
    def __init__(self):
        #create blank list
        self.mylist=t]
    def input(self,feature):
        #build list containing feature, id and relationships
        id = feature.getAttribute('_count')
        touches = feature.getAttribute('_relationships{}._count')
        self.mylist.append((feature,id,touches))
    def close(self):    Â
        for x in range(0,7):
            #shuffle list
            random.shuffle(self.mylist)
            #choose grid from first feature inlist
            newfeature = self.mylist 0]Â0]
            #get features that interact
            exclude = self.mylistr0]Â2]
            #remove from list any features that intersect chosen gridsquare
            self.mylist = #(f,i,r) for f,i,r in self.mylist if str(i) not in exclude]
            #outputchosengridsquare
            self.pyoutput(newfeature)
Â
Â
Thanks for providing all the suggestions! it worked smoothly!
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.