3

I use the field calculator to measure the length of LineStrings in my shapefile layer, but i get different results when using QGIS 2.18 or QGIS 3.0.

If I am using the local coordinate system the difference between the QGIS 2.18 and QGIS 3.0 is not significant. If I am using WGS84 (I know you should always use the local coordinate system) I get two different results based on the version I am using. In 10 km the difference is almost 2 km..

Does anyone know what might be the reason? Did the algorithm behind the length calculations change in QGIS 3?

  • 3
    Measuring in EPSG:4326 results in degrees, not meters or kilometers. Does this difference also exist when using a projected crs? – MrXsquared Dec 14 '18 at 9:34
3

The built-in functions that use a feature’s geometry (e.g. $length) for calculation use the units of the layer’s CRS. Geographic Coordinate Reference System(CRS) such as EPSG:4326 have degrees as units - so the length of the feature would be in degrees and area in square degrees - which is meaningless. You need to use a Projected Coordinate Reference System with units of meters or feet to perform such calculations.

And the algorithm behind the length calculations probably was not changed.

QGIS 2.18

 double QgsGeometry::length() const
 {
   if ( !d->geometry )
   {
     return -1.0;
   }
   QgsGeos g( d->geometry );
   return g.length();
 }

QGIS 3.2

 double QgsGeometry::length() const
 {
   if ( !d->geometry )
   {
     return -1.0;
   }
   QgsGeos g( d->geometry.get() );
   mLastError.clear();
   return g.length( &mLastError );
 }

References:

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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