Click here to Skip to main content
16,004,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a MapPoint List that has X and Y coordinates. I would like to find in that list, the smallest X and Y, the highest Y and the smallest X, the highest X and Y and then the smallest Y and the highest X (I need to get corner points). Does anyone know how to sort List so that I have it so sorted? I know how to make it depend only on X or Y.

What I have tried:

C#
ReadOnlyPointCollection pts = linieStrany.Points;
                      var mapPointList = pts.ToList();
                      var serazenySeznam=mapPointList.OrderByDescending(o => o.X).ToList();

Don't know how to do it? Maybe it's done in a completely different way...

Thank you

David
Posted
Updated 6-Jun-22 0:56am

1 solution

Look at the Max and Min methods:
Enumerable.Max Method (System.Linq) | Microsoft Docs[^]
Enumerable.Min Method (System.Linq) | Microsoft Docs[^]

If you want the corner points that enclose all points, then all you need are min x, min y, max x, and max y: the two corners (minX, minY) and (maxX, maxY) enclose all points.
 
Share this answer
 
v2
Comments
dejf111 6-Jun-22 7:38am    
Thank you
OriginalGriff 6-Jun-22 7:45am    
You're welcome!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900