Execution time to change attribute values in Pyqgis

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

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

Why is delta-v is the most useful quantity for planning space travel?

Tiptoe or tiphoof? Adjusting words to better fit fantasy races

Generic lambda vs generic function give different behaviour

How do I keep an essay about "feeling flat" from feeling flat?

Do I need a multiple entry visa for a trip UK -> Sweden -> UK?

I'm in charge of equipment buying but no one's ever happy with what I choose. How to fix this?

Understanding "audieritis" in Psalm 94

What is the term when two people sing in harmony, but they aren't singing the same notes?

Opposite of a diet

How can I use the arrow sign in my bash prompt?

Why did Kant, Hegel, and Adorno leave some words and phrases in the Greek alphabet?

Valid Badminton Score?

Using parameter substitution on a Bash array

Is there any easy technique written in Bhagavad GITA to control lust?

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

What would happen if the UK refused to take part in EU Parliamentary elections?

Efficiently merge handle parallel feature branches in SFDX

How do I rename a LINUX host without needing to reboot for the rename to take effect?

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

Hide Select Output from T-SQL

Ways to speed up user implemented RK4

Is there a problem with hiding "forgot password" until it's needed?



Execution time to change attribute values in Pyqgis














0















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



























    0















    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

























      0












      0








      0








      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














      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












      share










      share



      share










      asked 7 mins ago









      strythestrythe

      687




      687






















          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-to-change-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-to-change-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

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

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

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