how to fill values in a field of a layer if the id columns of two layers match using pyqgis 3?How do I change...

Draw bounding region by list of points

Should we avoid writing fiction about historical events without extensive research?

Can I solder 12/2 Romex to extend wire 5 ft?

Is there a full canon version of Tyrion's jackass/honeycomb joke?

How to fix my table, centering of columns

What is the meaning of "notice to quit at once" and "Lotty points”

How can neutral atoms have exactly zero electric field when there is a difference in the positions of the charges?

Are small insurances worth it

Is every open circuit a capacitor?

Should I use HTTPS on a domain that will only be used for redirection?

Caulking a corner instead of taping with joint compound?

Levi-Civita symbol: 3D matrix

Is there a way to find out the age of climbing ropes?

How does signal strength relate to bandwidth?

“I had a flat in the centre of town, but I didn’t like living there, so …”

Why won't the strings command stop?

Can we carry rice to Japan?

Can the Shape Water Cantrip be used to manipulate blood?

Specific Chinese carabiner QA?

What can I do if someone tampers with my SSH public key?

Wardrobe above a wall with fuse boxes

Can an earth elemental drown/bury its opponent underground using earth glide?

Book about a time-travel war fought by computers

Misplaced tyre lever - alternatives?



how to fill values in a field of a layer if the id columns of two layers match using pyqgis 3?


How do I change the pixel values of raster data from QGIS python pluginHow to define border colour for rule-based style using PyQGIS?Renaming non-GIS files through QGIS?How to duplicate a map layer at most once as the bottom layer in qgis3 (python)Using nested for loops to iterate through features in two layersHow to fill fields with layer name in PyQGISQGIS Attribute table - How to merge the values of $area field of several elements by the same attribute (point ID)?I have a shapefile where in I want to select features based on their feature idsCall the QGIS 3D view using PyQGISHow to fill values in a field by comparing values of other two fields in QGIS3 script?













0















I have two layers, pipes and intersect layers. Both layers have an id,score column but intersect layer does not have all the ids present in pipes. So i am trying to check if the id present in pipes exists in intersect, if yes then copy intersect's score to pipe's score else leave it blank and continue. But the code neither gives an error nor does it make the changes in the attribute table of the pipe layer.
The code is as follows:



pipe_feat = selectedLayer.getFeatures() #pipes layer
field4 = selectedLayer.fields().indexFromName(fid1) #id column is referenced
selectedLayer.startEditing()
featLayer = layer.getFeatures() #intersect layer
field3 = layer.fields().indexFromName('PIPEID')
for feat in pipe_feat:
for f in featLayer:
if feat[field4]==f[field3]:
feat['SewerScore'] = f['Score']
selectedLayer.updateFeature(feat)
else:
continue
selectedLayer.commitChanges()


I have also tried this method: But even this does not work.



  id_score={}
for f in featLayer:
id_score[f[field3]] = f['Score']

for feat in pipe_feat:
for key,value in id_score.items():
if key == feat[field4] :
feat['SewerScore'] = id_score.get[key]
layer.updateFeature(f)
selectedLayer.updateFeature(feat)
else:
continue








share



























    0















    I have two layers, pipes and intersect layers. Both layers have an id,score column but intersect layer does not have all the ids present in pipes. So i am trying to check if the id present in pipes exists in intersect, if yes then copy intersect's score to pipe's score else leave it blank and continue. But the code neither gives an error nor does it make the changes in the attribute table of the pipe layer.
    The code is as follows:



    pipe_feat = selectedLayer.getFeatures() #pipes layer
    field4 = selectedLayer.fields().indexFromName(fid1) #id column is referenced
    selectedLayer.startEditing()
    featLayer = layer.getFeatures() #intersect layer
    field3 = layer.fields().indexFromName('PIPEID')
    for feat in pipe_feat:
    for f in featLayer:
    if feat[field4]==f[field3]:
    feat['SewerScore'] = f['Score']
    selectedLayer.updateFeature(feat)
    else:
    continue
    selectedLayer.commitChanges()


    I have also tried this method: But even this does not work.



      id_score={}
    for f in featLayer:
    id_score[f[field3]] = f['Score']

    for feat in pipe_feat:
    for key,value in id_score.items():
    if key == feat[field4] :
    feat['SewerScore'] = id_score.get[key]
    layer.updateFeature(f)
    selectedLayer.updateFeature(feat)
    else:
    continue








    share

























      0












      0








      0








      I have two layers, pipes and intersect layers. Both layers have an id,score column but intersect layer does not have all the ids present in pipes. So i am trying to check if the id present in pipes exists in intersect, if yes then copy intersect's score to pipe's score else leave it blank and continue. But the code neither gives an error nor does it make the changes in the attribute table of the pipe layer.
      The code is as follows:



      pipe_feat = selectedLayer.getFeatures() #pipes layer
      field4 = selectedLayer.fields().indexFromName(fid1) #id column is referenced
      selectedLayer.startEditing()
      featLayer = layer.getFeatures() #intersect layer
      field3 = layer.fields().indexFromName('PIPEID')
      for feat in pipe_feat:
      for f in featLayer:
      if feat[field4]==f[field3]:
      feat['SewerScore'] = f['Score']
      selectedLayer.updateFeature(feat)
      else:
      continue
      selectedLayer.commitChanges()


      I have also tried this method: But even this does not work.



        id_score={}
      for f in featLayer:
      id_score[f[field3]] = f['Score']

      for feat in pipe_feat:
      for key,value in id_score.items():
      if key == feat[field4] :
      feat['SewerScore'] = id_score.get[key]
      layer.updateFeature(f)
      selectedLayer.updateFeature(feat)
      else:
      continue








      share














      I have two layers, pipes and intersect layers. Both layers have an id,score column but intersect layer does not have all the ids present in pipes. So i am trying to check if the id present in pipes exists in intersect, if yes then copy intersect's score to pipe's score else leave it blank and continue. But the code neither gives an error nor does it make the changes in the attribute table of the pipe layer.
      The code is as follows:



      pipe_feat = selectedLayer.getFeatures() #pipes layer
      field4 = selectedLayer.fields().indexFromName(fid1) #id column is referenced
      selectedLayer.startEditing()
      featLayer = layer.getFeatures() #intersect layer
      field3 = layer.fields().indexFromName('PIPEID')
      for feat in pipe_feat:
      for f in featLayer:
      if feat[field4]==f[field3]:
      feat['SewerScore'] = f['Score']
      selectedLayer.updateFeature(feat)
      else:
      continue
      selectedLayer.commitChanges()


      I have also tried this method: But even this does not work.



        id_score={}
      for f in featLayer:
      id_score[f[field3]] = f['Score']

      for feat in pipe_feat:
      for key,value in id_score.items():
      if key == feat[field4] :
      feat['SewerScore'] = id_score.get[key]
      layer.updateFeature(f)
      selectedLayer.updateFeature(feat)
      else:
      continue






      python qgis-3 pyqgis-3





      share












      share










      share



      share










      asked 6 mins ago









      raorao

      578




      578






















          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%2f314675%2fhow-to-fill-values-in-a-field-of-a-layer-if-the-id-columns-of-two-layers-match-u%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%2f314675%2fhow-to-fill-values-in-a-field-of-a-layer-if-the-id-columns-of-two-layers-match-u%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 Содержание Параметры шины | Стандартизация |...