4

I use QGIS for a hobby project on American historical railroads. When digitizing a quite short section of railroad line, giving a polyline feature in a shapefile, QGIS gives two values for the line length: "cartesian" vs. "ellipsoidal". The "Cartesian" length is 4.230 miles and the "ellipsoidal" length is 3.209 miles. The Official Guide for the Railroads from 1923 gives the length as 3.2 miles, so the "ellipsoidal" length is correct for me.

Why is the "Cartesian" length a mile longer? What use is the "Cartesian" length for?

I found the first answer to this question, which states, that "cartesian" distance is calculated on a flat plane, but that implies that the "cartesian" distance should be slightly smaller than the "ellipsoidal" one, which it is not.

1
  • 5
    Cartesian distance is calculated in the units of the coordinate system. For example web Mercator EPSG:3857 has great distortion in scales near the poles and cartesian method does not care about that. You'd get also different Cartesian area if you reproject the geometry into another coordinate system. Ellipsoidal method is following the shape of Earth everywhere.
    – user30184
    Commented Jan 24, 2022 at 6:55

1 Answer 1

1

The problem is with the CRS of the base layer of my project, Web-Mercator EPSG:3857. This CRS has meter as unit. This means that the point coordinates of my feature are meters, for the x value the distance from the Greenwich Meridian measured along the equator, and for the y value the distance along the local meridian measured from the equator.

This implies that these coordinates should not be used for distance measurements, unless you are in places like Equador, Cameroon or Borneo. In the USA, or Europe, you will find, that the y coordinate diff is precise, but the x coordinate diff is wildly too long. It should at least be multiplied by the cosine of the local latitude to have any reasonable validity.

This is pretty exactly what the "ellipsoid" distance calculates. IMHO, the QGS Python documentation should point this out more clearly in the discussions about the distance calculator QgsDistanceArea. In fact, the "ellipsoid" calculation transforms the input points to lon,lat coordinates, calculates the great-circle curve between them, and measures that curve in terms of the ellipsoid, in display units (meters in this case).

I tried to clarify this in more detail to explain the base problem, which is why the "cartesian" distance of my example is a full mile longer than the "ellipsoid" distance. I realise that this answer is a paraphrase of user30184's comment above.

The data of my experiment: Location: Cowansburg, PA 11.5 miles WSW of Greensburg, PA, USA Railroad line: Cowansburg - Greensburg, Pennsylvania Railroad


Feature coordinates in EPSG:3857

  #        x                y
  0        -8878226.1285    4903036.6079
  1        -8878158.6597    4903096.1392
  ...      ...              ...

Coordinate differences between points 1 and 0

           67.4688          59.5313

Cartesian distance EPSG:3857:  89.978 meters

Feature coordinates in WGS84 as per pyproj.Proj('EPSG:3857') inverse
rounded for 1 cm projected precision

  #        x             y
  0        -79.754462    40.254787
  1        -79.753856    40.255195
  ...      ...                   ...

Ellipsoid distance WGS84: 68.648 meters

The ellipsoid distance was calculated in QGIS by a Python instance of QgsDistanceArea, properly configured with Project ellipsoid and, very important, with the CRS of the "rails" line layer, and the transform context of the Project. I spent a full day trying to understand the ridiculous values the calculator gave me, when I did not know that the project transformContext was essential. Another point for the Python Documentation project. I used the measureLine method on two QgsPointXY instances with the above coordinates.

2
  • Good work. Is there any chance that you can add a graphic or screenshot to your answer that will illustrate what you described? Also, is your problem limited to just EPSG:3857, or all CRSs? Finally, can you draw some conclusions, such as "Here's when to use Cartesian, and here's when to use ellipsoid".
    – Stu Smith
    Commented Jan 26, 2022 at 16:10
  • @StuSmith: the problem is related to the Mercator Projection. Cartesian calculations are performed on the virtual map cylinder which is "way out in space". Modern Transverse Mercator uses a small cylinder touching the poles, so that the x value is precise, and the y error minimal. The old geographers of the USGS solved the problem by using the Polyconic Projection, which attributes each map its own dedicated little map plane. Commented Jan 26, 2022 at 17:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.