Mapping Toolbox | ![]() ![]() |
Perform polygon boolean operations.
Syntax
Description
[lat,lon] = polybool(flag
,x1,y1,x2,y2) performs the polygon boolean operation identified by flag
. Valid flags strings are one of the following alternatives: ('intersection
','and
','&
'), ('union
','or
','|
','+
','plus
'), ('exclusiveor
','xor
') and ('subtraction
','minus
','-
'). The polygon inputs are NaN
-delimited vectors, or cell arrays containing individual polygons in each element with the outer face separated from the subsequent inner faces by NaN
s. The result is output as NaN
-delimited vectors.
[lat,lon] = polybool(flag
,x1,y1,x2,y2,outputformat
) controls the format of the resulting polygons. If outputformat
is 'vector
', the result is returned as vectors with NaN
s separating the faces. No distinction is made between outer and inner faces of polygons. If outputformat
is 'cutvector
', inner faces are connected to the enclosing polygon face by inserting a cut. If outputformat
is 'cell
', the result is returned as cell arrays containing individual polygons in each element, with the outer face separated from the subsequent inner faces by NaN
s. If omitted, 'vector
' is assumed.
Limitations
Polygons are assumed to be in a cartesian coordinate system. As such, geographic data that encompasses a pole cannot be used directly. Use flatearthpoly to convert polygons to cartesian coordinates.
Example
theta = (0:pi/6:2*pi)'; lat1 = sin(theta); lon1 = cos(theta); lat2 = [0 1 -1 0]'; lon2 = [0 2 2 0]'; [latb,lonb] = polybool('intersection',lat1,lon1,lat2,lon2); axesm miller plotm(lat1,lon1,'b') plotm(lat2,lon2,'r') patchm(latb,lonb,'g')
[latb2,lonb2] = polybool('xor',lat1,lon1,lat2,lon2,'cell') latb2 = [ 6x1 double] [15x1 double] lonb2 = [ 6x1 double] [15x1 double]
See Also
bufferm |
Compute buffer zones for vector data |
polyjoin |
Convert polygon segments from cell array to vector format |
polysplit |
Extract segments of NaN -delimited polygon vectors to cell arrays |
![]() | polcmap | polyjoin | ![]() |