Bug report #17151

wrong vector line length calculation by $length in attribute table calculator

Added by Helmut Kudrnovsky almost 7 years ago. Updated almost 7 years ago.

Status:Closed
Priority:High
Assignee:-
Category:Attribute table
Affected QGIS version:2.18.12 Regression?:No
Operating System:windows 10 Easy fix?:Yes
Pull Request or Patch supplied:No Resolution:fixed/implemented
Crashes QGIS or corrupts data:No Copied to github as #:25050

Description

attached a line vector shape file in EPSG:31287 (https://epsg.io/31287)

vector line length calculation seems to be wrong in QGIS 2.18.12

comparison between: QGIS 2.18.12, GRASS 7.3svn and QGIS-Version 2.99.0-Master QGIS-Codeversion ba9cb873ae

v.db.select map=test_vector_length@vlengthtest                                  
cat|id|qvlength|qvlength3|vlengthgrass
1||31.6929908772|31683.5186360268|31683.518636
2||128.842829285|128802.141660603|128802.141661
3||187.2653676151|187203.580023903|187203.580024
4||20.5063076544|20500.6624186491|20500.662419
5||56.5505940728|56535.5429605752|56535.542961
6||98.8004239584|98775.9189262182|98775.918926

qvlength => calculated by QGIS 2.18.12
qvlength3 => calculated by QGIS-Version 2.99.0-Master
vlengthgrass => calculated by GRASS 7.3.svn

line length is in meters.

qvlength3 and vlengthgrass are the same, but regarding qvlength calculated by 2.18.12 seems to wrong.

attached is the related shapefile and a spatialite db exported by GRASS, both with the length values in the attribute table.

tested with:
----
QGIS version
2.18.12
QGIS code revision
a6c461b
Compiled against Qt
4.8.5
Running against Qt
4.8.5
Compiled against GDAL/OGR
2.2.1
Running against GDAL/OGR
2.2.1
Compiled against GEOS
3.5.0-CAPI-1.9.0
Running against GEOS
3.5.0-CAPI-1.9.0 r4084
PostgreSQL Client Version
9.2.4
SpatiaLite Version
4.3.0
QWT Version
5.2.3
PROJ.4 Version
493
QScintilla2 Version
2.7.2

test_vector_length.zip (2.08 KB) Helmut Kudrnovsky, 2017-09-15 10:58 PM

test_vector_length_grass.zip (389 KB) Helmut Kudrnovsky, 2017-09-15 10:58 PM

vlength_epsg3035.zip (2.47 KB) Helmut Kudrnovsky, 2017-09-16 09:41 AM

testline_epsg31254.zip (2.68 KB) Helmut Kudrnovsky, 2017-09-18 01:11 PM

History

#1 Updated by Helmut Kudrnovsky almost 7 years ago

Helmut Kudrnovsky wrote:

attached a line vector shape file in EPSG:31287 (https://epsg.io/31287)

vector line length calculation seems to be wrong in QGIS 2.18.12

it seems that the decimal point is shifted.

#2 Updated by Helmut Kudrnovsky almost 7 years ago

Helmut Kudrnovsky wrote:

attached a line vector shape file in EPSG:31287 (https://epsg.io/31287)

vector line length calculation seems to be wrong in QGIS 2.18.12

now tested with another projection (EPSG:3035) - test shapefile attached.

the line length are for test case from ~10m up to ~1254830m

vlength3        vlength2
11.9809053481        0.0119809053
20.5154479097        0.0205154479
34.1924131816        0.0341924132
48.4426040881        0.0484426041
84.0983546768        0.0840983547
168.8711406481        0.1688711406
269.9793624986        0.2699793625
329.6264100979        0.3296264101
422.1590048316        0.4221590048
1260.8220223604        1.2608220224
2997.1665069434        2.9971665069
5805.2376357774        5.8052376358
29350.800049287        29.3508000493
111646.269300223    111.6462693002
207864.02027185        207.8640202719
303161.374344716    303.1613743447
790590.141646461    790.5901416465
1254830.64894956    1254.8306489496

vlength2 calculated by QGIS 2.18.12
vlength3 calculated by QGIS QGIS-Version 2.99.0-Master

also in this projection there seems to be an unwanted shift of the decimal point.

#3 Updated by Giovanni Manghi almost 7 years ago

  • Status changed from Open to Feedback

Just tried on both Linux and Windows 7 with 2.18.12 and I get the right values.

#4 Updated by Helmut Kudrnovsky almost 7 years ago

Giovanni Manghi wrote:

Just tried on both Linux and Windows 7 with 2.18.12 and I get the right values.

thanks for testing.

in OSGeo4W there is now QGIS 2.18.13 available.

QGIS version
2.18.13
QGIS code revision
8cba0bb9eb
Compiled against Qt
4.8.5
Running against Qt
4.8.5
Compiled against GDAL/OGR
2.2.1
Running against GDAL/OGR
2.2.1
Compiled against GEOS
3.5.0-CAPI-1.9.0
Running against GEOS
3.5.0-CAPI-1.9.0 r4084
PostgreSQL Client Version
9.2.4
SpatiaLite Version
4.3.0
QWT Version
5.2.3
PROJ.4 Version
493
QScintilla2 Version
2.7.2

tested it with another vector shape in EPSG 31254 and compared it to QGIS 2.99.:

vlenqgs213    vlengqgs3
7.4098756    7409.9628946
23.7302064    23730.4588719
19.5467015    19546.9312967
32.6276445    32627.8490494
2.3586266    2358.6796179
0.8076811    807.708901
7.6789837    7679.2103411
3.2085795    3208.6738047
38.5676211    38568.1000222
1.0096307    1009.6361262
0.364028    364.0294823
0.5436955    543.7056935
14.0659768    14066.3523728
10.7428602    10743.0602009
11.028371    11028.4584316

still the issue. very strange.

any idea what's going on? any idea what to test?

#5 Updated by Nyall Dawson almost 7 years ago

Check your project distance unit setting - I suspect this is affecting the result.

#6 Updated by Helmut Kudrnovsky almost 7 years ago

Nyall Dawson wrote:

Check your project distance unit setting - I suspect this is affecting the result.

my workflow is:

  • start qgis 2.18.13
  • load shapefile in EPSG:31254
  • check in project properties: Selected CRS: MGI / Austria GK West (+proj=tmerc +lat_0=0 +lon_0=10.33333333333333 +k=1 +x_0=0 +y_0=-5000000 +ellps=bessel +towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232 +units=m +no_defs)
  • open attribute table to edit
  • add Decimal number column
  • calculate length by $length in the new column

where do I check project distance unit settings elsewhere than in the project properties?

#7 Updated by Helmut Kudrnovsky almost 7 years ago

Helmut Kudrnovsky wrote:

Nyall Dawson wrote:

Check your project distance unit setting - I suspect this is affecting the result.

my workflow is:

  • start qgis 2.18.13
  • load shapefile in EPSG:31254
  • check in project properties: Selected CRS: MGI / Austria GK West (+proj=tmerc +lat_0=0 +lon_0=10.33333333333333 +k=1 +x_0=0 +y_0=-5000000 +ellps=bessel +towgs84=577.326,90.129,463.919,5.137,1.474,5.297,2.4232 +units=m +no_defs)
  • open attribute table to edit
  • add Decimal number column
  • calculate length by $length in the new column

where do I check project distance unit settings elsewhere than in the project properties?

ok I've found it: something has changed in Settings -> Options -> MapTools -> Measure tool -> preferred distance units from meters to kilometers.

changing back to meters, calculations are ok.

thanks to Werner to help identifying the issue.

closing ticket.

though from a user point of view, I wouldn't assume, that I change in the manual measuring tool by going over Configuration the whole behaviour of length calculation.

#8 Updated by Werner Macho almost 7 years ago

  • Resolution set to fixed/implemented
  • Status changed from Feedback to Closed
  • Crashes QGIS or corrupts data changed from Yes to No
  • Regression? changed from Yes to No
  • Easy fix? changed from No to Yes

Problem solved by choosing default Settings in "Project Properties" AND "Settings -> Options -> Map Tools -> Measure Tool"

Also available in: Atom PDF