Home - General / All posts - Area minimum distance to point in m.
 cassini95 post(s) #11-Sep-21 20:49 Hello everybody, I need to extract the smallest distance from project areas (layer1) to grid connection points (layers2) I would be grateful if you could let me know if anyone has worked on the subject and share their experience. The goal is to add a Distance column in meter to Zones layer. I am attaching a test file to better understand my research.
 Dimitri6,713 post(s) #12-Sep-21 05:47 Sounds like you need to do a cross join between the two layers, and then in each row use GeomDistance to get the distance between the two objects in that row. GeomDistance always reports the minimum distance between two objects (such as areas). A cross join is just a permutation of possible combinations, so if you have 5 objects in one table and 4 objects in the other table you get 20 rows.
 adamw9,738 post(s) #12-Sep-21 10:53 It seems you wanted to attach the test file but forgot to do this. :-)The task is relatively straightforward, we can use a cross join like Dimitri says and find a global minimum for all possible pairs, or we can optimize a bit with, say, merging connection points into a single geom, using GeomDistance to find the distance to that geom from each area, then taking the minimum of the resulting values, etc.
 cassini95 post(s) #13-Sep-21 21:56 Hello Dimitri, Adam,thanks to you twoI think I understand the idea.I imagine that it is achievable with M9 (I have since received it)Here is the file that I forgot to attach (and which is under M8), but i think but I think you understoodAttachments: Test.map
 adamw9,738 post(s) #14-Sep-21 16:35 Thanks. The layers use the exact same coordinate system. Great, this allows us to not write the code that would convert between different coordinate systems, making queries shorter.Here's what you can try:--SQL9VALUE @allpoints GEOM = (SELECT GeomMergePoints([geom (i)]) FROM [Postes]);SELECT mfd_id, GeomDistance([geom (i)], @allpoints, 0) FROM [Zones];-- SELECT Min(GeomDistance([geom (i)], @allpoints, 0)) FROM [Zones];-- returns: 0The first statement (VALUE) merges all points together into a value named @allpoints.The second statement (SELECT) shows the distance from each area to that geom (so, the minimum distance from each area in 'Zones' to the points in 'Postes').The third statement (SELECT with Min) shows the minimum of the distances shown by the second query, but it currently returns 0 because some points landed in some areas, this is why I am leaving uncommented the second query - its results are more interesting.