# Sort points

**URL:** <https://discourse.mcneel.com/t/sort-points/108994>\
**Category:** Grasshopper\
**Created:** [September 21, 2020, 6:57am UTC](https://discourse.mcneel.com/t/sort-points/108994 "2020-09-21T06:57:19Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![cristian.gutierrez.v](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/cristian.gutierrez.v/32/473651_2.png) [@cristian.gutierrez.v](https://discourse.mcneel.com/u/cristian.gutierrez.v)\
**Post date:** [September 21, 2020, 6:57am UTC](https://discourse.mcneel.com/t/sort-points/108994/1 "2020-09-21T06:57:19Z")

</div>

Hi.

I have two sets of points. The second one is the result of a number of operations, but the order gets wrong.  
How do I give the original order back to the second set?

Thank you 🙂

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/7/1/712827bde387d82b70459bb141e78adae6d6c546.png)

[POINT ORDER.gh](https://discourse.mcneel.com/uploads/short-url/r25Jtihs0AqhS2PuoC25nTuwsDr.gh) (5.0 KB)

---

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [September 21, 2020, 7:12am UTC](https://discourse.mcneel.com/t/sort-points/108994/2 "2020-09-21T07:12:08Z")

</div>

This is a way, maybe be the solution is more simple in your original script

[POINT ORDER\_r.gh](https://discourse.mcneel.com/uploads/short-url/oE5OSSJ2zgdnYScPCTk7jZ8etbk.gh) (13.7 KB)

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/1/0/10627eb9b8d6c70d883d11d531f060bac7ef6a0e.png)

Another way

 ![image](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/d/1/d1616854e0c442b7f23342d25a476414317d51f6.png)

---

<div class="post-metadata">

**Author:** ![cristian.gutierrez.v](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/cristian.gutierrez.v/32/473651_2.png) [@cristian.gutierrez.v](https://discourse.mcneel.com/u/cristian.gutierrez.v)\
**Post date:** [September 21, 2020, 7:45am UTC](https://discourse.mcneel.com/t/sort-points/108994/3 "2020-09-21T07:45:28Z")

</div>

Brilliant!

Why do you use “Orient” component in both definitions? I want to understand

Thanks!!!

---

<div class="post-metadata">

**Author:** ![HS\_Kim](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/hs_kim/32/473975_2.png) [@HS\_Kim](https://discourse.mcneel.com/u/HS_Kim)\
**Post date:** [September 21, 2020, 7:50am UTC](https://discourse.mcneel.com/t/sort-points/108994/4 "2020-09-21T07:50:28Z")

</div>

Check this as well.

 ![Canvas at 16;49;04](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/b/d/bd36861c5adc61a28fa41ffeedda2f777ee8aabd.png)  
[POINT ORDER\_re.gh](https://discourse.mcneel.com/uploads/short-url/8ixlsnQD2UBY2PsNaZ7XcD6HaZK.gh) (8.2 KB)

---

<div class="post-metadata">

**Author:** ![cristian.gutierrez.v](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/cristian.gutierrez.v/32/473651_2.png) [@cristian.gutierrez.v](https://discourse.mcneel.com/u/cristian.gutierrez.v)\
**Post date:** [September 21, 2020, 7:51am UTC](https://discourse.mcneel.com/t/sort-points/108994/5 "2020-09-21T07:51:35Z")

</div>

The first answer, allows me to reorder the areas of which the points are the centroids of. But it depends on “closest points”, a feature that maybe not always is going to work, I think.  
The second could not fail, but how do i extract the indexes to apply them to reorder the geometry?

Thanks

---

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [September 21, 2020, 8:07am UTC](https://discourse.mcneel.com/t/sort-points/108994/6 "2020-09-21T08:07:40Z")

</div>

Orient i just to move points on top of original one than use sort or closest point

---

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [September 21, 2020, 8:08am UTC](https://discourse.mcneel.com/t/sort-points/108994/7 "2020-09-21T08:08:46Z")

</div>

I don’t understand your question, which geometry?

---

<div class="post-metadata">

**Author:** ![cristian.gutierrez.v](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/cristian.gutierrez.v/32/473651_2.png) [@cristian.gutierrez.v](https://discourse.mcneel.com/u/cristian.gutierrez.v)\
**Post date:** [September 21, 2020, 8:23am UTC](https://discourse.mcneel.com/t/sort-points/108994/8 "2020-09-21T08:23:15Z")

</div>

All the points are centroids of individual areas. So with the right order of the points I want to give the right order to that areas (The geometry). Now that you have explained to me the use of the component “orient” and its relation with “closest points” i think it should never fail to give the right order when the same definition will be used to new sets of centroids.  
thank you

---

<div class="post-metadata">

**Author:** ![anon39580149](https://avatars.discourse-cdn.com/v4/letter/a/977dab/32.png) [@anon39580149](https://discourse.mcneel.com/u/anon39580149)\
**Post date:** [September 21, 2020, 8:36am UTC](https://discourse.mcneel.com/t/sort-points/108994/9 "2020-09-21T08:36:44Z")

</div>

> [@cristian.gutierrez.v](#):
>
> “orient” and its relation with “closest points”

Both of them work , but i think you don’t need that in your original file

---

<div class="post-metadata">

**Author:** ![cristian.gutierrez.v](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/cristian.gutierrez.v/32/473651_2.png) [@cristian.gutierrez.v](https://discourse.mcneel.com/u/cristian.gutierrez.v)\
**Post date:** [September 21, 2020, 9:45am UTC](https://discourse.mcneel.com/t/sort-points/108994/10 "2020-09-21T09:45:29Z")

</div>

Thanks! 🙂  
I’ve tried to understand your solution, but there are things I don’t get:

- why do you transform the points to numbers and then sort the same points according to those numbers? Shouldn’t be already sorted since the numbers came from the points?
- maybe I’m wrong, but it seems that both sets of resulting numbers are the same. How does the relation between both sets of points work?

Thanks again

---

<div class="post-metadata">

**Author:** ![HS\_Kim](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/hs_kim/32/473975_2.png) [@HS\_Kim](https://discourse.mcneel.com/u/HS_Kim)\
**Post date:** [September 21, 2020, 10:32am UTC](https://discourse.mcneel.com/t/sort-points/108994/11 "2020-09-21T10:32:04Z")

</div>

Your two point sets are placed directionally in 2d space, so if you sort the point order according to the “Y” direction for instance, you would be able to sort their order identically.

And then you can extract the original point order out of the first(correct order) by using the sorted points andMember Index.

---

<div class="post-metadata">

**Author:** ![Joseph\_Oster](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/joseph_oster/32/549124_2.png) [@Joseph\_Oster](https://discourse.mcneel.com/u/Joseph_Oster)\
**Post date:** [September 21, 2020, 1:36pm UTC](https://discourse.mcneel.com/t/sort-points/108994/12 "2020-09-21T13:36:12Z")

</div>

> [@cristian.gutierrez.v](#):
>
> I have two sets of points. The second one is the result of a number of operations, but the order gets wrong.

I would re-examine the code that caused them to get out of sequence. How/why did that happen?

 ![point_order](https://global.discourse-cdn.com/mcneel/uploads/default/original/3X/2/8/285caf302ab4902c0db820d897e0d781ea03dff9.png)

And why are these points so _ **very far** _ from the origin?

---

<div class="post-metadata">

**Author:** ![cristian.gutierrez.v](https://sea3.discourse-cdn.com/mcneel/user_avatar/discourse.mcneel.com/cristian.gutierrez.v/32/473651_2.png) [@cristian.gutierrez.v](https://discourse.mcneel.com/u/cristian.gutierrez.v)\
**Post date:** [September 22, 2020, 3:50am UTC](https://discourse.mcneel.com/t/sort-points/108994/13 "2020-09-22T03:50:18Z")

</div>

The difference in the sequence, I supposed, is because the original set is a tree with 15 items in 5 branches that operates with another tree with 10 branches and 13 items in total. So it gets messy.

The points are far from the origin because are referenced to coordinates in UTM - DATUM WGS 84. I just forgot to drag them to the origin.
