Bug report #10679

$length is always in degrees, even if i select another projection

Added by baditaflorin - over 6 years ago. Updated over 6 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:-
Affected QGIS version:2.2.0 Regression?:No
Operating System:Windows Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:19077

Description

I am trying to calculate the total length of of the roads in Romania.

I have saved the shp file as the projection 31700 ( Stereo1970 - Dealul Piscului )

I have exited and entered again. When i set the layer to editable and i go to the new bar field calculator in Qgis 2.3, i get the length as a part of one degree, per example 0.0004953245

The reason i choose the 31700 projection is because the ratio is exactly one meter. So if i have a 12 meters road, i will get 12 meters.

I also tried with sum line length but for the 440.000 ways that romania osm extract have, and i get a Not Responding on a 8 GB, Quad Core configuration.

I also tried with Group Stats Plugin but this also return the values in degrees

I also tried this python example from http://woostuff.wordpress.com/2011/02/23/total-length-of-selected-objects-qgis-via-python/

with shapely installed, but is seems not to work

from shapely.wkb import loads
def getLength():
    layer = qgis.utils.iface.mapCanvas().currentLayer()
    total = 0
    for feature in layer.selectedFeatures():
        geom = feature.geometry()
        wkb = geom.asWkb()
        line = loads(wkb)
        total = total + line.length
    return total

print getLength()

i get

File "<input>", line 11
    print
        ^
SyntaxError: invalid syntax 

wrong_lenght.png (61.8 KB) baditaflorin -, 2014-06-23 11:41 AM

sum_line_lenght.png (25.8 KB) baditaflorin -, 2014-06-23 11:41 AM

is_this_a_bug.png (226 KB) baditaflorin -, 2014-06-23 11:41 AM

wsg84.png (67.8 KB) baditaflorin -, 2014-06-24 02:14 AM

after_i_hit_ok_i_see_like_this.png (225 KB) baditaflorin -, 2014-06-24 02:14 AM

History

#1 Updated by Matthias Kuhn over 6 years ago

  • Status changed from Open to Feedback

Is On The Fly CRS tranformation (OTF) enabled?
And what is the CRS definition of your project?

#2 Updated by baditaflorin - over 6 years ago

After searching the whole internet, i was able to find it with this not so intuitive Project properties, i set to meters and the project to wsg84 and is working

But after i hit ok, when i go the next time in Project properties i see non/planimetric even if i configured wsg84

But the lenght gets calculated in meters

#3 Updated by Giovanni Manghi over 6 years ago

  • Resolution set to invalid
  • Status changed from Feedback to Closed

baditaflorin - wrote:

After searching the whole internet, i was able to find it with this not so intuitive Project properties, i set to meters and the project to wsg84 and is working

But after i hit ok, when i go the next time in Project properties i see non/planimetric even if i configured wsg84

But the lenght gets calculated in meters

I just tested with your data (Romania OSM, right?) and see no issue on QGIS master:

If I save the roads to CRS 31700 (form WGS84 as they are in origin) then computations are in meters (both in Field Calculator and the plugins as Group Stats).

Such computations are always in layers units, the fact you may have OTFR on (to reptoject a layer in a geographic CRS into a projected one) is not taken into account.

#4 Updated by Giovanni Manghi over 6 years ago

please reopen if I got the issue the wrong way.

Also available in: Atom PDF