www.gusucode.com > map 案例源码 matlab代码程序 > map/TrimVectorsToFormLinesAndPolygonsExample.m

    %% Trim Vectors to Form Lines and Polygons
% This example shows how to trim vectors to form lines and polygons using
% the |maptriml| and |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
% <docid:map_ref.f14-951617> function returns variables containing only
% those points that lie within the defined region. If, instead, you want to
% maintain polygon format, use the <docid:map_ref.f14-374347> 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 (
% |FLatLimit| and |FLonLimit| map axes properties) for azimuthal
% projections, or to frame or map limits (|MapLatLimit| and |MapLonLimit|
% map axes properties) for nonazimuthal projections. The trimming is done
% internally in the display routine, keeping the original data intact.
%%
% Load the |coastlines| MAT-file. This file contains data for the entire
% world.

% Copyright 2015 The MathWorks, Inc.

load coastlines
%%
% Define a region-of-interest centered on Australia.
latlim = [-50 0]; 
lonlim = [105 160];
%%
% Use |maptriml| to delete all line data outside these limits, producing
% line vectors.
[linelat,linelon] = maptriml(coastlat,coastlon,latlim,lonlim);
%%
% Use |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.
whos
%%
% 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')