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

    %% Extracting and Joining Polygons or Line Segments
% This example shows how to identify line or patch segments once they have
% been combined into large |NaN|-clipped vectors. You can separate these
% polygon or line vectors into their component segments using the
% |polysplit| function, which takes column vectors as inputs. To join
% together individual polygon or line vectors use |polyjoin|.
%%
% Create two |NaN|-delimited arrays in the form of column vectors.

% Copyright 2015 The MathWorks, Inc.

lat = [45.6 -23.47 78 NaN 43.9 -67.14 90 -89]';
lon = [13 -97.45 165 NaN 0 -114.2 -18 0]';
%%
% Split the column vectors into individual line segment cell arrays at the
% NaN separators using |polysplit|.
[latc,lonc] = polysplit(lat,lon)
%%
% Inspect the contents of the cell arrays. Note that each cell array
% element contains a segment of the original line.
[latc{1} lonc{1}]
[latc{2} lonc{2}]
%%
% To reverse the process, use |polyjoin|. 
[lat2,lon2] = polyjoin(latc,lonc);
%%
% Perform a logical comparison of the joined segments. Note that they are
% identical with the initial |lat| and |lon| arrays. The logical comparison
% is false for the |NaN| delimiters, by definition.
[lat lon] == [lat2 lon2]
%%
% Test for global equality, including |NaN| values.
isequaln(lat,lat2) & isequaln(lon,lon2)