Bug report #22105
$length return bad value
|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|
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.
#3 Updated by Alessandro Pasotti 3 months 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).
#5 Updated by Alessandro Pasotti 3 months 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.