Lengths

URL:
https://<root>/Utilities/Geometry/GeometryServer/lengths
Methods:
GET
Version Introduced:
9.3

Description

The lengths operation is performed on a geometry service resource. This operation calculates the 2D Euclidean or geodesic length of each polyline specified in the input array. You can provide arguments to the lengths operation as query parameters defined in the following parameters table.

Request parameters

ParameterDetails

polylines

Specifies the array of polylines whose lengths are to be computed. The spatial reference of the polylines is specified by sr. The structure of each polyline in the array is the same as the structure of the JSON polyline objects returned by ArcGIS REST API.

Syntax

Use dark colors for code blocksCopy
1
[<polyline1>, <polyline2>, ..., <polylineN>]

Example

Use dark colors for code blocksCopy
1
2
3
4
5
6
7
8
9
10
11
12
13
[
  {
    "paths": [
      [[-117,34],[-116,34],[-117,33]],
      [[-115,44],[-114,43],[-115,43]]
    ]
  },
  {
    "paths": [
      [[32.49,17.83],[31.96,17.59],[30.87,17.01],[30.11,16.86]]
    ]
  }
]

For a large set of geometries, you can specify a URL to the input geometries stored in a JSON structure in a file on a public server. The expected format of the file's contents will be the same as that expected if the polylines were directly embedded in the request.

URL-based syntax

Use dark colors for code blocksCopy
1
polylines={"url": "<URL to file>"}

URL-based example

Use dark colors for code blocksCopy
1
polylines={"url": "https://<myserver>/<mygeometries>/<afile.txt>"}

sr

Specifies the well-known ID (WKID) of the spatial reference or a spatial reference JSON object for the input polylines. For a list of valid WKID values, see Using spatial references.

lengthUnit

Specifies the unit in which the lengths of polylines are calculated. If calculationType is planar, lengthUnit can be any esriUnits constant. If calculationType is planar and lengthUnit is not specified, the units are derived from sr. If calculationType is not planar, lengthUnit must be a linear esriUnits constant such as esriSRUnit_Meter or esriSRUnit_SurveyMile. If calculationType is not planar and lengthUnit is not specified, the units are meters.

For a list of valid units, see esriSRUnitType Constants and esriSRUnit2Type Constants.

geodesic

If polylines are in a geographic coordinate system, geodesic must be set to true to calculate the ellipsoidal shortest-path distance between each pair of the vertices in the polylines. If lengthUnit is not specified, the output is returned in meters.

calculationType

Defines the length calculation for the geometry. The type can be one of the following values:

  • planar — Planar measurements use 2D Euclidean distance to calculate length. Use this type only if the length needs to be calculated in the given spatial reference. Otherwise, use preserveShape.
  • geodesic — Use this type to calculate a length using only the vertices of the polygon and define the lines between the vertices as geodesic segments independent of the actual shape of the polyline. A geodesic segment is the shortest path between two points on an earth ellipsoid.
  • preserveShape — This type calculates the length of the geometry on the surface of the earth ellipsoid. The shape of the geometry in its coordinate system is preserved.

f

The response format. The default response format is html .

Values: html | json | pjson

Example usage

The following is a sample request URL for lengths. In this example, the lengths of two input polylines are calculated. The preserveShape calculation type is used. The result unit is kilometers.

Use dark colors for code blocksCopy
1
https://sampleserver6.arcgisonline.com/ArcGIS/rest/services/Utilities/Geometry/GeometryServer/lengths?sr=4269&polylines=[{"paths":[[[-117,34],[-116,34],[-117,33]],[[-115,44],[-114,43],[-115,43]]]},{"paths":[[[32.49,17.83],[31.96,17.59],[30.87,17.01],[30.11,16.86]]]}]&lengthUnit=9036&calculationType=preserveShape&f=pjson

JSON Response syntax

Use dark colors for code blocksCopy
1
2
3
{
  "lengths": [<length1>, <length2>, ..., <lengthN>]
}

JSON Response example

Use dark colors for code blocksCopy
1
2
3
4
5
6
{
  "lengths": [
    456.04101753137257,
    277.29464412330174
  ]
}

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.