import { geodesicAreas, geodesicLengths, geodesicDensify, geodesicDistance, pointFromDistance } from "@arcgis/core/geometry/support/geodesicUtils.js";const { geodesicAreas, geodesicLengths, geodesicDensify, geodesicDistance, pointFromDistance } = await $arcgis.import("@arcgis/core/geometry/support/geodesicUtils.js");- Since
- ArcGIS Maps SDK for JavaScript 4.12
This class performs geodetic computations for Earth and 70+ non-Earth spheroids. Methods include geodesic length, area, point-distance and point-to-point computations.
- See also
Functions
| Name | Return Type | Object |
|---|---|---|
geodesicAreas deprecated | number[] | |
geodesicLengths deprecated | number[] | |
geodesicDensify deprecated | | |
geodesicDistance deprecated | | |
pointFromDistance deprecated | | |
InverseGeodeticSolverResult deprecated | | |
geodesicAreas
Geodetically computes the area for one or more polygons.
- Signature
-
geodesicAreas (polygons: Polygon[], unit?: AreaUnit): number[]
Parameters
- Returns
- number[]
An array of areas corresponding to the source polygons.
Example
// Display the area of the Bermuda Triangle.const MIAMI = { lat: 25.775278, lon: -80.208889 }; // Floridaconst HAMILTON = { lat: 32.293, lon: -64.782 }; // Bermudaconst SANJUAN = { lat: 18.406389, lon: -66.063889 }; // Puerto Ricoconst polygon = new Polygon({ rings: [[ [MIAMI.lon, MIAMI.lat], [HAMILTON.lon, HAMILTON.lat], [SANJUAN.lon, SANJUAN.lat], [MIAMI.lon, MIAMI.lat] ]]});const areas = geodesicUtils.geodesicAreas([polygon], "square-kilometers");const area = Math.round(areas[0]);console.log("Area: ", area, " km²"); // Area: 1150498 km² geodesicLengths
Geodetically computes polygon perimeter or polyline length for one or more geometries.
- Signature
-
geodesicLengths (geometries: Polyline[] | Polygon[], unit?: LengthUnit): number[]
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| geometries | The input polylines or polygons. | | |
| unit | = "meters" - Output linear units. | |
- Returns
- number[]
An array of lengths/perimeters corresponding to the input geometries.
Example
// Display the perimeter of the Bermuda Triangle.const MIAMI = { lat: 25.775278, lon: -80.208889 }; // Floridaconst HAMILTON = { lat: 32.293, lon: -64.782 }; // Bermudaconst SANJUAN = { lat: 18.406389, lon: -66.063889 }; // Puerto Ricoconst polygon = new Polygon({ rings: [[ [MIAMI.lon, MIAMI.lat], [HAMILTON.lon, HAMILTON.lat], [SANJUAN.lon, SANJUAN.lat], [MIAMI.lon, MIAMI.lat] ]]});const perimeters = geodesicUtils.geodesicLengths([polygon], "kilometers");const perimeter = Math.round(perimeters[0]);console.log("Perimeter: ", perimeter, " km"); // Perimeter: 4879 km geodesicDensify
Computes and returns a densified polyline or polygon.
- Signature
-
geodesicDensify (geometry: Polygon | Polyline, maxSegmentLength: number): Polygon | Polyline
Parameters
Example
// Densify the polygon representing Bermuda Triangle with maximum segment size of 100km.const MIAMI = { lat: 25.775278, lon: -80.208889 }; // Floridaconst HAMILTON = { lat: 32.293, lon: -64.782 }; // Bermudaconst SANJUAN = { lat: 18.406389, lon: -66.063889 }; // Puerto Ricoconst polygon = new Polygon({ rings: [[ [MIAMI.lon, MIAMI.lat], [HAMILTON.lon, HAMILTON.lat], [SANJUAN.lon, SANJUAN.lat], [MIAMI.lon, MIAMI.lat] ]]});const densifiedPolygon = geodesicUtils.geodesicDensify(polygon, 100000);const vertexCountBefore = polygon.rings[0].length;const vertexCountAfter = densifiedPolygon.rings[0].length;console.log("Before: ", vertexCountBefore, ", After: ", vertexCountAfter); // Before: 4, After: 51 geodesicDistance
Geodetically computes the direction and distance between two known locations. Both input points must have the same geographic coordinate system.
- Signature
-
geodesicDistance (from: Point, to: Point, unit?: LengthUnit): InverseGeodeticSolverResult
Parameters
| Parameter | Type | Description | Required |
|---|---|---|---|
| from | The origin location. | | |
| to | The destination location. | | |
| unit | = "meters" - Output linear units. | |
- Returns
- InverseGeodeticSolverResult
Computed distance and direction between the two known locations.
Name Type Description distance number The distance between the two locations. azimuth number The azimuth (or "bearing") in degrees. Values range from 0° to 360°. reverseAzimuth number The reverse azimuth in degrees. Values range from 0° to 360°.
Example
// Display the distance and direction between Los Angeles and New York City.const LA = { latitude: 34.05, longitude: -118.25};const NY = { latitude: 40.7127, longitude: -74.0059};const join = geodesicUtils.geodesicDistance( new Point({ x: LA.longitude, y: LA.latitude }), new Point({ x: NY.longitude, y: NY.latitude }), "kilometers");const { distance, azimuth } = join;console.log("Distance: ", distance, ", Direction: ", azimuth); pointFromDistance
Geodetically computes the location at a defined distance and direction from a known location.
- Signature
-
pointFromDistance (point: Point, distance: number, azimuth: number): Point
Parameters
- Returns
- Point
The computed point.
Example
// Display the location of a point 10km East of Los Angeles.const LA = { latitude: 34.05, longitude: -118.25};const destination = geodesicUtils.pointFromDistance( new Point({ x: LA.longitude, y: LA.latitude }), 10000, 90);const { latitude, longitude } = destination;console.log("Latitude: ", latitude, ", Longitude: ", longitude);