What is a length and area analysis?
Length and area analysis calculates the length of lines and the area of polygons using either planar or geodesic methods. To execute the analysis, you can use ArcGIS Maps SDK for JavaScript, ArcGIS Maps SDKs for Native Apps, or ArcGIS API for Python. See the code examples below.
How to measure length and area
The measured length of a line or area of a polygon depends on the coordinate system used to define the geometry. For example, if you measure the area of Lake Superior in one coordinate system, and compare the result to an area measurement in another coordinate system, then both results will likely differ because they involve different coordinates.
Since each coordinate system will yield different measurement results, you need to ensure the geometries being measured use a coordinate system that gives you the most accurate results given their locations.
There are two types of length and area calculations you can perform: planar and geodesic.
Planar measurement
Planar calculations measure lengths and areas on a flat, two-dimensional plane. Planar length uses Euclidean distance, and planar area uses the area enclosed by the projected geometry. Results can be returned in linear or area units, such as meters, feet, square meters, or square feet.
When measuring length, you should ensure the projected coordinate system of the input geometries preserves distance. When measuring area, you should ensure the projected coordinate system of the input geometries preserves area.
Geodesic measurement
Geodesic calculations measure lengths and areas on the surface of a spheroid, accounting for the earth's curvature. Results can be returned in linear or area units, such as kilometers, meters, square kilometers, or square meters. Geodesic calculations commonly use geometries defined in a geographic coordinate system, such as WGS 84. They can also accept geometries defined in Web Mercator, as described below.
Types of length and area operations
| Operation | Description | Example |
|---|---|---|
| Area | Returns the planar | |
| Distance | Returns the planar | |
| Length | Returns the planar |
Code examples
Calculate geodesic area
This example demonstrates how to calculate the geodesic area of the Bermuda Triangle from a polygon defined in the WGS 1984 geographic coordinate system (WKID 4326). The map automatically projects the polygon for display, while the geodesic area calculation measures the geometry on the surface of a spheroid and returns the result in square kilometers.
if (!geodeticAreaOperator.isLoaded()) {
updateNotice("geodeticAreaOperator is not loaded.");
return;
}
const geoArea = geodeticAreaOperator.execute(polygon, {
unit: "square-kilometers",
}); // Area: 1,145,170.40 square kilometers.
updateNotice(
`The geodetic area of the polygon is ${intl.formatNumber(geoArea, numFormat)} km<sup>2</sup>.`
);
Calculate planar area
This example demonstrates how to calculate the planar area of country polygons. The map uses the WGS 1984 Equal Earth projected coordinate system (WKID 8857), an equal-area projection that preserves the relative areas of geographic features when they are projected. The country data is reprojected to match the map's spatial reference, allowing the planar area operator to calculate and display each country's area in square kilometers when you hover over it.
const area = areaOperator.execute(polygon, {
unit: "square-kilometers",
});
return intl.formatNumber(area, {
useGrouping: true,
maximumFractionDigits: 0,
})
Calculate geodesic length
This example demonstrates how to calculate the geodesic length of a line defined in the WGS 1984 geographic coordinate system (WKID 4326).
const length = geodeticLengthOperator.execute(line, {
unit: "kilometers",
}); // Length: 932.47 kilometers
const formattedLength = `The geodetic length of the line is ${length.toFixed(2)} kilometers.`;
console.log(formattedLength);
lengthResultUI.textContent = formattedLength;
Calculate planar length
This example shows how to label linear features with their planar length calculated in an Arcade expression. Arcade provides you with many geometry functions for measuring lengths and areas. You can also use it to perform other client-side spatial analyses.
Using planar length as opposed to geodesic length is appropriate here because the map is rendered in a State Plane coordinate system, which preserves distance and length.
labelExpressionInfo: {
expression: `
var l = Length($feature, 'feet')
Text(l, "Planar: #,### ft")
`,
},