<div dir="ltr"><div><div>It is working!<br><br></div>This spectralIndices saves a lot of time and only expensive packages has similar option, to calculate a lot of VI in one run.<br><br></div>Thank you very much to all!<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Dec 12, 2016 at 4:11 PM, Benjamin Leutner <span dir="ltr"><<a href="mailto:benjamin.leutner@uni-wuerzburg.de" target="_blank">benjamin.leutner@uni-wuerzburg.de</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
  
    
  
  <div bgcolor="#FFFFFF" text="#000000">
    Hi Dragan,<br>
    <br>
    for your first question: yes,  spectralIndices can be calculated on
    Sentinel 2 images as well and L1C data are indeed top of atmosphere
    reflectance.<br>
    Just for calculating spectral indices in principle there's no need
    for further conversions. Nevertheless, it is a good idea to perform
    atmospheric correction on Sentinel 2 data beforehand (with ESA SNAP
    software and/or SEN2COR), because this should improve comparability
    among different scenes.<br>
    <br>
    for your last question. the data() function is out of place here. <br>
    Your code should read:<br>
    <span style="color:rgb(0,0,255)"><span class="">bs3 <-
      raster("C:/R_examples/VI/B3.<wbr>TIF")<br>
      bs4 <- raster("C:/R_examples/VI/B4.<wbr>TIF")<br></span>
      group <- stack(bs3, bs4)<br>
      names(group) <- c("bs3", "bs4")</span><span style="color:rgb(0,0,255)"> # make proper names</span><span class=""><span style="color:rgb(0,0,255)"><br>
    </span><span style="color:rgb(0,0,255)">ndvi <-
      spectralIndices(group, red = "bs3", nir = "bs4", indices = "NDVI")<br>
    </span><br>
    <br></span>
    Cheers,<br>
    Benjamin<div><div class="h5"><br>
    <br>
    <br>
    <div class="m_-5106371961862776677moz-cite-prefix">On 12/12/2016 03:45 PM, Dragan
      Kaludjerovic wrote:<br>
    </div>
    <blockquote type="cite">
      <div dir="ltr">
        <div>
          <div>Martin,<br>
          </div>
          I have replaced brick() with stack() and still got the error
          when I run the line data. Here is how it looks now:<br>
          <br>
          <span style="color:rgb(0,0,255)">install.packages("RStoolbox")<br>
            install.packages(raster)<br>
            <br>
            library(ggplot2)<br>
            library(raster)<br>
            library(rgdal)<br>
            <br>
            bs3 <- raster("C:/R_examples/VI/B3.<wbr>TIF")<br>
            bs4 <- raster("C:/R_examples/VI/B4.<wbr>TIF")<br>
            <br>
            bs3<br>
            bs4<br>
            <br>
            group <- stack(bs3, bs4)<br>
            <br>
            #writeRaster(group, filename = "C:/R_examples/VI/grupa.TIF")<br>
            <br>
            data(group)<br>
            <br>
            ## Calculate NDVI <br>
            <br>
            ndvi <- spectralIndices(group, red = "bs3", nir = "bs4",
            indices = "NDVI")<br>
            <br>
            ndvi<br>
            <br>
          </span></div>
        <span style="color:rgb(0,0,255)">eror when I run line </span><span style="color:rgb(0,0,255)">data(group)<br>
          <br>
        </span>
        <pre class="m_-5106371961862776677gmail-GODMDAHBLOB" id="m_-5106371961862776677gmail-rstudio_console_output" style="font-family:"lucida console";font-size:10pt;outline:medium none;border-width:medium;border-style:none;border-color:-moz-use-text-color;word-break:break-all;margin:0px;white-space:pre-wrap;line-height:15px;color:rgb(0,0,0);font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255)"><span class="m_-5106371961862776677gmail-GODMDAHBFOB m_-5106371961862776677gmail-ace_constant" style="color:rgb(197,6,11)">Warning message:
