ArcGIS Pro 3.3 API Reference Guide
ArcGIS.Core.Geometry Namespace / IGeometryEngine Interface / ShapePreservingLength Method / ShapePreservingLength(Geometry,LinearUnit) Method
The input geometry. Cannot be null and its spatial reference cannot be null.
The unit of the output length. If null, then the length is in meters.
Example

In This Topic
    ShapePreservingLength(Geometry,LinearUnit) Method
    In This Topic
    Calculates the length of the geometry on the surface of the Earth ellipsoid. This method preserves the shape of the geometry in its coordinate system.
    Syntax
    double ShapePreservingLength( 
       Geometry geometry,
       LinearUnit lengthUnit
    )
    Overloads Function ShapePreservingLength( _
       ByVal geometry As Geometry, _
       ByVal lengthUnit As LinearUnit _
    ) As Double

    Parameters

    geometry
    The input geometry. Cannot be null and its spatial reference cannot be null.
    lengthUnit
    The unit of the output length. If null, then the length is in meters.

    Return Value

    Shape preserving length of the geometry in lengthUnit. If lengthUnit is null, then the shape preserving length is in meters.

    If the geometry is empty, then zero is returned.

    Exceptions
    ExceptionDescription
    Geometry is null or geometry's spatial reference is null.
    The method is not implemented for GeometryBag or Multipatch.
    Geometry is missing a spatial reference.
    Spatial reference of geometryis an image coordinate system.
    Remarks
    This method preserves the shape of the geometry in its coordinate system. In other words, the length will be calculated for the geometry you see in the map. For example, if you have a polyline with only two vertices that represents the equator, the length returned will be the length of the equator.
    Example
    Calculate length of geometry on surface of Earth's ellipsoid - ShapePreservingLength
    // pt
    MapPoint pt = MapPointBuilderEx.CreateMapPoint(1.0, 3.0, SpatialReferences.WebMercator);
    double len = GeometryEngine.Instance.ShapePreservingLength(pt);          // len = 0
    
    List<MapPoint> pts = new List<MapPoint>();
    pts.Add(MapPointBuilderEx.CreateMapPoint(1.0, 1.0, 3.0));
    pts.Add(MapPointBuilderEx.CreateMapPoint(1.0, 3.0, 3.0));
    pts.Add(MapPointBuilderEx.CreateMapPoint(3, 3, 3.0));
    pts.Add(MapPointBuilderEx.CreateMapPoint(3.0, 1.0, 3.0));
    
    // multipoint
    Multipoint mPt = MultipointBuilderEx.CreateMultipoint(pts);
    len = GeometryEngine.Instance.ShapePreservingLength(mPt);                // len = 0
    
    // polyline
    Polyline polyline = PolylineBuilderEx.CreatePolyline(pts, SpatialReferences.WGS84);
    len = GeometryEngine.Instance.ShapePreservingLength(polyline);
    
    // polygon
    Polygon polygon = PolygonBuilderEx.CreatePolygon(pts, SpatialReferences.WGS84);
    len = GeometryEngine.Instance.ShapePreservingLength(polygon);
    
    
    
    polyline = PolylineBuilderEx.CreatePolyline(new[]
    {
        MapPointBuilderEx.CreateMapPoint( -170, 0),
        MapPointBuilderEx.CreateMapPoint( 170, 0)
    }, SpatialReferences.WGS84);
    
    
    var length_meters = GeometryEngine.Instance.ShapePreservingLength(polyline); // , LinearUnits.Meters);
    var length_miles = GeometryEngine.Instance.ShapePreservingLength(polyline, LinearUnit.Miles);
    
    // length_meters - 37848626.869713023
    // length_miles - 23518.046402579574
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also