Sorting landmarks

29 views
Skip to first unread message

Maia R.

unread,
Oct 12, 2021, 2:12:39 PM10/12/21
to scalismo
I would like to sort a sequence of anatomical landmarks wrt to the landmark ID.
I tried this:
===
val refIDs = refLMs.map(lm => lm.id).sorted
But how to sort the point as well with the corresponding id ?
Could some one have an idea on how to do that ?
Thank you
Best regards

Max

unread,
Oct 12, 2021, 3:19:57 PM10/12/21
to scalismo
Hi Maia,

this should do the job (provided that lm.id is actually an integer):

val sorted = refLMs.map(lm => (lm.id.toInt, lm.point)).sortBy(_._1)

Best
Max

Maia R.

unread,
Oct 13, 2021, 8:40:02 AM10/13/21
to scalismo
Dear Max, 
Thank you very much, it works (I just suppress .toInt as my ID are of String type).
Best
Maia

Maia R.

unread,
Oct 13, 2021, 9:29:15 AM10/13/21
to scalismo
I had also to add Landmark conversion, otherwise I got error, so final solution is (my landmarks are anatomical ones with String name):
val sorted = refLMs.map(lm => (lm.id, lm.point)).sortBy(_._1).map(f  => Landmark(f._1, f._2))

Thank you very much,
Best regards

Reply all
Reply to author
Forward
0 new messages