Execution time while changing attribute values in PyQGISSpeed of editing attributes in QGIS from a Python...

Stereotypical names

Why does John Bercow say “unlock” after reading out the results of a vote?

How can I replace every global instance of "x[2]" with "x_2"

Increase performance creating Mandelbrot set in python

How can I get through very long and very dry, but also very useful technical documents when learning a new tool?

If you attempt to grapple an opponent that you are hidden from, do they roll at disadvantage?

Is there an Impartial Brexit Deal comparison site?

What's the purpose of "true" in bash "if sudo true; then"

The baby cries all morning

What is the opposite of 'gravitas'?

(Bedrock Edition) Loading more than six chunks at once

Is it okay / does it make sense for another player to join a running game of Munchkin?

when is out of tune ok?

What is the intuitive meaning of having a linear relationship between the logs of two variables?

Student evaluations of teaching assistants

apt-get update is failing in debian

Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?

Curses work by shouting - How to avoid collateral damage?

Generic lambda vs generic function give different behaviour

Will it be accepted, if there is no ''Main Character" stereotype?

Can criminal fraud exist without damages?

Greatest common substring

What is difference between behavior and behaviour

Is there any reason not to eat food that's been dropped on the surface of the moon?



Execution time while changing attribute values in PyQGIS


Speed of editing attributes in QGIS from a Python pluginPyQGIS: Speed up for adding features and attribute arrays?Via PyQgis how to refresh a modified CSV layer without having to reopen the file?qgis python: select on screen and change (pre-set) properties accordinglyPyQGIS: Change attribute value doesn't work, results in NULLpyqgis QgsAttributeDialog crashesHow to change attribute value in drop down list with constraint and/or Function Editor in QGIS?Duplicating active layer and adding definition query using PyQGIS?How to populate auxiliary fields in QGIS 3?Best way (performance wise) to add Attribute fields in pyQGIS on large files













1















Just want to ask if this is a normal run time when creating new attributes and writing the values of more than 30,000 features. This is for a script I'm writing.



Time to change attribute value: 0:03:44.954493


The process takes approximately 4 minutes just to execute this code



mem_layer.startEditing()
startendField = QgsField(fieldname1, QVariant.String)
durationField = QgsField(fieldname2, QVariant.String)
prov = mem_layer.dataProvider()
prov.addAttributes([startendField])
prov.addAttributes([durationField])
mem_layer.updateFields()
t0 = datetime.now()
i=0
for feat in mem_layer.getFeatures():
#mem_layer.changeAttributeValue(feat.id(),newdatetimeIdx, 12345.67890)
feat.setAttribute(fieldname1, startend_tbl[i])
feat.setAttribute(fieldname2, duration_tbl[i])
#feat[fieldname1] = startend_tbl[i]
#feat[fieldname2] = duration_tbl[i]
mem_layer.updateFeature(feat)
i+=1
mem_layer.commitChanges()
t1 = datetime.now()
feedback.pushInfo('Time to change attribute value: {}'.format(str(t1-t0)))


I read somewhere that using the data provider is not the most efficient method but I don't have any idea what the other options are.










share|improve this question





























    1















    Just want to ask if this is a normal run time when creating new attributes and writing the values of more than 30,000 features. This is for a script I'm writing.



    Time to change attribute value: 0:03:44.954493


    The process takes approximately 4 minutes just to execute this code



    mem_layer.startEditing()
    startendField = QgsField(fieldname1, QVariant.String)
    durationField = QgsField(fieldname2, QVariant.String)
    prov = mem_layer.dataProvider()
    prov.addAttributes([startendField])
    prov.addAttributes([durationField])
    mem_layer.updateFields()
    t0 = datetime.now()
    i=0
    for feat in mem_layer.getFeatures():
    #mem_layer.changeAttributeValue(feat.id(),newdatetimeIdx, 12345.67890)
    feat.setAttribute(fieldname1, startend_tbl[i])
    feat.setAttribute(fieldname2, duration_tbl[i])
    #feat[fieldname1] = startend_tbl[i]
    #feat[fieldname2] = duration_tbl[i]
    mem_layer.updateFeature(feat)
    i+=1
    mem_layer.commitChanges()
    t1 = datetime.now()
    feedback.pushInfo('Time to change attribute value: {}'.format(str(t1-t0)))


    I read somewhere that using the data provider is not the most efficient method but I don't have any idea what the other options are.










    share|improve this question



























      1












      1








      1








      Just want to ask if this is a normal run time when creating new attributes and writing the values of more than 30,000 features. This is for a script I'm writing.



      Time to change attribute value: 0:03:44.954493


      The process takes approximately 4 minutes just to execute this code



      mem_layer.startEditing()
      startendField = QgsField(fieldname1, QVariant.String)
      durationField = QgsField(fieldname2, QVariant.String)
      prov = mem_layer.dataProvider()
      prov.addAttributes([startendField])
      prov.addAttributes([durationField])
      mem_layer.updateFields()
      t0 = datetime.now()
      i=0
      for feat in mem_layer.getFeatures():
      #mem_layer.changeAttributeValue(feat.id(),newdatetimeIdx, 12345.67890)
      feat.setAttribute(fieldname1, startend_tbl[i])
      feat.setAttribute(fieldname2, duration_tbl[i])
      #feat[fieldname1] = startend_tbl[i]
      #feat[fieldname2] = duration_tbl[i]
      mem_layer.updateFeature(feat)
      i+=1
      mem_layer.commitChanges()
      t1 = datetime.now()
      feedback.pushInfo('Time to change attribute value: {}'.format(str(t1-t0)))


      I read somewhere that using the data provider is not the most efficient method but I don't have any idea what the other options are.










      share|improve this question
















      Just want to ask if this is a normal run time when creating new attributes and writing the values of more than 30,000 features. This is for a script I'm writing.



      Time to change attribute value: 0:03:44.954493


      The process takes approximately 4 minutes just to execute this code



      mem_layer.startEditing()
      startendField = QgsField(fieldname1, QVariant.String)
      durationField = QgsField(fieldname2, QVariant.String)
      prov = mem_layer.dataProvider()
      prov.addAttributes([startendField])
      prov.addAttributes([durationField])
      mem_layer.updateFields()
      t0 = datetime.now()
      i=0
      for feat in mem_layer.getFeatures():
      #mem_layer.changeAttributeValue(feat.id(),newdatetimeIdx, 12345.67890)
      feat.setAttribute(fieldname1, startend_tbl[i])
      feat.setAttribute(fieldname2, duration_tbl[i])
      #feat[fieldname1] = startend_tbl[i]
      #feat[fieldname2] = duration_tbl[i]
      mem_layer.updateFeature(feat)
      i+=1
      mem_layer.commitChanges()
      t1 = datetime.now()
      feedback.pushInfo('Time to change attribute value: {}'.format(str(t1-t0)))


      I read somewhere that using the data provider is not the most efficient method but I don't have any idea what the other options are.







      pyqgis qgis-3






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 mins ago









      Taras

      2,3113727




      2,3113727










      asked 2 hours ago









      strythestrythe

      737




      737






















          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%2f316791%2fexecution-time-while-changing-attribute-values-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%2f316791%2fexecution-time-while-changing-attribute-values-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

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

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

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