# Efficient way to 2D sort? "Sort by Z, then Y"

What’s a good way to 2D sort in GH? For example, sorting points by Z, then Y, in cases where there are many with the same Z. In attached GH with random points, Z coords are rounded off to demonstrate.

Spreadsheets have this built in. Is there an efficient way or plugin to do this?

Thanks all.

sort-question.gh (13.7 KB)

Sort Points (Sort Pt) with “fake” points.

sort-question_2019Nov21a.gh (16.9 KB)

2 Likes

Hi,

this is one of possibilities…

Hahah…same time…almost

1 Like

Instead of deconstruct/construct point, you could also use Points To Numbers and Numbers To Points to swap around coordinates.

2 Likes

It took me quite awhile this morning to understand how to use Points To Numbers and Numbers To Points in this context, but I got it. For any single case, I don’t see any advantage at all since the orange (Deconstruct) and yellow (Pt2Num) groups produce identical results.

sort-question_2019Nov22b.gh (24.3 KB)

If one wants to explore all the sorting options, a case can be made for Pt2Num with its ‘M’ (Mask) input. Given the time invested to fully understand it though, I’m not so sure.

sort-question_2019Nov22a.gh (30.6 KB)

There isn’t a benefit in this case, just another way of doing it. There may be benefits in other cases though, so being aware of this may be useful one day.

The major difference here is the in the one case the ordering is encoded via wires, while in the other it’s via data.

2 Likes

Thanks all. The decon/con method is wonderfully simple. However I am getting unexpected results with my actual points. The Z is sorted properly, but the Y is not. GH attached with points embedded.

sort-question_2019Nov22.gh (21.2 KB)

Note that there’s about 16 decimal places in numbers, but GH will only show the first six usually. So the x values could actually be different in the 7th or 8th or 15th place and affect the sorting.

1 Like

Thank you David! That was indeed the issue. Rounding off before Construct resolves it.

1 Like