Change MultiLineString direction in QGIS/PyQGISHow can I switch line direction in QGIS?

Why has the mole been redefined for 2019?

Avoiding morning and evening handshakes

Can an insurance company drop you after receiving a bill and refusing to pay?

Writing a character who is going through a civilizing process without overdoing it?

Could a phylactery of a lich be a mirror or does it have to be a box?

What's a good word to describe a public place that looks like it wouldn't be rough?

Can I write a book of my D&D game?

What is the purpose of easy combat scenarios that don't need resource expenditure?

Publishing research using outdated methods

Citing paywalled articles accessed via illegal web sharing

Can making a creature unable to attack after it has been assigned as an attacker remove it from combat?

Why avoid shared user accounts?

How should I handle players who ignore the session zero agreement?

Why do no American passenger airlines still operate dedicated cargo flights?

Difference between `vector<int> v;` and `vector<int> v = vector<int>();`

How to say "Brexit" in Latin?

How much mayhem could I cause as a sentient fish?

Can I become debt free or should I file bankruptcy ? How to manage my debt and finances?

Why is working on the same position for more than 15 years not a red flag?

Advice for a new journal editor

If I delete my router's history can my ISP still provide it to my parents?

Why isn't there a non-conducting core wire for high-frequency coil applications

Would a National Army of mercenaries be a feasible idea?

Porting Linux to another platform requirements



Change MultiLineString direction in QGIS/PyQGIS


How can I switch line direction in QGIS?













0















I am looking for a method in PyQGIS (QGIS3.x) of reversing the direction of a MultiLineString feature.



I have found a similar question -
How can I switch line direction in QGIS? - for LineString/Polyline. - which only works for QGIS2 - and modified it slightly for use in QGIS3. However, I can't work out how to adapt the approach for MultiLineStrings.



layer = qgis.utils.iface.mapCanvas().currentLayer()
fid = 1 # feature id
feature = layer.getFeature(1)
geom = feature.geometry()
nodes = geom.asPolyline()
nodes.reverse()
newgeom = QgsGeometry.fromPolylineXY(nodes)
layer.startEditing()
layer.changeGeometry(feature.id(),newgeom)
layer.commitChanges()


In theory the above approach could be used with
newgeom = QgsGeometry.fromMultiPolylineXY()
but I can't see how to generate the necessary QgsMultiPolylineXY object.



I have also noted the reversed() function on the QGSMultiLineCurve class, but I couldn't attach the generated QGSMultiLineCurve to the original feature.



I'm not really interested in UI-based approaches, as the features to be reversed are determined programatically.



Any approaches are welcome - if there's a better general approach than above, I'm happy to hear.









share



























    0















    I am looking for a method in PyQGIS (QGIS3.x) of reversing the direction of a MultiLineString feature.



    I have found a similar question -
    How can I switch line direction in QGIS? - for LineString/Polyline. - which only works for QGIS2 - and modified it slightly for use in QGIS3. However, I can't work out how to adapt the approach for MultiLineStrings.



    layer = qgis.utils.iface.mapCanvas().currentLayer()
    fid = 1 # feature id
    feature = layer.getFeature(1)
    geom = feature.geometry()
    nodes = geom.asPolyline()
    nodes.reverse()
    newgeom = QgsGeometry.fromPolylineXY(nodes)
    layer.startEditing()
    layer.changeGeometry(feature.id(),newgeom)
    layer.commitChanges()


    In theory the above approach could be used with
    newgeom = QgsGeometry.fromMultiPolylineXY()
    but I can't see how to generate the necessary QgsMultiPolylineXY object.



    I have also noted the reversed() function on the QGSMultiLineCurve class, but I couldn't attach the generated QGSMultiLineCurve to the original feature.



    I'm not really interested in UI-based approaches, as the features to be reversed are determined programatically.



    Any approaches are welcome - if there's a better general approach than above, I'm happy to hear.









    share

























      0












      0








      0








      I am looking for a method in PyQGIS (QGIS3.x) of reversing the direction of a MultiLineString feature.



      I have found a similar question -
      How can I switch line direction in QGIS? - for LineString/Polyline. - which only works for QGIS2 - and modified it slightly for use in QGIS3. However, I can't work out how to adapt the approach for MultiLineStrings.



      layer = qgis.utils.iface.mapCanvas().currentLayer()
      fid = 1 # feature id
      feature = layer.getFeature(1)
      geom = feature.geometry()
      nodes = geom.asPolyline()
      nodes.reverse()
      newgeom = QgsGeometry.fromPolylineXY(nodes)
      layer.startEditing()
      layer.changeGeometry(feature.id(),newgeom)
      layer.commitChanges()


      In theory the above approach could be used with
      newgeom = QgsGeometry.fromMultiPolylineXY()
      but I can't see how to generate the necessary QgsMultiPolylineXY object.



      I have also noted the reversed() function on the QGSMultiLineCurve class, but I couldn't attach the generated QGSMultiLineCurve to the original feature.



      I'm not really interested in UI-based approaches, as the features to be reversed are determined programatically.



      Any approaches are welcome - if there's a better general approach than above, I'm happy to hear.









      share














      I am looking for a method in PyQGIS (QGIS3.x) of reversing the direction of a MultiLineString feature.



      I have found a similar question -
      How can I switch line direction in QGIS? - for LineString/Polyline. - which only works for QGIS2 - and modified it slightly for use in QGIS3. However, I can't work out how to adapt the approach for MultiLineStrings.



      layer = qgis.utils.iface.mapCanvas().currentLayer()
      fid = 1 # feature id
      feature = layer.getFeature(1)
      geom = feature.geometry()
      nodes = geom.asPolyline()
      nodes.reverse()
      newgeom = QgsGeometry.fromPolylineXY(nodes)
      layer.startEditing()
      layer.changeGeometry(feature.id(),newgeom)
      layer.commitChanges()


      In theory the above approach could be used with
      newgeom = QgsGeometry.fromMultiPolylineXY()
      but I can't see how to generate the necessary QgsMultiPolylineXY object.



      I have also noted the reversed() function on the QGSMultiLineCurve class, but I couldn't attach the generated QGSMultiLineCurve to the original feature.



      I'm not really interested in UI-based approaches, as the features to be reversed are determined programatically.



      Any approaches are welcome - if there's a better general approach than above, I'm happy to hear.







      qgis pyqgis direction





      share












      share










      share



      share










      asked 16 secs ago









      Tom BrennanTom Brennan

      11




      11






















          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%2f313998%2fchange-multilinestring-direction-in-qgis-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%2f313998%2fchange-multilinestring-direction-in-qgis-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

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

          Венесуэла на летних Олимпийских играх 2000 Содержание Состав...

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