Solved

neighbour finder finding the same closest candidate, which is already allotted

  • 10 September 2021
  • 8 replies
  • 83 views

Badge +3

Hi FME colleagues,

Neighbor finder transformer finds the nearest neighbor and allotting the same candidate to multiple bases. In my requirement, I need to pair the points from two set of data, but one base one candidate, that means one candidate should not be paired with more than one base.

for ex :

 

I have two sets of data, one is Blue and the other is REd. Now, first, the blue base comes and finding its closest candidate (good). Now the second base comes in and finds the same candidate which is already paired with the first blue base. this should not happen in my case, if it's already paired(i mean the closest candidate to some other base) then remove it from the candidate set. the candidate set should go smaller and smaller through the fme process.

now what our neighbor finder does is matching with all bases to first(1) candidates. many to one.

 

safe1can we achieve this using any transformer? or any workaround within FME using python caller?

icon

Best answer by connecter 11 September 2021, 11:28

View original

8 replies

Badge +4

Hi @f.kemminje​ ,

you can try something from this post to solve your problem:

https://community.safe.com/s/question/0D54Q00008aKQnaSAG/loop-through-featurejoiner

VariableRetriever -->Tester--> VariableSetter

Badge +22

Have you looked at the following related questions?

 

https://community.safe.com/s/question/0D54Q00008DpOYsSAN/neighborfinder-each-candidate-available-just-once

 

https://community.safe.com/s/question/0D54Q000080hTpkSAE/neighborfinder-and-excluding-candidates-after-matched

 

I think you would have to use the NeighborFinder in a loop which is tricky but not impossible.

https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Workbench/Workbench/looping_with_blocking_transformer.htm

Badge +3

safe3@jdh​ ,@connecter​ . Sorry, my question was not clear I think. Please refer to my image. links above are not excluding candidates if it is already matched. Also attached are my source MicroStation dgn file and fmw file. @david_r​ ,@mark2atsafe​ ,@Takashi Iijima​  Can you pls help me

Badge +3

As soon as "A" is matched with "1". then 1 should be excluded from the set. when b comes in, it should search only with 2 and 3, and now B will be matched to a closest candidate"2". and "2" excluded. and C will come and only one left, that is "3"

Badge +4

Hello again @f.kemminje​ ,

here is a workflow I build for you:

Point_NeighborfinderThe result table:

Point_Neighborfinder_2

Badge +3

safe4I used Python caller for this and achieved the target.

I used list exploder after neighbor finder, then stored the feature and its attributes to list @ pythoncaller's input method. 

And in the close() method, 

created one new list , and appended only valid feature and its attributes. No duplicate base or candidates.(ID not in List then only append)

I got the Result what I want.

Thanks For Everyone, who Answered my Q.

import fme
import fmeobjects
 
 
class FeatureProcessor(object):
    def __init__(self):
        self.featureList = []
        self.mylist = []
        self.mylist2 = []
 
    def input(self,feature):
        self.featureList.append(feature)
        self.mylist.append(str(feature.getAttribute('tid')))
        self.mylist2.append(str(feature.getAttribute('cid')))
        #self.mylist2.append(feature.getAttribute('_creation_instance'))
        
 
    def close(self):
        outlist1=[]
        outlist2=[]
        mylist1=self.mylist
        mylist2=self.mylist2
        i = 0
        while i < len(mylist1):
            tid=(mylist1[i])
            cid=(mylist2[i])
            if tid not in outlist1 and cid not in outlist2:
                outlist1.append(str(tid))
                outlist2.append(str(cid))
                print(tid)
                print(cid)
                self.featureList[i].setAttribute('tid',tid)
                self.featureList[i].setAttribute('cid',cid)
                self.pyoutput(self.featureList[i])
            i = i + 1
 

 

Badge +3

Hello again @f.kemminje​ ,

here is a workflow I build for you:

Point_NeighborfinderThe result table:

Point_Neighborfinder_2

Thanks ! @connecter​ 

Badge +3

Thanks ! @connecter​ 

Thanks to All

Reply