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?
Best answer by ebygomm
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=[]
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.mylist[0][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)
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.