[GIS] Given a set of coordinates, how can I calculate the minimum bounds

coordinates

I have a set of coordinates in lon/lat. There are always at least 3 ordered coordinates that form a poly (if they were projected flat). How can I calculate the minimum bounds for these coordinates as a set of valid longitude and latitude ranges? (by 'valid' I mean ranges that explicitly account for the antimeridian). Its kind of hard to explain what I'm looking for so I have a picture.

enter image description here

The case in the picture is trivial; you just find the absolute minimum and maximum for all the points. This doesn't work for all cases though. Is there a generic solution?

Edit:
To clarify what I mean by 'valid', say I had three longitude values in my data set: -76, -135 and 164. The values cross the antimeridian and I'd like the resulting ranges to be split: -76 to -180 AND 164 to 180.

Some more clarification. The points form a polygon, so in certain cases, the required range could be from -180 to +180 (ie, the full 360 degrees):

enter image description here

The image on the left shows the longitude of four coordinates that occur on one 'half' of the Earth. Imagine it as if you were looking down onto the north pole (black dot). The pink shows the minimum longitudinal range that encompasses the polygon (the polygon is shown between the four points in purple). The case on the left would have two longitudinal ranges: [-180 to -120] and [135 to 180] (just visually estimating it)

The image on the right shows another case where the points go all the way around the Earth. This range would be [-180 to 180].

Best Answer

Hope i understand the question correctly...

We can solve the problem for longitude and latitude separately, so i will take your example with the longitudes: -76, -135 and 164.

First i would order them:

-135, -76, 164

Then i would add the left most coordinate to the right again: -135 + 360 = 225

-135, -76, 164, 225

Now we can calculate the gaps between the coordinates:

-135 (59) -76 (240) 164 (61) 225
             .......

The biggest gap (240) must be the boundary of the minimum bounding box, the part that does not belong to the box. The dotted line is the biggest part of the circle we can spare out. In our example that means, the boundary box starts with 164, includes -135 and ends with -76.

Related Question