Calculate length of selected features in PyQGISHow to Calculate length of polyline geometry for several...

Other than edits for international editions, did Harry Potter and the Philosopher's Stone receive errata?

Charging phone battery with a lower voltage, coming from a bike charger?

Create linguistic diagram (in TikZ?)

If I tried and failed to start my own business, how do I apply for a job without job experience?

Plausible reason for gold-digging ant

If angels and devils are the same species, why would their mortal offspring appear physically different?

What is a good way to explain how a character can produce flames from their body?

"Starve to death" Vs. "Starve to the point of death"

What is a good reason for every spaceship to carry gun on board?

why typing a variable (or expression) prints the value to stdout?

How to extract specific values/fields from the text file?

Why does 0.-5 evaluate to -5?

Minimum Viable Product for RTS game?

Is there a way to pause a running process on Linux systems and resume later?

Boss asked me to sign a resignation paper without a date on it along with my new contract

Why do neural networks need so many examples to perform?

Word for something that's always reliable, but never the best?

Remove isolated elements of a vector

"I showed the monkey himself in the mirror". Why is this sentence grammatical?

Why didn't Tom Riddle take the presence of Fawkes and the Sorting Hat as more of a threat?

Is Screenshot Time-tracking Common?

How to fly a direct entry holding pattern when approaching from an awkward angle?

Is it possible to rotate the Isolines on a Surface Using `MeshFunction`?

How do you get out of your own psychology to write characters?



Calculate length of selected features in PyQGIS


How to Calculate length of polyline geometry for several tables in PostGIS?Getting features in order they are selected using PyQGIS?Deleting selected features using PyQGIS?How to find length of a discontinued line featureCreating Shapefile of subset of input features in PyQGIS?QGIS 2.8+: How can layer.selectedFeatures() return an empty list while layer.selectedFeatureCount() returns the correct number of selected features?Display selected features with same point geometrySelecting Feature in more layers and highlighting them using PyQGIS?Calculate common length of two lines using ArcGIS Desktop?Adding new field with expression in pyqgis













0















I create a selection with getFeatures(QgsFeatureRequest()) and I want to calculate the length of the result which is a QgsFeatureIterator :



select = QgsExpression(" myexpression ")
selectedfeats = layer.getFeatures(QgsFeatureRequest(select ))

total = 0
for feature in selectedfeats :
geom = feature.geometry()
total += geom.length()


But it doesn't work it returns 0 whereas the selectedfeats is not empty.









share





























    0















    I create a selection with getFeatures(QgsFeatureRequest()) and I want to calculate the length of the result which is a QgsFeatureIterator :



    select = QgsExpression(" myexpression ")
    selectedfeats = layer.getFeatures(QgsFeatureRequest(select ))

    total = 0
    for feature in selectedfeats :
    geom = feature.geometry()
    total += geom.length()


    But it doesn't work it returns 0 whereas the selectedfeats is not empty.









    share



























      0












      0








      0








      I create a selection with getFeatures(QgsFeatureRequest()) and I want to calculate the length of the result which is a QgsFeatureIterator :



      select = QgsExpression(" myexpression ")
      selectedfeats = layer.getFeatures(QgsFeatureRequest(select ))

      total = 0
      for feature in selectedfeats :
      geom = feature.geometry()
      total += geom.length()


      But it doesn't work it returns 0 whereas the selectedfeats is not empty.









      share
















      I create a selection with getFeatures(QgsFeatureRequest()) and I want to calculate the length of the result which is a QgsFeatureIterator :



      select = QgsExpression(" myexpression ")
      selectedfeats = layer.getFeatures(QgsFeatureRequest(select ))

      total = 0
      for feature in selectedfeats :
      geom = feature.geometry()
      total += geom.length()


      But it doesn't work it returns 0 whereas the selectedfeats is not empty.







      pyqgis geometry qgis-3 expression length





      share














      share












      share



      share








      edited 3 mins ago









      Vince

      14.6k32748




      14.6k32748










      asked 7 mins ago









      dmjf08dmjf08

      1588




      1588






















          0






          active

          oldest

          votes











          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%2f313462%2fcalculate-length-of-selected-features-in-pyqgis%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          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%2f313462%2fcalculate-length-of-selected-features-in-pyqgis%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

          Щит и меч (фильм) Содержание Названия серий | Сюжет |...

          is 'sed' thread safeWhat should someone know about using Python scripts in the shell?Nexenta bash script uses...

          Meter-Bus Содержание Параметры шины | Стандартизация |...