Extracting single band from multiple band raster with PyQGIS?Per-pixel (statistical) calculations on a raster...

How to deal with an incendiary email that was recalled

What is this metal M-shaped device for?

Can you earn endless XP using a Flameskull and its self-revival feature?

Why can a 352GB NumPy ndarray be used on an 8GB memory macOS computer?

Quenching swords in dragon blood; why?

Dilemma of explaining to interviewer that he is the reason for declining second interview

How to generate a matrix with certain conditions

Do authors have to be politically correct in article-writing?

What are the advantages of using `make` for small projects?

Why avoid shared user accounts?

Why don't I see the difference between two different files in insert mode in vim?

Program that converts a number to a letter of the alphabet

What's the most convenient time of year in the USA to end the world?

Manipulating a general length function

Using only 1s, make 29 with the minimum number of digits

What to do if authors don't respond to my serious concerns about their paper?

Is there hidden data in this .blend file? Trying to minimize the file size

I am on the US no-fly list. What can I do in order to be allowed on flights which go through US airspace?

How Internet Communication Works on a Coaxial Cable

Using loops to create tables

How can I deal with a significant flaw I found in my previous supervisor’s paper?

Number of FLOP (Floating Point Operations) for exponentiation

How to acknowledge an embarrassing job interview, now that I work directly with the interviewer?

Jumping Numbers



Extracting single band from multiple band raster with PyQGIS?


Per-pixel (statistical) calculations on a raster stack using GDALUsing Union on multiple shapefiles to output single resultExtracting one band from multiple stacking raster layers using PyQGIS?“unexpected indent” in the scriptRunning script over every file in folder using GDAL in Python?How to use gdal to convert HDF multi-band file to a single GeoTiff file?How to extract ALL bands from multiband raster in ArcGIS?Creating geopackage from multiple raster files?convert multiple band image to point layerSplit many multi-band files into single-band files using PyQGIS?













0















I'm approaching naw in the script and I'm trying to select many multi-band files from a folder and extract a single band from the file, putting everything in an output folder with the single-band transformed files.



Currently I concluded the following script:



 import sys, os

output = "C:/../folder"

layers =[layer for layer in QgsProject.instance().mapLayers().values()]


for lyr in layers:
if (lyr.type()==QgsMapLayer.RasterLayer):

cmd1 = "gdal_translate -b 1 "+ lyr.source() + "C:/..raster_input" + outputDir + "C:..output" + lyr.name() + "test.ecw"

os.system(cmd1)

cmd2 = outputDir + "C:..output" + lyr.name() + "test.ecw"

iface.addRasterLayer(cmd2)


But it does not work!










share|improve this question









New contributor




vins_26 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    0















    I'm approaching naw in the script and I'm trying to select many multi-band files from a folder and extract a single band from the file, putting everything in an output folder with the single-band transformed files.



    Currently I concluded the following script:



     import sys, os

    output = "C:/../folder"

    layers =[layer for layer in QgsProject.instance().mapLayers().values()]


    for lyr in layers:
    if (lyr.type()==QgsMapLayer.RasterLayer):

    cmd1 = "gdal_translate -b 1 "+ lyr.source() + "C:/..raster_input" + outputDir + "C:..output" + lyr.name() + "test.ecw"

    os.system(cmd1)

    cmd2 = outputDir + "C:..output" + lyr.name() + "test.ecw"

    iface.addRasterLayer(cmd2)


    But it does not work!










    share|improve this question









    New contributor




    vins_26 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.























      0












      0








      0








      I'm approaching naw in the script and I'm trying to select many multi-band files from a folder and extract a single band from the file, putting everything in an output folder with the single-band transformed files.



      Currently I concluded the following script:



       import sys, os

      output = "C:/../folder"

      layers =[layer for layer in QgsProject.instance().mapLayers().values()]


      for lyr in layers:
      if (lyr.type()==QgsMapLayer.RasterLayer):

      cmd1 = "gdal_translate -b 1 "+ lyr.source() + "C:/..raster_input" + outputDir + "C:..output" + lyr.name() + "test.ecw"

      os.system(cmd1)

      cmd2 = outputDir + "C:..output" + lyr.name() + "test.ecw"

      iface.addRasterLayer(cmd2)


      But it does not work!










      share|improve this question









      New contributor




      vins_26 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.












      I'm approaching naw in the script and I'm trying to select many multi-band files from a folder and extract a single band from the file, putting everything in an output folder with the single-band transformed files.



      Currently I concluded the following script:



       import sys, os

      output = "C:/../folder"

      layers =[layer for layer in QgsProject.instance().mapLayers().values()]


      for lyr in layers:
      if (lyr.type()==QgsMapLayer.RasterLayer):

      cmd1 = "gdal_translate -b 1 "+ lyr.source() + "C:/..raster_input" + outputDir + "C:..output" + lyr.name() + "test.ecw"

      os.system(cmd1)

      cmd2 = outputDir + "C:..output" + lyr.name() + "test.ecw"

      iface.addRasterLayer(cmd2)


      But it does not work!







      pyqgis gdal extract multi-band






      share|improve this question









      New contributor




      vins_26 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question









      New contributor




      vins_26 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question








      edited 7 mins ago









      PolyGeo

      53.6k1780240




      53.6k1780240






      New contributor




      vins_26 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked 2 hours ago









      vins_26vins_26

      113




      113




      New contributor




      vins_26 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      vins_26 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      vins_26 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          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
          });


          }
          });






          vins_26 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f314166%2fextracting-single-band-from-multiple-band-raster-with-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








          vins_26 is a new contributor. Be nice, and check out our Code of Conduct.










          draft saved

          draft discarded


















          vins_26 is a new contributor. Be nice, and check out our Code of Conduct.













          vins_26 is a new contributor. Be nice, and check out our Code of Conduct.












          vins_26 is a new contributor. Be nice, and check out our Code of Conduct.
















          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%2f314166%2fextracting-single-band-from-multiple-band-raster-with-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 Содержание Параметры шины | Стандартизация |...