# Sort lists by proximity

**URL:** <https://forum.dynamobim.com/t/sort-lists-by-proximity/23031>\
**Category:** Revit\
**Created:** [June 22, 2018, 1:36pm UTC](https://forum.dynamobim.com/t/sort-lists-by-proximity/23031 "2018-06-22T13:36:29Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![BIMadmin](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@BIMadmin](https://forum.dynamobim.com/u/BIMadmin)\
**Post date:** [June 22, 2018, 1:36pm UTC](https://forum.dynamobim.com/t/sort-lists-by-proximity/23031/1 "2018-06-22T13:36:29Z")

</div>

Hello community,

We need to do an exercise and I wonder if you have come across this before:

We have two lists of points:

List A has X,Y and Z Coordinates  
List B has X,Y Coordinates

Points in List B are close to points on A, let’s say in radius\<500mm

The goal is to copy the Z Coordinates from List A into List B, but we need to put both lists in the same order based on their X and Y coordinates proximity.

Our first try was to generate a mesh from list A and create lines with start points from list B and the distance from 0 to the mesh will give us the Z coordinates of these points, but when I try geometry.intersect Dynamo crashes.

Image attached of our current approach.

 ![c1](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/d/b/db7bb53230b486de0af3315e372ecd36fed6b89a.JPG)

Any other approach???

Many thanks!!!

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [June 22, 2018, 1:51pm UTC](https://forum.dynamobim.com/t/sort-lists-by-proximity/23031/2 "2018-06-22T13:51:09Z")

</div>

Can you explain your overall goal here? How do you know which Z coordinate to use? Is it based off the closest point in any direction? Closest point in the Z direction? Could you use ProjectInputOnto? How are the points being sorted? X first then Y? We need more information to give you a solid answer.

---

<div class="post-metadata">

**Author:** ![BIMadmin](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@BIMadmin](https://forum.dynamobim.com/u/BIMadmin)\
**Post date:** [June 22, 2018, 2:16pm UTC](https://forum.dynamobim.com/t/sort-lists-by-proximity/23031/3 "2018-06-22T14:16:30Z")

</div>

Hi Nick,  
I think I got what I needed from this post:

> [@Closest point for given point sorting loop](https://forum.dynamobim.com/t/closest-point-for-given-point-sorting-loop/12600):
>
> Hi dynamo users. I stucked with idea of loop that can sort the points by distance but not from just one point: -\>Starting with starting point and point collection,-\> then find closest point to the starting then take the found one and repeat the search of closest one. Then sort it in found order. I tried with loop while node after I created custom node that giving the closest point and rest of collection. Ty for help!.

I need to copy z coordinates from a list to another list based on the shortest distance.

 ![c2](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/8/9/89d39a8eb1b86e52dd03fc3e20880abf6d3412f8.JPG)

---

<div class="post-metadata">

**Author:** ![BIMadmin](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@BIMadmin](https://forum.dynamobim.com/u/BIMadmin)\
**Post date:** [June 22, 2018, 4:07pm UTC](https://forum.dynamobim.com/t/sort-lists-by-proximity/23031/4 "2018-06-22T16:07:14Z")

</div>

The logic seems to be right but the outcome isn’t.

 ![c3](https://us1.discourse-cdn.com/flex022/uploads/dynamobim/original/3X/b/a/bac7420ce841fcd47f67843132131b5f2682654e.JPG)  
The node _Geometry.Distance to_ calculate the distance between all the points  
_List.MinimumItem_ give me the smallest distance per sublist  
_Index_ of give me the index of the shortest distance within the sublist  
This way I can feed the second list with the right values from the first list  
Everything seems to be working fine but the output is not!!!  
I think the problem is on the calculation of distances, anyone know how this node works???

---

<div class="post-metadata">

**Author:** ![BIMadmin](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@BIMadmin](https://forum.dynamobim.com/u/BIMadmin)\
**Post date:** [June 22, 2018, 4:13pm UTC](https://forum.dynamobim.com/t/sort-lists-by-proximity/23031/5 "2018-06-22T16:13:09Z")

</div>

Attached Graph and data sets.[Home.dyn](https://forum.dynamobim.com/uploads/short-url/jW9LjmYO7oKJR5JhANHhW5lNaSJ.dyn) (20.4 KB)  
[points data\_.xls](https://forum.dynamobim.com/uploads/short-url/msTVDBJTuNrHoQVwkjh1MuW0Q2B.xls) (84 KB)  
[text data.xls](https://forum.dynamobim.com/uploads/short-url/nv3GEhgx38ZmOE1D8WPM0TGF0ig.xls) (169.5 KB)

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [June 22, 2018, 4:18pm UTC](https://forum.dynamobim.com/t/sort-lists-by-proximity/23031/6 "2018-06-22T16:18:07Z")

</div>

I think you need to switch your Geometry.DistanceTo inputs. You’re finding the shortest distance in the bottom list then pulling the item from the first list.

---

<div class="post-metadata">

**Author:** ![BIMadmin](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@BIMadmin](https://forum.dynamobim.com/u/BIMadmin)\
**Post date:** [June 22, 2018, 4:20pm UTC](https://forum.dynamobim.com/t/sort-lists-by-proximity/23031/7 "2018-06-22T16:20:04Z")

</div>

Hello Nick,

Thanks for your prompt answer,

Can you explain me a bit what you mean please?

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [June 22, 2018, 4:26pm UTC](https://forum.dynamobim.com/t/sort-lists-by-proximity/23031/8 "2018-06-22T16:26:36Z")

</div>

The index you’re getting is the index for the closest item in the bottom list. But you’re using it to select the item in the top list. You need to flip the inputs so that you’re getting the closest item in the top list and therefore pulling the correct item from that same list.

---

<div class="post-metadata">

**Author:** ![BIMadmin](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@BIMadmin](https://forum.dynamobim.com/u/BIMadmin)\
**Post date:** [June 22, 2018, 4:33pm UTC](https://forum.dynamobim.com/t/sort-lists-by-proximity/23031/9 "2018-06-22T16:33:48Z")

</div>

you mean to swap the inputs in the Geometry.DistanceTo?  
Geom to other  
other to geom???

---

<div class="post-metadata">

**Author:** ![Nick\_Boyts](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.dynamobim.com/nick_boyts/32/76313_2.png) [@Nick\_Boyts](https://forum.dynamobim.com/u/Nick_Boyts)\
**Post date:** [June 22, 2018, 4:34pm UTC](https://forum.dynamobim.com/t/sort-lists-by-proximity/23031/10 "2018-06-22T16:34:59Z")

</div>

Correct.

---

<div class="post-metadata">

**Author:** ![BIMadmin](https://avatars.discourse-cdn.com/v4/letter/b/958977/32.png) [@BIMadmin](https://forum.dynamobim.com/u/BIMadmin)\
**Post date:** [June 22, 2018, 4:40pm UTC](https://forum.dynamobim.com/t/sort-lists-by-proximity/23031/11 "2018-06-22T16:40:35Z")

</div>

BINGOOOOOOO!!!  
Thanks soooooo muuuuuuch!!!
