havatv / qgisnnjoinplugin

GNU General Public License v2.0
7 stars 8 forks source link

Cardinality Question: What record does NN Join choose when there are two points inside a polygon? #27

Open taraharder opened 4 years ago

taraharder commented 4 years ago

Does anyone know what record will be chosen when using NN Join in QGIS when joining a polygon layer to a point layer with one-to-many cardinality?

I am joining a point layer to a polygon layer. The points layer are well test results with dates and concentration readings. I only want the oldest test result to be joined to the polygon it falls inside of but I'm not sure how NN Join selects which point will be joined to the polygon. Please help if you know!

Capture (Which of the two points will be joined!?)

havatv commented 4 years ago

Hi, @taraharder! When there are many points that have the distance 0 from the polygon (being inside it), NNJoin chooses the first one it encounters. So this approach of joining the polygon layer to the point layer is probably not very useful for your application. You could instead consider to do it the other way around.

  1. Make sure that your polygons have a unique id.
  2. Do NNJoin with the point layer as input layer and the polygon layer as join layer. In the output layer you will, for each well have information about the polygon in which it resides.
  3. Use that information to do whatever you would like to do by using the polygon id attribute/field that the points have received from the polygon layer in the join to determine which polygon the point is placed in (and perhaps group the points based on the same attribute).
taraharder commented 4 years ago

Thanks @havatv! That is what I ended up doing.