Bug report #22105

$length return bad value

Added by Ludovic JACQUET almost 5 years ago. Updated almost 5 years ago.

Status:Closed
Priority:Normal
Assignee:Alessandro Pasotti
Category:Geometry
Affected QGIS version:3.6.1 Regression?:Yes
Operating System:Windows 10 home 64 Easy fix?:No
Pull Request or Patch supplied:No Resolution:worksforme
Crashes QGIS or corrupts data:No Copied to github as #:29918

Description

On QGIS 3.6.1 when I use $length for obtain the length value, QGIS return a bad value.
After a return of a customer who is surprise by the length I test my SHP with QGIS 2.8 and FME workbench 2016. I have the same length whith FME, QGIS 2.8 and customer software.

RESEAU.dbf (21.6 KB) Ludovic JACQUET, 2019-05-20 12:17 PM

RESEAU.prj (449 Bytes) Ludovic JACQUET, 2019-05-20 12:17 PM

RESEAU.shp (11.9 KB) Ludovic JACQUET, 2019-05-20 12:17 PM

RESEAU.shx (636 Bytes) Ludovic JACQUET, 2019-05-20 12:17 PM

RESEAU.dbf (23.8 KB) Ludovic JACQUET, 2019-05-20 02:01 PM

RESEAU.prj (449 Bytes) Ludovic JACQUET, 2019-05-20 02:01 PM

RESEAU.shx (636 Bytes) Ludovic JACQUET, 2019-05-20 02:01 PM

RESEAU.shp (11.9 KB) Ludovic JACQUET, 2019-05-20 02:01 PM

History

#1 Updated by Ludovic JACQUET almost 5 years ago

On .dbf file LONG_GEO is the value obtain with FME.

#2 Updated by Alessandro Pasotti almost 5 years ago

  • Assignee set to Alessandro Pasotti

#3 Updated by Alessandro Pasotti almost 5 years ago

  • Resolution set to worksforme
  • Status changed from Open to Closed

You don't say what "bad value" means to you so I'm just guessing here.

Btw, I tested this on master and I think that the small difference between the FME length and QGIS length is that by default the QGIS algorithm makes a calculation on WGS84 ellipsoidal disatance instead of a simple cartesian distance.

The cartesian distance, rounded to 2 decimal places is exactly the same that you have in LONG_GEO and it is always smaller than the WGS84 ellipsoidal distance, as expected.

Click on identify and then on "Derived" to see what I mean (the results of both algorithms).

#4 Updated by Ludovic JACQUET almost 5 years ago

OK I discover parameter for change the ellipsoidal WGS84 to none on project option.

#5 Updated by Alessandro Pasotti almost 5 years ago

IIRC, 2.18 did not make ellipsoid length calculations by default but it used planimetric distance, that's why you see the difference now (btw, that's not an error, it's a different algorithm to calculate distances).

From the documentation of $length:

Returns the length of a linestring. If you need the length of a border of a polygon, use $perimeter instead. The length calculated by this function respects both the current project's ellipsoid setting and distance unit settings. For example, if an ellipsoid has been set for the project then the calculated length will be ellipsoidal, and if no ellipsoid is set then the calculated length will be planimetric.

#6 Updated by Alessandro Pasotti almost 5 years ago

For your information, you can get the planimetric length with this expression (you can add a virtual field to verify):

length( $geometry )

Also available in: Atom PDF