ArcGIS Pro 3.2 API Reference Guide
ArcGIS.Core.Geometry Namespace / IGeometryEngine Interface / GeodesicLength Method / GeodesicLength(Geometry) Method
The input geometry. Cannot be null and its spatial reference cannot be null.
Example

In This Topic
    GeodesicLength(Geometry) Method
    In This Topic
    Gets the geodesic length of the input geometry.
    Syntax
    double GeodesicLength( 
       Geometry geometry
    )
    Overloads Function GeodesicLength( _
       ByVal geometry As Geometry _
    ) As Double

    Parameters

    geometry
    The input geometry. Cannot be null and its spatial reference cannot be null.

    Return Value

    The calculated geodesic length 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.
    Spatial reference of geometryis an image coordinate system.
    Remarks
    Geodesic length is calculated by using only the vertices of the geometry and defining the segments between the points as geodesic segments independent of the actual shape of the geometry. A geodesic segment is the shortest path between two points on an ellipsoid. For example, if you have a closed polyline with only two vertices that represents the equator, the length returned will be zero.
    Example
    Determine geodesic length of a line
    var polyline = PolylineBuilderEx.CreatePolyline(new[]
    {
        MapPointBuilderEx.CreateMapPoint(-10018754.1713946, 10018754.1713946),
        MapPointBuilderEx.CreateMapPoint(10018754.1713946, 10018754.1713946)
    }, SpatialReferences.WebMercator);
    
    var length = GeometryEngine.Instance.GeodesicLength(polyline);
    // length is approx 5243784.5551844323 in meters
    
    length = GeometryEngine.Instance.GeodesicLength(polyline, LinearUnit.Miles);
    // length is approx 3258.33666089067 in miles
    
    var polyline2 = GeometryEngine.Instance.Project(polyline, SpatialReferences.WGS84);
    length = GeometryEngine.Instance.GeodesicLength(polyline2);
    // length is approx 5243784.55518443 in meters after projecting
    
    GeodeticDensifyByLength - polygon
    List<Coordinate2D> coords = new List<Coordinate2D>()
    {
      new Coordinate2D(-80, 0),
      new Coordinate2D(-20, 60),
      new Coordinate2D(40, 20),
      new Coordinate2D(0, -20),
      new Coordinate2D(-80, 0)
    };
    
    SpatialReference sr = SpatialReferences.WGS84;
    
    // create a polygon
    Polygon polygon = PolygonBuilderEx.CreatePolygon(coords, sr);
    
    // get the geodesic lengths of the polygon segments
    ReadOnlySegmentCollection segments = polygon.Parts[0];
    List<Double> geoLengths = new List<Double>(segments.Count);
    foreach (Segment s in segments)
    {
      Polyline line = PolylineBuilderEx.CreatePolyline(s, sr);
      double geoLen = GeometryEngine.Instance.GeodesicLength(line);
      geoLengths.Add(geoLen);
    }
    
    // find the max length
    geoLengths.Sort();
    double maxLen = geoLengths[geoLengths.Count - 1];
    
    // densify the polygon (in meters)
    Polygon densifiedPoly = GeometryEngine.Instance.GeodeticDensifyByLength(polygon, maxLen, LinearUnit.Meters, GeodeticCurveType.Geodesic) as Polygon;
    
    // densify the polygon (in km)
    double maxSegmentLength = maxLen / 10000;
    densifiedPoly = GeometryEngine.Instance.GeodeticDensifyByLength(polygon, maxSegmentLength, LinearUnit.Kilometers, GeodeticCurveType.Geodesic) as Polygon;
    
    Requirements

    Target Platforms: Windows 11, Windows 10

    ArcGIS Pro version: 3 or higher.
    See Also