flatearthpoly

Clip polygon to world limits

Syntax

[latf,lonf] = flatearthpoly(lat,lon)
[latf,lonf] = flatearthpoly(lat,lon,longitudeOrigin)

Description

[latf,lonf] = flatearthpoly(lat,lon) trims NaN-separated polygons specified by the latitude and longitude vectors lat and lon to the limits [-180 180] in longitude and [-90 90] in latitude, inserting straight segments along the +/- 180-degree meridians and at the poles. Inputs and outputs are in degrees.

[latf,lonf] = flatearthpoly(lat,lon,longitudeOrigin) centers the longitude limits on the longitude specified by the scalar longitude longitudeOrigin.

Examples

Vector data for geographic objects that encompass a pole will inevitably encounter or cross the date line. While the toolbox properly displays such polygons, they can cause problems for functions like the polygon intersection and Boolean operations that work with Cartesian coordinates. When these polygons are treated as Cartesian coordinates, the date line crossing results in a spurious line segment, and the polygon displayed as a patch does not have the interior filled correctly.

antarctica = shaperead('landareas', 'UseGeoCoords', true,...
    'Selector', {@(name) strcmp(name,'Antarctica'), 'Name'});
figure; plot(antarctica.Lon, antarctica.Lat); ylim([-100 -60])

The polygons can be reformatted more appropriately for Cartesian coordinates using the flatearthpoly function. The result resembles a map display on a cylindrical projection. The polygon meets the date line, drops down to the pole, sweeps across the longitudes at the pole, and follows the date line up to the other side of the date line crossing.

[latf, lonf] = flatearthpoly(antarctica.Lat', antarctica.Lon');
figure; mapshow(lonf, latf, 'DisplayType', 'polygon')
ylim([-100 -60])
xlim([-200 200])
axis square 

Tips

The polygon defined by lat and lon must be well-formed:

  • The boundaries must not intersect.

  • The vertices of outer boundaries must be in a clockwise order and the vertices of inner boundaries must be in a counterclockwise order, such that the interior of the polygon is always to the right of the boundary.

For more information, see Create and Display Polygons.

Introduced before R2006a