linelength
Syntax
Description
Examples
Read world rivers into the workspace as a geospatial table. Extract the line shapes.
rivers = readgeotable("worldrivers.shp");
shape = rivers.Shapeshape=128×1 geolineshape array with properties:
NumParts: [128×1 double]
Geometry: "line"
CoordinateSystemType: "geographic"
GeographicCRS: [1×1 geocrs]
⋮
Calculate the lengths of the line shapes.
len = linelength(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 line lengths are in meters.
shape.GeographicCRS.Spheroid.LengthUnit
ans = 'meter'
Include the line lengths in the geospatial table by creating a new table variable. Sort the rows of the table in descending order by Length. Then, view the first eight rows of the table by using the head function. Note that, because the worldrivers.shp file stores information about some rivers using multiple line shapes, the line lengths reported in the first eight rows of the table might not reflect the total lengths of the named rivers.
rivers.Length = len; rivers = sortrows(rivers,"Length","descend"); head(rivers)
Shape Name Length
____________ ___________________ __________
geolineshape "Nile - White Nile" 4.2573e+06
geolineshape "Mekong" 3.9981e+06
geolineshape "Yangtze" 3.3539e+06
geolineshape "Yellow" 3.1722e+06
geolineshape "Niger" 3.0812e+06
geolineshape "Missouri" 2.9331e+06
geolineshape "Indus" 2.5962e+06
geolineshape "Brahmaputra" 2.5607e+06
Read hydrographic data for Concord, MA into the workspace as a geospatial table. Extract the line shapes.
hydro = readgeotable("concord_hydro_line.shp");
shape = hydro.Shapeshape=237×1 maplineshape array with properties:
NumParts: [237×1 double]
Geometry: "line"
CoordinateSystemType: "planar"
ProjectedCRS: [1×1 projcrs]
⋮
Calculate the lengths of the line shapes.
len = linelength(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 line lengths are in meters.
shape.ProjectedCRS.LengthUnit
ans = "meter"
Create a new geospatial table from the shape objects and the line lengths. View the first eight rows of the table by using the head function.
hydro_length = table(shape,len,VariableNames=["Shape","Length"]); head(hydro_length)
Shape Length
____________ ______
maplineshape 86.53
maplineshape 137.36
maplineshape 151.86
maplineshape 32.875
maplineshape 70.196
maplineshape 109.87
maplineshape 117.55
maplineshape 59.693
Input Arguments
Line shape, specified as a geolineshape
object, a maplineshape
object, an array of geolineshape objects, or an array of
maplineshape objects.
Output Arguments
Line length, returned as an array. The size of len matches the
size of shape.
The units of len depend on the type of line shape.
When
shapecontainsgeolineshapeobjects, the length unit of the reference ellipsoid for the shape determines the units. To find the length unit, get thegeocrsobject for the shape by querying theGeographicCRSproperty of the shape object. Then, get the ellipsoid by querying theSpheroidproperty of thegeocrsobject. If the ellipsoid is areferenceEllipsoidorreferenceSphereobject, then query theLengthUnitproperty of the ellipsoid. For a shapeshp, the length unit isshp.GeographicCRS.Spheroid.LengthUnit. If theGeographicCRSproperty of the object is empty, the function calculates the line length using the WGS84 reference ellipsoid and a length unit of meters.When
shapecontainsmaplineshapeobjects, the length unit of the projected coordinate reference system for the shape determines the units. To find the length unit, get theprojcrsobject for the shape by querying theProjectedCRSproperty of the shape object. Then, query theLengthUnitproperty of theprojcrsobject. For a shapeshp, the length unit isshp.ProjectedCRS.LengthUnit.
When shape contains geolineshape objects, the
linelength function calculates the line lengths using geodesics.
Data Types: double
Tips
The accuracy of the linelength function depends on
the resolution of the data used to create the lines. As a result, the function can return
different results when you use line shapes from different data sets as inputs.
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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- 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)