union
Description
calculates the geometric union of the specified point, line, or polygon shapes.shapeout = union(shape1)
When you specify point shapes, the union is a point shape that contains all the points in
shape1.When you specify line shapes, the union is a line shape that contains all the line parts in
shape1.When you specify polygon shapes, the union is a polygon shape that combines the polygon regions in
shape1.
Examples
Read a shapefile of world rivers into the workspace as a geospatial table. The table represents the rivers using line shapes in geographic coordinates. Extract the line shapes.
rivers = readgeotable("worldrivers.shp");
shape1 = rivers.Shapeshape1=128×1 geolineshape array with properties:
NumParts: [128×1 double]
Geometry: "line"
CoordinateSystemType: "geographic"
GeographicCRS: [1×1 geocrs]
⋮
Calculate the union of the line shapes. The result is a scalar line shape in geographic coordinates.
shapeout = union(shape1)
shapeout =
geolineshape with properties:
NumParts: 130
Geometry: "line"
CoordinateSystemType: "geographic"
GeographicCRS: [1×1 geocrs]
Read a shapefile containing the coordinates of locations in Boston as a geospatial table. The table represents the locations using point shapes in planar coordinates.
GT = readgeotable("boston_placenames.shp");Create a subtable that contains two table rows. Then, create a vector of polygon shapes by buffering the point shapes.
subGT = geocode(["BEACON HILL","COPPS HILL"],GT); shape1 = buffer(subGT.Shape,1000)
shape1=2×1 mappolyshape array with properties:
NumRegions: [2×1 double]
NumHoles: [2×1 double]
Geometry: "polygon"
CoordinateSystemType: "planar"
ProjectedCRS: [1×1 projcrs]
Display the polygon shapes on a map.
figure geoplot(shape1)

Calculate the union of the polygon shapes. The result is a scalar polygon shape in planar coordinates.
shapeout = union(shape1)
shapeout =
mappolyshape with properties:
NumRegions: 1
NumHoles: 0
Geometry: "polygon"
CoordinateSystemType: "planar"
ProjectedCRS: [1×1 projcrs]
Display the union on a new map.
figure geoplot(shapeout)

Create two vectors of polygon shapes in geographic coordinates.
The first vector contains polygon shapes that buffer the cities of Adelaide and Brisbane.
The second vector contains polygon shapes that buffer the cities of Melbourne and Sydney.
GT1 = geocode(["Adelaide","Brisbane"]); shape1 = buffer(GT1.Shape,6); GT2 = geocode(["Melbourne","Sydney"]); shape2 = buffer(GT2.Shape,3.5);
Display the polygon shapes on a map.
figure geoplot([shape1; shape2])

Calculate the element-wise unions of the polygon shapes. The result is a two-element vector of polygon shapes.
The first polygon shape is the union of the polygon shapes for Adelaide and Melbourne.
The second polygon shape is the union of the polygon shapes for Brisbane and Sydney.
shapeout = union(shape1,shape2)
shapeout=2×1 geopolyshape array with properties:
NumRegions: [2×1 double]
NumHoles: [2×1 double]
Geometry: "polygon"
CoordinateSystemType: "geographic"
GeographicCRS: [1×1 geocrs]
Display the unions on a new map. Note that the union function did not calculate the union of the polygon shapes for Melbourne and Sydney.
figure geoplot(shapeout)

Input Arguments
Input shapes, specified as one of these options:
Array of
geopointshapeobjects — Point shapes in geographic coordinatesArray of
geolineshapeobjects — Line shapes in geographic coordinatesArray of
geopolyshapeobjects — Polygon shapes in geographic coordinatesArray of
mappointshapeobjects — Point shapes in planar coordinatesArray of
maplineshapeobjects — Line shapes in planar coordinatesArray of
mappolyshapeobjects — Polygon shapes in planar coordinates
If you specify both shape1 and shape2
as input to the union function, then
shape1 and shape2 must share these characteristics:
The geometric types of
shape1andshape2must match. For example, ifshape1is a polygon, thenshape2must also be a polygon. You can find the geometric type of a shape object by querying theGeometryproperty.The coordinate system types of
shape1andshape2must match. For example, ifshape1is in geographic coordinates, thenshape2must also be in geographic coordinates. You can find the coordinate system type of a shape object by querying theCoordinateSystemTypeproperty.The coordinate reference systems (CRSs) of
shape1andshape2must match, unless one ofshape1orshape2is not associated with a CRS. For a shape object in geographic coordinates, you can find the CRS by querying theGeographicCRSproperty. For a shape object in planar coordinates, you can find the CRS by querying theProjectedCRSproperty.The sizes of
shape1andshape2must be compatible. For more information about compatible array sizes, see Compatible Array Sizes for Basic Operations.
Output Arguments
Union of the shapes, returned as an array of geopointshape, geolineshape, geopolyshape, mappointshape, maplineshape, or mappolyshape objects.
When you specify only shape1, the
shapeout argument is a scalar. When you specify both
shape1 and shape2, the size of
shapeout depends on the sizes of
shape1 and shape2. For more
information about array sizes, see Compatible Array Sizes for Basic Operations.
The geometric type and coordinate system of shapeout
matches the geometric type and coordinate system of the input shape or shapes. For
example, if shape1 and shape2 contain
maplineshape objects, then shapeout also
contains maplineshape objects.
Version History
Introduced in R2025a
See Also
Functions
Objects
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Web サイトの選択
Web サイトを選択すると、翻訳されたコンテンツにアクセスし、地域のイベントやサービスを確認できます。現在の位置情報に基づき、次のサイトの選択を推奨します:
また、以下のリストから Web サイトを選択することもできます。
最適なサイトパフォーマンスの取得方法
中国のサイト (中国語または英語) を選択することで、最適なサイトパフォーマンスが得られます。その他の国の MathWorks のサイトは、お客様の地域からのアクセスが最適化されていません。
南北アメリカ
- América Latina (Español)
- Canada (English)
- United States (English)
ヨーロッパ
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)