SitePoint Sponsor

# Thread: Determine 4 corner coordinates of an XY list

1. ## Determine 4 corner coordinates of an XY list

I'm trying to figure out a way to determine the 4 coordinate corners. The string won't always be the same. Sometimes it may have more or less coordinates. It doesn't seem all that hard, but I don't see a clear cut way to do it either.

Code:
```48.010918880032534,-102.27871447619208,
48.007298546092386,-102.27871873313035,
48.007300404087175,-102.28410804755288,
48.007302263082124,-102.28949736197535,
48.007304121076913,-102.29488670439923,
48.007305979071589,-102.30027601882199,
48.010925506717513,-102.30027931864152,
48.014545007363211,-102.30028259146059,
48.018163867996407,-102.3002842242235,
48.023143739025727,-102.30028731751861,
48.023143709229146,-102.29967535036019,
48.023140964347476,-102.29489150234963,
48.023137856666608,-102.28949565918271,
48.023137825974516,-102.28890660889158,
48.023135053987971,-102.28409987201547,
48.023131946306933,-102.2787040848512,
48.018158490915084,-102.27870810340568,
48.014539184972818,-102.27871024825487,
48.010918880032534,-102.27871447619208```

2. Figured it out

PHP Code:
``` \$String = '48.010918880032534,-102.27871447619208,48.007298546092386,-102.27871873313035,48.007300404087175,-102.28410804755288,48.007302263082124,-102.28949736197535,48.007304121076913,-102.29488670439923,48.007305979071589,-102.30027601882199,48.010925506717513,-102.30027931864152,48.014545007363211,-102.30028259146059,48.018163867996407,-102.3002842242235,48.023143739025727,-102.30028731751861,48.023143709229146,-102.29967535036019,48.023140964347476,-102.29489150234963,48.023137856666608,-102.28949565918271,48.023137825974516,-102.28890660889158,48.023135053987971,-102.28409987201547,48.023131946306933,-102.2787040848512,48.018158490915084,-102.27870810340568,48.014539184972818,-102.27871024825487,48.010918880032534,-102.27871447619208'; \$Exp = explode(',',\$String); if(is_array(\$Exp)) {     \$C = 1;     foreach(\$Exp as \$Exp2) {         if(!empty(\$Exp2)) {                 if(\$Exp2 > 0) {                     \$Latitude[] = \$Exp2;                     } else {                     \$Longitude[] = \$Exp2;                     }             }         } } array_multisort(\$Latitude, SORT_ASC, \$Longitude, SORT_ASC);  ```

3. Actually.... it still doesn't work, because there's no guarantee that the highest X value will actually be the highest X value with the highest Y value (and the other 3 combinations to get corners).

4. This is my visualization. My brain needs it when I'm reaching the end of my day lol. As you can see, sorting by X, then Y will never return the top right coordinate in any case. Appreciate any thoughts!

Sort.jpg

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•