Layer names changed after reclassification of rasterstack, RLooping a raster stack with a step, RPerforming...

Why Ylvis used go instead of say in phrases like Dog goes "woof"?

two subject complements in passive form?

How can I give a Ranger advantage on a check due to Favored Enemy without spoiling the story for the player?

Third wheel character

User input happy birthday program

How can I handle players killing my NPC outside of combat?

What is the meaning of "usr"?

How do I narratively explain how in-game circumstances do not mechanically allow a PC to instantly kill an NPC?

If we can’t finish all tasks, does this mean we are doing Scrum wrong?

Is it possible to narrate a novel in a faux-historical style without alienating the reader?

Dealing with an internal ScriptKiddie

Can you say "leftside right"?

Is having explosions as a go-to solution considered bad table manners?

What is wrong with my use of "find -print0"?

How do I avoid the "chosen hero" feeling?

Coworker is trying to get me to sign his petition to run for office. How to decline politely?

filecontents: select rows of group to display

Are all power cords made equal?

What does an unprocessed RAW file look like?

Performance and power usage for Raspberry Pi in the Stratosphere

How many diagrams is too much in a research article?

Can you help me solve this algebra problem?

Why write a book when there's a movie in my head?

Is practicing on a digital piano harmful to an experienced piano player?



Layer names changed after reclassification of rasterstack, R


Looping a raster stack with a step, RPerforming Raster Reclassification in QGIS?How to programmatically change raster symbology after reclassification?Reclassification of rasterExtract all the polygon coordinates from a SpatialPolygonsDataframe?Multiband Raster Reclassification in QGISExtract values from large rasterstack, RR: Writing individual variables from a RasterStack in loopWrite RasterLayer by loop preserving the layer names and grouping modelsCalculating Median/Quantile of Rasterstack and converting Results to Data Frame in RR: Reclassify a raster stack through the range of the quantiles of each layer. Generic quantiles function ; layer by layer













0















Following one of my previous questions about looping through a rasterstack (here), I now face a different issue. My initial rasterstack had dates as names (e.g. X2000_05_08.1) and I reclassified it in order to change specific values. After the reclassification though, I got a raster brick and the names changed from dates to layer.1, layer.2 and so on.



Can anyone help me to understand what I did wrong and how to fix this as I want to keep the dates?



Reclassify code:



m <- c(-1, 0,NA) 
rclmat <- matrix(m, ncol=3, byrow=TRUE) # matrix with the value to reclass
new_rc <- reclassify(new, rclmat,right=FALSE) # reclassify my stack ("new")









share|improve this question
















bumped to the homepage by Community 10 mins ago


