Select to view content in your preferred language

Length is off by more than 50%: Tryin' to understand Length/Distance calculation

727
3
Jump to solution
08-09-2023 11:57 PM
Labels (1)
SokoFromNZ
Occasional Contributor

Hi guys,

After reading about the differences in SpatialReference (planar, geodesic) and transformations and a lot of try and error I've found the solution in using GeometryEngine.LengthGeodesic() instead of Length()...

Reading this helped a little, but still I'm not sure why the following is happening as I'm analysing a very small area.

I have two points which are 900 meters appart. Then I project them to Wgs84 (AngularUnit) and WebMercator (LinearUnit) with the correct transformation.

 

        var gauss2 = SpatialReference.Create(31466);
        var point1Gauss2 = new MapPoint(2548675.907, 5717625.516, gauss2);
        var point2Gauss2 = new MapPoint(2548033.679, 5718260.329, gauss2);
        var polyLineGauss2 = new Polyline(new[] { point1Gauss2, point2Gauss2 });

        var transMercator = TransformationCatalog.GetTransformation(gauss2, SpatialReferences.WebMercator);
        var point1Mercator = (MapPoint) point1Gauss2.Project(SpatialReferences.WebMercator, transMercator);
        var point2Mercator = (MapPoint) point2Gauss2.Project(SpatialReferences.WebMercator, transMercator);
        var polyLineMercator = new Polyline(new[] { point1Mercator, point2Mercator });
        var polyLineMercatorProjected = (Polyline) polyLineGauss2.Project(SpatialReferences.WebMercator, transMercator);
        
        var transWgs84 = TransformationCatalog.GetTransformation(gauss2, SpatialReferences.Wgs84);
        var point1Wgs84 = (MapPoint) point1Gauss2.Project(SpatialReferences.Wgs84, transWgs84);
        var point2Wgs84 = (MapPoint) point2Gauss2.Project(SpatialReferences.Wgs84, transWgs84);
        var polyLineWgs84 = new Polyline(new[] { point1Wgs84, point2Wgs84 });
        var polyLineWgs84Projected = (Polyline) polyLineGauss2.Project(SpatialReferences.Wgs84, transWgs84);

        var gauss2Length = polyLineGauss2.Length();
        var gauss2LengthG = polyLineGauss2.LengthGeodetic();
        
        var mercatorLength = polyLineMercator.Length();
        var mercatorLengthG = polyLineMercator.LengthGeodetic();

        var mercatorProjectedLength = polyLineMercatorProjected.Length();
        var mercatorProjectedLengthG = polyLineMercatorProjected.LengthGeodetic();

        var wgs84Length = polyLineWgs84.Length();
        var wgs84LengthG = polyLineWgs84.LengthGeodetic();

        var wgs84ProjectedLength = polyLineWgs84Projected.Length();
        var wgs84ProjectedLengthG = polyLineWgs84Projected.LengthGeodetic();

 

 

The output is:

SokoFromNZ_0-1691650168109.png

 

I quite do not understand why Length() in WebMercator gives 1452 meters (> 50% too long) while the original Gauss2 Length() is correct with 903 meters.

When I project the WebMercator points back to Gauss2 Length() gives the correct 903 meters. So it can be only an issue of the SpatialReference in itself!

So it really is the distortion described in the link above? And it is so bad?

Thanks for educating me here

Soko

0 Kudos
1 Solution

Accepted Solutions
DanPatterson
MVP Esteemed Contributor

the documentation is correct (check the web as well)... web  mercator is not a projected coordinate system that should be used for distance or area measurements... pick something else

FAQ: Why Are My Map, Distance and Area Measurements Wrong When Using WGS 1984 Web Mercator (esri.com...


... sort of retired...

View solution in original post

3 Replies
DanPatterson
MVP Esteemed Contributor

the documentation is correct (check the web as well)... web  mercator is not a projected coordinate system that should be used for distance or area measurements... pick something else

FAQ: Why Are My Map, Distance and Area Measurements Wrong When Using WGS 1984 Web Mercator (esri.com...


... sort of retired...
SokoFromNZ
Occasional Contributor

Thanks, so its just a WGS84 thing, interersting.

Do you have a suggestions which wkid I can use with a linear unit? Europe would suffice...

Maybe also have a look here 

thanks again

0 Kudos
MatveiStefarov
Esri Contributor

Length() gives you a planar length, so the result in units of the projection system.  WebMercator projection is conformal -- it preserves angles/directions between points, at the expense of distorting distances/scales.  This means that the physical length of "1 WebMercator projection unit" depends on latitude.

At the equator, 1 unit is 1 meter long.  But at the latitude that you are working at, 1 WebMercator unit = cos(51.59°) = 0.62 physical meters.  That's where the difference you see comes from.

1452.5 WebMercator units * 0.62 ≈ 902.5 meters

In general, if you care about physical distance between 2 points in the real world, you should use LengthGeodetic() instead of Length().