# flatearthpoly

Insert points along date line to pole

## 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 ```

expand all

### Tips

The polygon topology for the input vectors must be valid. This means that vertices for outer rings (main polygon or "island" polygons) must be in clockwise order, and any inner rings ("lakes") must run in counterclockwise order for the function to work properly. You can use the `ispolycw` function to check whether or not your `lat`, `lon` vectors meet this criterion, and the `poly2cw` and `poly2ccw` functions to correct any that run in the wrong direction.

Get trial now