perimeter
Syntax
Description
Examples
Calculate Perimeter of Polygon in Geographic Coordinates
Read worldwide land masses into the workspace as a geospatial table. Extract the polygon shapes.
land = readgeotable("landareas.shp");
shape = land.Shape
shape=537×1 geopolyshape array with properties:
NumRegions: [537x1 double]
NumHoles: [537x1 double]
Geometry: "polygon"
CoordinateSystemType: "geographic"
GeographicCRS: [1x1 geocrs]
⋮
Calculate the perimeters of the polygon shapes.
P = perimeter(shape);
The units depend on the geographic coordinate reference system (CRS) for the shape. Find the length unit for the geographic CRS. The result indicates that the perimeters are in meters.
shape.GeographicCRS.Spheroid.LengthUnit
ans = 'meter'
Include the perimeters in the geospatial table by creating a new table variable. Sort the rows of the table in descending order by Perimeter
. Then, view the first eight rows of the table by using the head
function.
land.Perimeter = P; land = sortrows(land,"Perimeter","descend"); head(land)
Shape Name Perimeter ____________ _________________________ __________ geopolyshape "Africa and Eurasia" 1.4207e+08 geopolyshape "North and South America" 9.9316e+07 geopolyshape "Antarctica" 3.0741e+07 geopolyshape "Australia" 1.7029e+07 geopolyshape "Greenland" 1.281e+07 geopolyshape "Baffin Island" 9.2117e+06 geopolyshape "New Guinea" 7.2776e+06 geopolyshape "Borneo" 4.9742e+06
Calculate Perimeter of Polygon in Planar Coordinates
Read hydrographic data for Concord, MA into the workspace as a geospatial table. Extract the polygon shapes.
hydro = readgeotable("concord_hydro_area.shp");
shape = hydro.Shape
shape=98×1 mappolyshape array with properties:
NumRegions: [98x1 double]
NumHoles: [98x1 double]
Geometry: "polygon"
CoordinateSystemType: "planar"
ProjectedCRS: [1x1 projcrs]
⋮
Calculate the perimeters of the polygon shapes.
P = perimeter(shape);
The units depend on the projected coordinate reference system (CRS) for the shape. Find the length unit for the projected CRS. The result indicates that the perimeters are in meters.
shape.ProjectedCRS.LengthUnit
ans = "meter"
Create a new geospatial table from the shape objects and the perimeters. View the first eight rows of the table by using the head
function.
hydro_perimeter = table(shape,P,VariableNames=["Shape","Perimeter"]); head(hydro_perimeter)
Shape Perimeter ____________ _________ mappolyshape 289.22 mappolyshape 11264 mappolyshape 207.37 mappolyshape 117.55 mappolyshape 633.93 mappolyshape 370.54 mappolyshape 3378.7 mappolyshape 1650.6
Input Arguments
shape
— Polygon shape
geopolyshape
object | mappolyshape
object | array of geopolyshape
objects | array of mappolyshape
objects
Polygon shape, specified as a geopolyshape
object, a mappolyshape
object, an array of geopolyshape
objects, or an array of
mappolyshape
objects.
Output Arguments
P
— Perimeter
array
Perimeter, returned as an array. The size of P
matches the size
of shape
.
The units of P
depend on the type of polygon shape.
When
shape
containsgeopolyshape
objects, the length unit of the reference ellipsoid for the shape determines the units. To find the length unit, get thegeocrs
object for the shape by querying theGeographicCRS
property of the shape object. Then, get the ellipsoid by querying theSpheroid
property of thegeocrs
object. If the ellipsoid is areferenceEllipsoid
orreferenceSphere
object, then query theLengthUnit
property of the ellipsoid. For a shapeshp
, the length unit isshp.GeographicCRS.Spheroid.LengthUnit
. If theGeographicCRS
property of the object is empty, the function calculates the perimeter using the WGS84 reference ellipsoid and a length unit of meters.When
shape
containsmappolyshape
objects, the length unit of the projected coordinate reference system for the shape determines the units. To find the length unit, get theprojcrs
object for the shape by querying theProjectedCRS
property of the shape object. Then, query theLengthUnit
property of theprojcrs
object. For a shapeshp
, the length unit isshp.ProjectedCRS.LengthUnit
.
When shape
contains geopolyshape
objects, the
perimeter
function calculates the perimeters using geodesics.
Tips
The accuracy of the perimeter
function depends on
the resolution of the data used to create the polygons. As a result, the function can return
different results when you use polygon shapes from different data sets as inputs. This image
compares the perimeters of polygon shapes for the state of Florida from two data sets.
Version History
Introduced in R2024a
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.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- 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)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)