</span><span class="m_-5106371961862776677gmail-GODMDAHBFOB m_-5106371961862776677gmail-ace_constant" style="color:rgb(197,6,11)">In data(group) :</span><span class="m_-5106371961862776677gmail-GODMDAHBFOB m_-5106371961862776677gmail-ace_constant" style="color:rgb(197,6,11)"> data set ‘group’ not found</span></pre>
      </div>
      <div class="gmail_extra"><br>
        <div class="gmail_quote">On Mon, Dec 12, 2016 at 8:17 AM, Martin
          Wegmann <span dir="ltr"><<a href="mailto:martin.wegmann@uni-wuerzburg.de" target="_blank">martin.wegmann@uni-wuerzburg.<wbr>de</a>></span>
          wrote:<br>
          <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div style="background-color:rgb(255,255,255);line-height:initial" lang="en-GB">
              <div>Dear
                Dragan,</div>
              <div><br>
              </div>
              <div>Please
                replace brick() with stack() and it should work, and of
                course you need to adapt your band names in
                spectralIndices()‎.</div>
              <div><br>
              </div>
              <div>Regards,
                Martin</div>
              <div><br style="display:initial">
              </div>
              <table style="background-color:white;border-spacing:0px" width="100%">
                <tbody>
                  <tr>
                    <td colspan="2" style="font-size:initial;text-align:initial;background-color:rgb(255,255,255)">
                      <div>
                        <div><b>From: </b>Dragan Kaludjerovic</div>
                        <div><b>Sent: </b>Sunday, December 11, 2016
                          23:21</div>
                        <div><b>To: </b><a href="mailto:rs-ecology@lists.uni-wuerzburg.de" target="_blank">rs-ecology@lists.uni-wuerzburg<wbr>.de</a></div>
                        <div><b>Subject: </b>Re: [RS-ecology]
                          RS-ecology Digest, Vol 16, Issue 1</div>
                      </div>
                    </td>
                  </tr>
                </tbody>
              </table>
              <div>
                <div class="m_-5106371961862776677h5"><br>
                  <div id="m_-5106371961862776677m_3514289799792061681_originalContent">
                    <div dir="ltr">
                      <div>Now I have changed it, but still getting
                        error<br>
                        <br>
                        <span style="color:rgb(0,0,255)">install.packages("RStoolbox")<br>
                          install.packages(raster)<br>
                          <br>
                          library(ggplot2)<br>
                          library(raster)<br>
                          library(rgdal)<br>
                          <br>
                          bs3 <- raster("C:/R_examples/VI/B3.TI<wbr>F")<br>
                          bs4 <- raster("C:/R_examples/VI/B4.TI<wbr>F")<br>
                          <br>
                          bs3<br>
                          bs4<br>
                          <br>
                          group <- brick(bs3, bs4)<br>
                          <br>
                          data(group)<br>
                          <br>
                          ## Calculate NDVI <br>
                          <br>
                          ndvi <- spectralIndices(group, red = "bs3",
                          nir = "bs4", indices = "NDVI")<br>
                          <br>
                          ndvi<br>
                          <br>
                        </span></div>
                      error is:<span style="color:rgb(0,0,255)"><br>
                        <br>
                      </span><br>
                      <pre class="m_-5106371961862776677m_3514289799792061681gmail-GODMDAHBLOB" id="m_-5106371961862776677m_3514289799792061681gmail-rstudio_console_output" style="font-family:"lucida console";font-size:10pt;outline:medium none;border-width:medium;border-style:none;border-color:-moz-use-text-color;word-break:break-all;margin:0px;white-space:pre-wrap;line-height:15px;color:rgb(0,0,0);font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-indent:0px;text-transform:none;word-spacing:0px;background-color:rgb(255,255,255)"><span class="m_-5106371961862776677m_3514289799792061681gmail-GODMDAHBBPB m_-5106371961862776677m_3514289799792061681gmail-ace_keyword" style="color:blue;white-space:pre-wrap">> </span><span class="m_-5106371961862776677m_3514289799792061681gmail-GODMDAHBBOB m_-5106371961862776677m_3514289799792061681gmail-ace_keyword" style="color:blue">group <- brick(bs3, bs4)
</span><span class="m_-5106371961862776677m_3514289799792061681gmail-GODMDAHBBPB m_-5106371961862776677m_3514289799792061681gmail-ace_keyword" style="color:blue;white-space:pre-wrap">> </span><span class="m_-5106371961862776677m_3514289799792061681gmail-GODMDAHBBOB m_-5106371961862776677m_3514289799792061681gmail-ace_keyword" style="color:blue">data(group)
</span><span class="m_-5106371961862776677m_3514289799792061681gmail-GODMDAHBFOB m_-5106371961862776677m_3514289799792061681gmail-ace_constant" style="color:rgb(197,6,11)">Warning message:
</span><span class="m_-5106371961862776677m_3514289799792061681gmail-GODMDAHBFOB m_-5106371961862776677m_3514289799792061681gmail-ace_constant" style="color:rgb(197,6,11)">In data(group) :</span><span class="m_-5106371961862776677m_3514289799792061681gmail-GODMDAHBFOB m_-5106371961862776677m_3514289799792061681gmail-ace_constant" style="color:rgb(197,6,11)"> data set ‘group’ not found</span></pre>
                    </div>
                    <div class="gmail_extra"><br>
                      <div class="gmail_quote">On Sun, Dec 11, 2016 at
                        12:00 PM, <span dir="ltr"><<a href="mailto:rs-ecology-request@lists.uni-wuerzburg.de" target="_blank"></a><a class="m_-5106371961862776677moz-txt-link-abbreviated" href="mailto:rs-ecology-request@lists.uni" target="_blank">rs-ecology-request@lists.uni</a>-<wbr><a href="http://wuerzburg.de">wuerzburg.de</a>></span>
                        wrote:<br>
                        <blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Send RS-ecology
                          mailing list submissions to<br>
                                  <a href="mailto:rs-ecology@lists.uni-wuerzburg.de" target="_blank">rs-ecology@lists.uni-wuerzburg<wbr>.de</a><br>
                          <br>
                          To subscribe or unsubscribe via the World Wide
                          Web, visit<br>
                                  <a href="https://lists.uni-wuerzburg.de/mailman/listinfo/rs-ecology" rel="noreferrer" target="_blank">https://lists.uni-wuerzburg.de<wbr>/mailman/listinfo/rs-ecology</a><br>
                          or, via email, send a message with subject or
                          body 'help' to<br>
                                  <a href="mailto:rs-ecology-request@lists.uni-wuerzburg.de" target="_blank">rs-ecology-request@lists.uni-w<wbr>uerzburg.de</a><br>
                          <br>
                          You can reach the person managing the list at<br>
                                  <a href="mailto:rs-ecology-owner@lists.uni-wuerzburg.de" target="_blank">rs-ecology-owner@lists.uni-wue<wbr>rzburg.de</a><br>
                          <br>
                          When replying, please edit your Subject line
                          so it is more specific<br>
                          than "Re: Contents of RS-ecology digest..."<br>
                          <br>
                          <br>
                          Today's Topics:<br>
                          <br>
                             1. problem with RStoolbox (Dragan
                          Kaludjerovic)<br>
                             2. Re: problem with RStoolbox (Martin
                          Wegmann)<br>
                          <br>
                          <br>
                          ------------------------------<wbr>------------------------------<wbr>----------<br>
                          <br>
                          Message: 1<br>
                          Date: Sat, 10 Dec 2016 19:00:11 +0100<br>
                          From: Dragan Kaludjerovic <<a href="mailto:advancedgwt@gmail.com" target="_blank"></a><a class="m_-5106371961862776677moz-txt-link-abbreviated" href="mailto:advancedgwt@gmail.com" target="_blank">advancedgwt@gmail.com</a>><br>
                          To: <a href="mailto:RS-ecology@lists.uni-wuerzburg.de" target="_blank">RS-ecology@lists.uni-wuerzburg<wbr>.de</a><br>
                          Subject: [RS-ecology] problem with RStoolbox<br>
                          Message-ID:<br>
                                  <<a href="mailto:CAFZvhLipaCHuq-hQsk_5i31ThbCXGQZ4cPhP87%2BYS4P6__rzDw@mail.gmail.com" target="_blank">CAFZvhLipaCHuq-hQsk_5i31ThbCX<wbr>GQZ4cPhP87+YS4P6__rzDw@mail.gm<wbr>ail.com</a>><br>
                          Content-Type: text/plain; charset="utf-8"<br>
                          <br>
                          Hi,<br>
                          I have just discover RStoolbox and try simple
                          simple script<br>
                          <br>
                          install.packages("RStoolbox")<br>
                          install.packages(raster)<br>
                          <br>
                          library(ggplot2)<br>
                          library(raster)<br>
                          library(rgdal)<br>
                          <br>
                          data(img)<br>
                          <br>
                          ## Calculate NDVI<br>
                          ndvi <- spectralIndices(img, red =
                          "C:/R_examples/VI/B3.tif", nir =<br>
                          "C:/R_examples/VI/B4.tif", indices = "NDVI")<br>
                          ndvi<br>
                          <br>
                          <br>
                          when I run it I got error message<br>
                          <br>
                          Error in match(xi, names(img)) : object 'img'
                          not found<br>
                          <br>
                          Any suggestion is welcomed!<br>
                          <br>
                          Best Regards,<br>
                          <br>
                          Dragan<br>
                          -------------- next part --------------<br>
                          An HTML attachment was scrubbed...<br>
                          URL: <<a href="http://lists.uni-wuerzburg.de/pipermail/rs-ecology/attachments/20161210/0a7d11e2/attachment-0001.html" rel="noreferrer" target="_blank">http://lists.uni-wuerzburg.de<wbr>/pipermail/rs-ecology/attachme<wbr>nts/20161210/0a7d11e2/attachme<wbr>nt-0001.html</a>><br>
                          <br>
                          ------------------------------<br>
                          <br>
                          Message: 2<br>
                          Date: Sun, 11 Dec 2016 09:46:02 +0100<br>
                          From: Martin Wegmann <<a href="mailto:martin.wegmann@uni-wuerzburg.de" target="_blank">martin.wegmann@uni-wuerzburg.<wbr>de</a>><br>
                          To: Dragan Kaludjerovic <<a href="mailto:advancedgwt@gmail.com" target="_blank"></a><a class="m_-5106371961862776677moz-txt-link-abbreviated" href="mailto:advancedgwt@gmail.com" target="_blank">advancedgwt@gmail.com</a>>,<br>
                                  <a href="mailto:RS-ecology@lists.uni-wuerzburg.de" target="_blank">RS-ecology@lists.uni-wuerzburg<wbr>.de</a><br>
                          Subject: Re: [RS-ecology] problem with
                          RStoolbox<br>
                          Message-ID: <<a href="mailto:20161211084602.5943378.73264.3393@uni-wuerzburg.de" target="_blank">20161211084602.5943378.73264.<wbr>3393@uni-wuerzburg.de</a>><br>
                          Content-Type: text/plain; charset="us-ascii"<br>
                          <br>
                          An HTML attachment was scrubbed...<br>
                          URL: <<a href="http://lists.uni-wuerzburg.de/pipermail/rs-ecology/attachments/20161211/c04e82de/attachment-0001.html" rel="noreferrer" target="_blank">http://lists.uni-wuerzburg.de<wbr>/pipermail/rs-ecology/attachme<wbr>nts/20161211/c04e82de/attachme<wbr>nt-0001.html</a>><br>
                          <br>
                          ------------------------------<br>
                          <br>
                          ______________________________<wbr>_________________<br>
                          RS-ecology mailing list<br>
                          <a href="mailto:RS-ecology@lists.uni-wuerzburg.de" target="_blank">RS-ecology@lists.uni-wuerzburg<wbr>.de</a><br>
                          <a href="https://lists.uni-wuerzburg.de/mailman/listinfo/rs-ecology" rel="noreferrer" target="_blank">https://lists.uni-wuerzburg.de<wbr>/mailman/listinfo/rs-ecology</a><br>
                          <br>
                          <br>
                          End of RS-ecology Digest, Vol 16, Issue 1<br>
                          ******************************<wbr>***********<br>
                        </blockquote>
                      </div>
                      <br>
                    </div>
                    <br>
                  </div>
                </div>
              </div>
            </div>
          </blockquote>
        </div>
        <br>
      </div>
      <br>
      <fieldset class="m_-5106371961862776677mimeAttachmentHeader"></fieldset>
      <br>
      <pre>______________________________<wbr>_________________
RS-ecology mailing list
<a class="m_-5106371961862776677moz-txt-link-abbreviated" href="mailto:RS-ecology@lists.uni-wuerzburg.de" target="_blank">RS-ecology@lists.uni-<wbr>wuerzburg.de</a>
<a class="m_-5106371961862776677moz-txt-link-freetext" href="https://lists.uni-wuerzburg.de/mailman/listinfo/rs-ecology" target="_blank">https://lists.uni-wuerzburg.<wbr>de/mailman/listinfo/rs-ecology</a>
</pre>
    </blockquote>
    <br>
    </div></div><pre class="m_-5106371961862776677moz-signature" cols="72">-- 
Benjamin Leutner M.Sc.
PhD candidate

Department of Remote Sensing
University of Wuerzburg
Campus Hubland Nord 86
97074 Wuerzburg, Germany

Tel: <a href="tel:+49%20931%203189594" value="+499313189594" target="_blank">+49-(0)931-31 89594</a>
Fax: +49-(0)931-31 89594-0
Email: <a class="m_-5106371961862776677moz-txt-link-abbreviated" href="mailto:benjamin.leutner@uni-wuerzburg.de" target="_blank">benjamin.leutner@uni-<wbr>wuerzburg.de</a>
Web: <a class="m_-5106371961862776677moz-txt-link-freetext" href="http://www.fernerkundung.uni-wuerzburg.de" target="_blank">http://www.fernerkundung.uni-<wbr>wuerzburg.de</a>
</pre>
  </div>

</blockquote></div><br></div>