This example shows how to trim vectors to form lines and polygons using the
maptrimp functions. It is not unusual for vector data to extend beyond the geographic region currently of interest. For example, you might have coastline data for the entire world, but are interested in mapping Australia only. In this and other situations, you might want to eliminate unnecessary data from the workspace and from calculations in order to save memory or to speed up processing and display. Line data and patch data need to be trimmed differently. You can trim line data by simply removing points outside the region of interest by clipping lines at the map frame or to some other defined region. Patch data requires a more complicated method to ensure that the patch objects are correctly formed. If you want to handle vectors as line data, the
maptriml function returns variables containing only those points that lie within the defined region. If, instead, you want to maintain polygon format, use the
maptrimp function. Be aware, however, that patch-trimmed data is usually larger and more expensive to compute.
Note: When drawing maps, Mapping Toolbox display functions automatically trim vector geodata to the region specified by the frame limits (
FLonLimit map axes properties) for azimuthal projections, or to frame or map limits (
MapLonLimit map axes properties) for nonazimuthal projections. The trimming is done internally in the display routine, keeping the original data intact.
coastlines MAT-file. This file contains data for the entire world.
Define a region-of-interest centered on Australia.
latlim = [-50 0]; lonlim = [105 160];
maptriml to delete all line data outside these limits, producing line vectors.
[linelat,linelon] = maptriml(coastlat,coastlon,latlim,lonlim);
maptrimp to delete all polygon data outside these limits, producing polygon vectors.
[polylat,polylon] = maptrimp(coastlat,coastlon,latlim,lonlim);
Examine the variables to see how much data has been reduced. The clipped data is only 10% as large as the original data set.
Name Size Bytes Class Attributes coastlat 9865x1 78920 double coastlon 9865x1 78920 double latlim 1x2 16 double linelat 977x1 7816 double linelon 977x1 7816 double lonlim 1x2 16 double polylat 961x1 7688 double polylon 961x1 7688 double
Plot the trimmed patch vectors using a Miller projection.
axesm('MapProjection', 'miller', 'Frame', 'on',... 'FlatLimit', latlim, 'FlonLimit', lonlim) patchesm(polylat, polylon, 'c')
Plot the trimmed line vectors to see that they conform to the patches.
plotm(linelat, linelon, 'm')