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;








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










share|improve this question
































    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










    share|improve this question




























      3












      3








      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










      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      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























          2 Answers
          2






          active

          oldest

          votes


















          4















          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.






          share|improve this answer
































            0















            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.






            share|improve this answer

























            • 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













            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
            );



            );













            draft saved

            draft discarded


















            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









            4















            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.






            share|improve this answer





























              4















              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.






              share|improve this answer



























                4














                4










                4









                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.






                share|improve this answer













                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.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 16 at 11:05









                bugmenot123bugmenot123

                4,55214 silver badges43 bronze badges




                4,55214 silver badges43 bronze badges


























                    0















                    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.






                    share|improve this answer

























                    • 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















                    0















                    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.






                    share|improve this answer

























                    • 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













                    0














                    0










                    0









                    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.






                    share|improve this answer













                    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.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    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

















                    • 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

















                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

                    Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

                    Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?