QgsGeometry.length() giving wrong result?Is it possible to programmatically add calculated fields?Calculate line lengths with Python in QGISWhy can't I multiply values from column named 'length' using field calculator via PyQGIS?Why would having a reference string “boh@10” cause a crash?new vector layer's field based on other layers attributes - “for”cycle errorCalculate Expression with Python?how to get first and last point of MultiLineString-objects in qgis3Adding new field with expression in pyqgis
What's the point of fighting monsters in Zelda BotW?
Inspiration for failed idea?
Why does the weaker C–H bond have a higher wavenumber than the C=O bond?
Why might one *not* want to use a capo?
How to handle inventory and story of a player leaving
How does attacking during a conversation affect initiative?
Why is "I let him to sleep" incorrect (or is it)?
Was the six engine Boeing-747 ever seriously considered by Boeing?
How did medieval manors handle population growth? Were there room for more fields to be ploughed?
Drawing probabilities on a simplex in TikZ
Notice period 60 days but I need to join in 45 days
Why is there not a willingness from the world to step in between Pakistan and India?
Can I lend a small amount of my own money to a bank at the federal funds rate?
Another "Ask One Question" Question
Are there any to-scale diagrams of the TRAPPIST-1 system?
In Endgame, wouldn't Stark have remembered Hulk busting out of the stairwell?
Why can't you say don't instead of won't?
Can a network vulnerability be exploited locally?
Is allowing Barbarian features to work with Dex-based attacks imbalancing?
Is this position a forced win for Black after move 14?
How do you say "half the time …, the other half …" in German?
Normalized Malbolge to Malbolge translator
Group riding etiquette
How do Barton (Hawkeye/Ronin) and Romanov (Black Widow) end up on the Benatar on Morag in 2014?
QgsGeometry.length() giving wrong result?
Is it possible to programmatically add calculated fields?Calculate line lengths with Python in QGISWhy can't I multiply values from column named 'length' using field calculator via PyQGIS?Why would having a reference string “boh@10” cause a crash?new vector layer's field based on other layers attributes - “for”cycle errorCalculate Expression with Python?how to get first and last point of MultiLineString-objects in qgis3Adding new field with expression in pyqgis
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a vector layer with Multilinestrings and used the field calculator to add a field ("length") with the calculated $length of each feature. I know the field values are correct. Now, if I calculate the length of the features with PyQGIS, I get different, wrong results. Does anybody know, what could be the reason? I don't know where to start looking for the error.
Code example:
layer = iface.activeLayer()
feature = next(layer.getFeatures())
print(feature.geometry().length() / feature['length'])
Result: 1.67
pyqgis qgis-3
add a comment |
I have a vector layer with Multilinestrings and used the field calculator to add a field ("length") with the calculated $length of each feature. I know the field values are correct. Now, if I calculate the length of the features with PyQGIS, I get different, wrong results. Does anybody know, what could be the reason? I don't know where to start looking for the error.
Code example:
layer = iface.activeLayer()
feature = next(layer.getFeatures())
print(feature.geometry().length() / feature['length'])
Result: 1.67
pyqgis qgis-3
add a comment |
I have a vector layer with Multilinestrings and used the field calculator to add a field ("length") with the calculated $length of each feature. I know the field values are correct. Now, if I calculate the length of the features with PyQGIS, I get different, wrong results. Does anybody know, what could be the reason? I don't know where to start looking for the error.
Code example:
layer = iface.activeLayer()
feature = next(layer.getFeatures())
print(feature.geometry().length() / feature['length'])
Result: 1.67
pyqgis qgis-3
I have a vector layer with Multilinestrings and used the field calculator to add a field ("length") with the calculated $length of each feature. I know the field values are correct. Now, if I calculate the length of the features with PyQGIS, I get different, wrong results. Does anybody know, what could be the reason? I don't know where to start looking for the error.
Code example:
layer = iface.activeLayer()
feature = next(layer.getFeatures())
print(feature.geometry().length() / feature['length'])
Result: 1.67
pyqgis qgis-3
pyqgis qgis-3
edited Aug 16 at 20:35
PolyGeo♦
54.9k17 gold badges86 silver badges258 bronze badges
54.9k17 gold badges86 silver badges258 bronze badges
asked Aug 16 at 10:53
lueholueho
1309 bronze badges
1309 bronze badges
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
The $length
expression function states that
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.
QgsGeometry.length
on the other hand says
Returns the length of geometry using GEOS
Sadly this is not very helpful if you don't know what GEOS means. GEOS is the underlying geometry engine and it has no idea about coordinate systems, ellipsoids and all that spatial stuff. It is purely about geometry. This means QgsGeometry.length
will consider all coordinate values of the geometry as flat cartesian coordinates. You might know they are geographic/ellipsoidal, GEOS does not.
If you are in a length-preserving projection with meaningful units (meters), the result will (almost) be the measurement as if done in the real world. But in all other cases, the results from this function are rather useless.
add a comment |
Your layer's coordinate system is probably a Geographic one (meaning Ellipsoidal here), therefore the distance calculated in degree dimension. To solve this issue, first you have to a pick a proper Projected coordinate system, and save the layer in that coordinate system (Save as, change CRS).
You can find a proper Projected coordinate system at https://epsg.io, e.g. search for your country.
After the projection, the lenght() method's result will be fine.
I sure hope that QGIS provides functions for calculating "true" lengths without having to reproject manually.
– bugmenot123
Aug 16 at 13:19
Maybe try it...
– pnz
Aug 18 at 19:45
Yes, see QgsDistanceArea class
– ndawson
Aug 20 at 18:46
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "79"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f332179%2fqgsgeometry-length-giving-wrong-result%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
The $length
expression function states that
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.
QgsGeometry.length
on the other hand says
Returns the length of geometry using GEOS
Sadly this is not very helpful if you don't know what GEOS means. GEOS is the underlying geometry engine and it has no idea about coordinate systems, ellipsoids and all that spatial stuff. It is purely about geometry. This means QgsGeometry.length
will consider all coordinate values of the geometry as flat cartesian coordinates. You might know they are geographic/ellipsoidal, GEOS does not.
If you are in a length-preserving projection with meaningful units (meters), the result will (almost) be the measurement as if done in the real world. But in all other cases, the results from this function are rather useless.
add a comment |
The $length
expression function states that
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.
QgsGeometry.length
on the other hand says
Returns the length of geometry using GEOS
Sadly this is not very helpful if you don't know what GEOS means. GEOS is the underlying geometry engine and it has no idea about coordinate systems, ellipsoids and all that spatial stuff. It is purely about geometry. This means QgsGeometry.length
will consider all coordinate values of the geometry as flat cartesian coordinates. You might know they are geographic/ellipsoidal, GEOS does not.
If you are in a length-preserving projection with meaningful units (meters), the result will (almost) be the measurement as if done in the real world. But in all other cases, the results from this function are rather useless.
add a comment |
The $length
expression function states that
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.
QgsGeometry.length
on the other hand says
Returns the length of geometry using GEOS
Sadly this is not very helpful if you don't know what GEOS means. GEOS is the underlying geometry engine and it has no idea about coordinate systems, ellipsoids and all that spatial stuff. It is purely about geometry. This means QgsGeometry.length
will consider all coordinate values of the geometry as flat cartesian coordinates. You might know they are geographic/ellipsoidal, GEOS does not.
If you are in a length-preserving projection with meaningful units (meters), the result will (almost) be the measurement as if done in the real world. But in all other cases, the results from this function are rather useless.
The $length
expression function states that
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.
QgsGeometry.length
on the other hand says
Returns the length of geometry using GEOS
Sadly this is not very helpful if you don't know what GEOS means. GEOS is the underlying geometry engine and it has no idea about coordinate systems, ellipsoids and all that spatial stuff. It is purely about geometry. This means QgsGeometry.length
will consider all coordinate values of the geometry as flat cartesian coordinates. You might know they are geographic/ellipsoidal, GEOS does not.
If you are in a length-preserving projection with meaningful units (meters), the result will (almost) be the measurement as if done in the real world. But in all other cases, the results from this function are rather useless.
answered Aug 16 at 11:05
bugmenot123bugmenot123
4,55214 silver badges43 bronze badges
4,55214 silver badges43 bronze badges
add a comment |
add a comment |
Your layer's coordinate system is probably a Geographic one (meaning Ellipsoidal here), therefore the distance calculated in degree dimension. To solve this issue, first you have to a pick a proper Projected coordinate system, and save the layer in that coordinate system (Save as, change CRS).
You can find a proper Projected coordinate system at https://epsg.io, e.g. search for your country.
After the projection, the lenght() method's result will be fine.
I sure hope that QGIS provides functions for calculating "true" lengths without having to reproject manually.
– bugmenot123
Aug 16 at 13:19
Maybe try it...
– pnz
Aug 18 at 19:45
Yes, see QgsDistanceArea class
– ndawson
Aug 20 at 18:46
add a comment |
Your layer's coordinate system is probably a Geographic one (meaning Ellipsoidal here), therefore the distance calculated in degree dimension. To solve this issue, first you have to a pick a proper Projected coordinate system, and save the layer in that coordinate system (Save as, change CRS).
You can find a proper Projected coordinate system at https://epsg.io, e.g. search for your country.
After the projection, the lenght() method's result will be fine.
I sure hope that QGIS provides functions for calculating "true" lengths without having to reproject manually.
– bugmenot123
Aug 16 at 13:19
Maybe try it...
– pnz
Aug 18 at 19:45
Yes, see QgsDistanceArea class
– ndawson
Aug 20 at 18:46
add a comment |
Your layer's coordinate system is probably a Geographic one (meaning Ellipsoidal here), therefore the distance calculated in degree dimension. To solve this issue, first you have to a pick a proper Projected coordinate system, and save the layer in that coordinate system (Save as, change CRS).
You can find a proper Projected coordinate system at https://epsg.io, e.g. search for your country.
After the projection, the lenght() method's result will be fine.
Your layer's coordinate system is probably a Geographic one (meaning Ellipsoidal here), therefore the distance calculated in degree dimension. To solve this issue, first you have to a pick a proper Projected coordinate system, and save the layer in that coordinate system (Save as, change CRS).
You can find a proper Projected coordinate system at https://epsg.io, e.g. search for your country.
After the projection, the lenght() method's result will be fine.
answered Aug 16 at 11:17
pnzpnz
9164 silver badges17 bronze badges
9164 silver badges17 bronze badges
I sure hope that QGIS provides functions for calculating "true" lengths without having to reproject manually.
– bugmenot123
Aug 16 at 13:19
Maybe try it...
– pnz
Aug 18 at 19:45
Yes, see QgsDistanceArea class
– ndawson
Aug 20 at 18:46
add a comment |
I sure hope that QGIS provides functions for calculating "true" lengths without having to reproject manually.
– bugmenot123
Aug 16 at 13:19
Maybe try it...
– pnz
Aug 18 at 19:45
Yes, see QgsDistanceArea class
– ndawson
Aug 20 at 18:46
I sure hope that QGIS provides functions for calculating "true" lengths without having to reproject manually.
– bugmenot123
Aug 16 at 13:19
I sure hope that QGIS provides functions for calculating "true" lengths without having to reproject manually.
– bugmenot123
Aug 16 at 13:19
Maybe try it...
– pnz
Aug 18 at 19:45
Maybe try it...
– pnz
Aug 18 at 19:45
Yes, see QgsDistanceArea class
– ndawson
Aug 20 at 18:46
Yes, see QgsDistanceArea class
– ndawson
Aug 20 at 18:46
add a comment |
Thanks for contributing an answer to Geographic Information Systems Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f332179%2fqgsgeometry-length-giving-wrong-result%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown