QgsGeometry.length() giving wrong result?Is it possible to programmatically add calculated fields?Calculate...
Is "stainless" a bulk or a surface property of stainless steel?
Levenshtein Neighbours
Unsolved Problems due to Lack of Computational Power
What happened after the end of the Truman Show?
Why don't sharp and flat root note chords seem to be present in much guitar music?
How do slats reduce stall speed?
Why should I pay for an SSL certificate?
Repurpose telephone line to ethernet
Could sidesticks be linked?
Have only girls been born for a long time in this village?
Why didn’t Doctor Strange stay in the original winning timeline?
Is it allowable to use an organization's name to publish a paper in a conference, even after I graduate from it?
insert several equation in one frame in beamer
Are there any legal requirements concerning airline pilots and their watches?
How to avoid using System.String with Rfc2898DeriveBytes in C#
Does the Green Flame-Blade cantrip work with the Zephyr Strike spell?
Why doesn't the Falcon-9 first stage use three legs to land?
Are there categories whose internal hom is somewhat 'exotic'?
How to translate 脑袋短路 into English?
Nuclear decay triggers
Can I submit a paper to a computer science conference using an alias if using my real name can cause legal trouble in my original country
Use of vor in this sentence
In xXx, is Xander Cage's 10th vehicle a specific reference to another franchise?
How could Tony Stark wield the Infinity Nano Gauntlet - at all?
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 2 days ago
PolyGeo♦
54.9k17 gold badges86 silver badges258 bronze badges
54.9k17 gold badges86 silver badges258 bronze badges
asked Aug 16 at 10:53
lueholueho
1189 bronze badges
1189 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
23 hours ago
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,45214 silver badges43 bronze badges
4,45214 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
23 hours ago
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
23 hours ago
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
9064 silver badges17 bronze badges
9064 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
23 hours ago
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
23 hours ago
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
23 hours ago
Maybe try it...
– pnz
23 hours ago
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