This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.




















    0















    Following one of my previous questions about looping through a rasterstack (here), I now face a different issue. My initial rasterstack had dates as names (e.g. X2000_05_08.1) and I reclassified it in order to change specific values. After the reclassification though, I got a raster brick and the names changed from dates to layer.1, layer.2 and so on.



    Can anyone help me to understand what I did wrong and how to fix this as I want to keep the dates?



    Reclassify code:



    m <- c(-1, 0,NA) 
    rclmat <- matrix(m, ncol=3, byrow=TRUE) # matrix with the value to reclass
    new_rc <- reclassify(new, rclmat,right=FALSE) # reclassify my stack ("new")









    share|improve this question
















    bumped to the homepage by Community 10 mins ago


    This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.


















      0












      0








      0








      Following one of my previous questions about looping through a rasterstack (here), I now face a different issue. My initial rasterstack had dates as names (e.g. X2000_05_08.1) and I reclassified it in order to change specific values. After the reclassification though, I got a raster brick and the names changed from dates to layer.1, layer.2 and so on.



      Can anyone help me to understand what I did wrong and how to fix this as I want to keep the dates?



      Reclassify code:



      m <- c(-1, 0,NA) 
      rclmat <- matrix(m, ncol=3, byrow=TRUE) # matrix with the value to reclass
      new_rc <- reclassify(new, rclmat,right=FALSE) # reclassify my stack ("new")









      share|improve this question
















      Following one of my previous questions about looping through a rasterstack (here), I now face a different issue. My initial rasterstack had dates as names (e.g. X2000_05_08.1) and I reclassified it in order to change specific values. After the reclassification though, I got a raster brick and the names changed from dates to layer.1, layer.2 and so on.



      Can anyone help me to understand what I did wrong and how to fix this as I want to keep the dates?



      Reclassify code:



      m <- c(-1, 0,NA) 
      rclmat <- matrix(m, ncol=3, byrow=TRUE) # matrix with the value to reclass
      new_rc <- reclassify(new, rclmat,right=FALSE) # reclassify my stack ("new")






      r reclassify rasterstack layer-name






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 24 at 20:16









      PolyGeo

      53.6k1780240




      53.6k1780240










      asked Jan 24 at 7:42









      foofoo

      364




      364





      bumped to the homepage by Community 10 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.







      bumped to the homepage by Community 10 mins ago


      This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.
























          1 Answer
          1






          active

          oldest

          votes


















          0














          Using the example in the help for reclassify (because we can't run your code because we don't have your new object)...



          If a raster has names:



          > names(r)="Region-A"


          and is reclassified....



          > rc <- reclassify(r, rclmat)


          the name is not preserved:



          > names(rc)
          [1] "layer"


          This also applies if you have a stack:



          > s = stack(r,r,r,r,r,r,r)


          with names...



          > names(s)=paste0("Region ",LETTERS[1:7])


          and reclassify:



          > sc <- reclassify(s, rclmat)
          > names(sc)
          [1] "layer.1" "layer.2" "layer.3" "layer.4" "layer.5" "layer.6" "layer.7"


          the fix is to reset the names on the reclassified stack from the original stack:



          > names(sc) = names(s)
          > names(sc)
          [1] "Region.A" "Region.B" "Region.C" "Region.D" "Region.E" "Region.F" "Region.G"
          >


          If you do this a lot then write a wrapper (untested, but should be something like):



          nreclassify = function(r, ...){
          rc = reclassify(r, ...)
          names(rc) = names(r)
          return(rc)
          }


          you might also consider suggesting it as an enhancement to the raster package, but the author might have a good reason for not doing this by default.






          share|improve this answer























            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%2f309711%2flayer-names-changed-after-reclassification-of-rasterstack-r%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            Using the example in the help for reclassify (because we can't run your code because we don't have your new object)...



            If a raster has names:



            > names(r)="Region-A"


            and is reclassified....



            > rc <- reclassify(r, rclmat)


            the name is not preserved:



            > names(rc)
            [1] "layer"


            This also applies if you have a stack:



            > s = stack(r,r,r,r,r,r,r)


            with names...



            > names(s)=paste0("Region ",LETTERS[1:7])


            and reclassify:



            > sc <- reclassify(s, rclmat)
            > names(sc)
            [1] "layer.1" "layer.2" "layer.3" "layer.4" "layer.5" "layer.6" "layer.7"


            the fix is to reset the names on the reclassified stack from the original stack:



            > names(sc) = names(s)
            > names(sc)
            [1] "Region.A" "Region.B" "Region.C" "Region.D" "Region.E" "Region.F" "Region.G"
            >


            If you do this a lot then write a wrapper (untested, but should be something like):



            nreclassify = function(r, ...){
            rc = reclassify(r, ...)
            names(rc) = names(r)
            return(rc)
            }


            you might also consider suggesting it as an enhancement to the raster package, but the author might have a good reason for not doing this by default.






            share|improve this answer




























              0














              Using the example in the help for reclassify (because we can't run your code because we don't have your new object)...



              If a raster has names:



              > names(r)="Region-A"


              and is reclassified....



              > rc <- reclassify(r, rclmat)


              the name is not preserved:



              > names(rc)
              [1] "layer"


              This also applies if you have a stack:



              > s = stack(r,r,r,r,r,r,r)


              with names...



              > names(s)=paste0("Region ",LETTERS[1:7])


              and reclassify:



              > sc <- reclassify(s, rclmat)
              > names(sc)
              [1] "layer.1" "layer.2" "layer.3" "layer.4" "layer.5" "layer.6" "layer.7"


              the fix is to reset the names on the reclassified stack from the original stack:



              > names(sc) = names(s)
              > names(sc)
              [1] "Region.A" "Region.B" "Region.C" "Region.D" "Region.E" "Region.F" "Region.G"
              >


              If you do this a lot then write a wrapper (untested, but should be something like):



              nreclassify = function(r, ...){
              rc = reclassify(r, ...)
              names(rc) = names(r)
              return(rc)
              }


              you might also consider suggesting it as an enhancement to the raster package, but the author might have a good reason for not doing this by default.






              share|improve this answer


























                0












                0








                0







                Using the example in the help for reclassify (because we can't run your code because we don't have your new object)...



                If a raster has names:



                > names(r)="Region-A"


                and is reclassified....



                > rc <- reclassify(r, rclmat)


                the name is not preserved:



                > names(rc)
                [1] "layer"


                This also applies if you have a stack:



                > s = stack(r,r,r,r,r,r,r)


                with names...



                > names(s)=paste0("Region ",LETTERS[1:7])


                and reclassify:



                > sc <- reclassify(s, rclmat)
                > names(sc)
                [1] "layer.1" "layer.2" "layer.3" "layer.4" "layer.5" "layer.6" "layer.7"


                the fix is to reset the names on the reclassified stack from the original stack:



                > names(sc) = names(s)
                > names(sc)
                [1] "Region.A" "Region.B" "Region.C" "Region.D" "Region.E" "Region.F" "Region.G"
                >


                If you do this a lot then write a wrapper (untested, but should be something like):



                nreclassify = function(r, ...){
                rc = reclassify(r, ...)
                names(rc) = names(r)
                return(rc)
                }


                you might also consider suggesting it as an enhancement to the raster package, but the author might have a good reason for not doing this by default.






                share|improve this answer













                Using the example in the help for reclassify (because we can't run your code because we don't have your new object)...



                If a raster has names:



                > names(r)="Region-A"


                and is reclassified....



                > rc <- reclassify(r, rclmat)


                the name is not preserved:



                > names(rc)
                [1] "layer"


                This also applies if you have a stack:



                > s = stack(r,r,r,r,r,r,r)


                with names...



                > names(s)=paste0("Region ",LETTERS[1:7])


                and reclassify:



                > sc <- reclassify(s, rclmat)
                > names(sc)
                [1] "layer.1" "layer.2" "layer.3" "layer.4" "layer.5" "layer.6" "layer.7"


                the fix is to reset the names on the reclassified stack from the original stack:



                > names(sc) = names(s)
                > names(sc)
                [1] "Region.A" "Region.B" "Region.C" "Region.D" "Region.E" "Region.F" "Region.G"
                >


                If you do this a lot then write a wrapper (untested, but should be something like):



                nreclassify = function(r, ...){
                rc = reclassify(r, ...)
                names(rc) = names(r)
                return(rc)
                }


                you might also consider suggesting it as an enhancement to the raster package, but the author might have a good reason for not doing this by default.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 24 at 8:39









                SpacedmanSpacedman

                23.7k23549




                23.7k23549






























                    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%2f309711%2flayer-names-changed-after-reclassification-of-rasterstack-r%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

                    (145452) 2005 RN43 Классификация | Примечания | Ссылки |...

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

                    Энтрерриос (город) Содержание История | Географическое...