Skip to main content
Solved

NeighborFinder : each candidate available just once

  • October 26, 2020
  • 5 replies
  • 238 views

alc33
Contributor
Forum|alt.badge.img+10
  • Contributor

Hi!

I would like to make a spatial join between two dataset. I usually use NeighborFinder but my problem is it duplicate each candidate each time a base is near. I would prefer for this time that each candidate can be used only once. So if a candidate match with a base then the candidate is not available for the others bases.

In the example, the blue feature nearest the green, take the value "10" and the other blue feature, take empty value.

 

Is it possible?

 

Thanks!

Best answer by mark2atsafe

A quick thought is to swap the base and the candidates. Then each candidate is now a base (call it a new-base) and will only match one other old-base (new-candidate) feature. The old-base then gets the ID of that new-base. It sounds odd, but I think it works.

But there's still some work to do - what if an old-base is matched by two or more new-bases? So you'd have to keep a list and maybe do some duplicate removal, but I think it will still work.

OK, that's a bit odd to get your head around (I'm confused re-reading that) but I think it might help.

View original
Did this help you find an answer to your question?

5 replies

Forum|alt.badge.img+1
  • October 27, 2020

You could put the neighborfinder in a custom transformer with a loop, with each base feature per go-around in the loop. Then, only put the unmatched candidates as the candidates-input for the next loop. However, this isn't something that will produce consistent results, as the order of the base features will determine the order in which the candidates become unavailable, thus not guaranteeing the closest feature being selected anymore. In theory, you could end up with a neighbor quite far away, although several features are closer (but have already been taken by a previous base feature).

 

If that's not an issue for you, then a loop inside the custom transformer is probably good. Please note, that you can only have one loop, so you'd have to use a single port on the return loop and have previously tagged the features as base or candidate, and test/testfilter them into two separate pipes. I think something like this, would work. If, again, you're ok with the above listed "risks".

 

You will also need some circuit breaker to limit the number of loops. Probably a good idea to count the number of bases beforehand and set the MAX_LOOP_ITERATIONS to that, so you don't run into infinite looping with only candidates remaining.Screenshot 2020-10-27 164307


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • October 27, 2020

So you have bases and candidates and want to attach some information from the base to it's nearest candidate only?

I think i would do something along the following lines

  • extract geometry of candidate to attribute
  • send base and candidates to neighbourfinder
  • build list containing candidate ids and geometry
  • sort list by distance
  • use the first candidate id in the list to become the candidate id
  • use the first geometry in the list to rebuild the geometry
  • you now have a candidate point with the base id
  • keep these along with any unmerged candidates

Capture 


ebygomm
Influencer
Forum|alt.badge.img+32
  • Influencer
  • October 27, 2020

Actually, you don't even need the geometry extractor step

Capture


mark2atsafe
Safer
Forum|alt.badge.img+44
  • Safer
  • Best Answer
  • October 30, 2020

A quick thought is to swap the base and the candidates. Then each candidate is now a base (call it a new-base) and will only match one other old-base (new-candidate) feature. The old-base then gets the ID of that new-base. It sounds odd, but I think it works.

But there's still some work to do - what if an old-base is matched by two or more new-bases? So you'd have to keep a list and maybe do some duplicate removal, but I think it will still work.

OK, that's a bit odd to get your head around (I'm confused re-reading that) but I think it might help.


alc33
Contributor
Forum|alt.badge.img+10
  • Author
  • Contributor
  • November 9, 2020

Thanks for all yours answers.

It is what I thought : not easy :)

It's a good start, I will deepen yours ideas.


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings