<div dir="ltr">BAND <- c("2", "3", "4", "5"); band = 2; <div>pmatch(band, BAND)<div><br></div><div>?pmatch</div><div><h3 style="color:rgb(89,89,89);font-family:sans-serif">Value</h3><p style="color:rgb(0,0,0);font-family:sans-serif;font-size:13px">An integer vector (possibly including <code>NA</code> if <code>nomatch = NA</code>) of the same length as<code>x</code>, <b>giving the indices of the elements</b> in <code>table</code> which matched, or <code>nomatch</code>.</p><p><font color="#000000" face="sans-serif">alternativa:</font></p><p><span style="color:rgb(0,0,0);font-family:sans-serif">band <- as.integer(BAND[</span><font color="#000000" face="sans-serif">pmatch(band, BAND)])</font><br></p><p><font color="#000000" face="sans-serif"><br></font></p></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">2016-02-03 17:44 GMT-02:00 ASANTOS <span dir="ltr"><<a href="mailto:alexandresantosbr@yahoo.com.br" target="_blank">alexandresantosbr@yahoo.com.br</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div bgcolor="#FFFFFF" text="#000000">
Caros Listeiros,<br>
<br>
A um mês atrás eu consegui criar a função abaixo com a ajuda
de vocês, no entanto, descobri que ela funciona quando seleciono
band=3, 4 ou 5, mas para band=2 que é a primeira condição da função
não funciona (<span style="color:rgb(197,6,11)">Error in radconvL(band2, band = 2) : object
'Lmax' not found</span> ), alguém poderia me ajudar?<br>
<br>
Segue CRM:<br>
<br>
require(raster)<br>
require(sp)<br>
<br>
# RasterLayer inventado<br>
r <- raster(nrows=10, ncols=10)<br>
r <- setValues(r, 1:ncell(r))<br>
plot(r)<br>
<br>
band2<- as(r, 'SpatialGridDataFrame') ### transforma em
SpatialGridDataFrame<br>
<br>
<br>
##Função para conversão DN para radiância - LISS III
---------------------------<br>
radconvL<-function(x, band = 2)<br>
{<br>
BAND <- c("2", "3", "4", "5")<br>
band <- pmatch(band, BAND)<br>
<br>
if (<a href="http://is.na" target="_blank">is.na</a>(band))<br>
stop("invalid band")<br>
<br>
Lmin = 0<br>
Qmax = 127<br>
x <- as.vector(as.matrix(x))<br>
results <- x<br>
<br>
if(band == 2) {<br>
Lmax <- 120.64<br>
} else if(band == 3) {<br>
Lmax <- 151.31<br>
} else if(band == 4) {<br>
Lmax <- 157.57<br>
} else if(band == 5) {<br>
Lmax <- 69.03<br>
}<br>
<br>
<br>
x <- Lmin + ((Lmax-Lmin)*x)/Qmax<br>
if (class(results) == "SpatialGridDataFrame")<br>
results@data[, 1] <- x<br>
else if (is.data.frame(x))<br>
results <- data.frame(matrix(x, nrow = nrow(results),<br>
ncol = ncol(results)))<br>
else results <- x<br>
results<br>
}<br>
######--<br>
<br>
teste2<-radconvL(band2, band = 2)<br>
teste2 <br>
<br>
Obrigado,<br>
<br>
<br>
<pre cols="72">--
======================================================================
Alexandre dos Santos
Proteção Florestal
IFMT - Instituto Federal de Educação, Ciência e Tecnologia de Mato Grosso
Campus Cáceres
Caixa Postal 244
Avenida dos Ramires, s/n
Bairro: Distrito Industrial
Cáceres - MT CEP: 78.200-000
Fone: <a href="tel:%28%2B55%29%2065%208132-8112" value="+556581328112" target="_blank">(+55) 65 8132-8112</a> (TIM) <a href="tel:%28%2B55%29%2065%209686-6970" value="+556596866970" target="_blank">(+55) 65 9686-6970</a> (VIVO)
<a href="mailto:e-mails:alexandresantosbr@yahoo.com.br" target="_blank">e-mails:alexandresantosbr@yahoo.com.br</a>
<a href="mailto:alexandre.santos@cas.ifmt.edu.br" target="_blank">alexandre.santos@cas.ifmt.edu.br</a>
Lattes: <a href="http://lattes.cnpq.br/1360403201088680" target="_blank">http://lattes.cnpq.br/1360403201088680</a>
OrcID: <a href="http://orcid.org/0000-0001-8232-6722" target="_blank">orcid.org/0000-0001-8232-6722</a>
Researchgate: <a href="https://www.researchgate.net/profile/Alexandre_Santos10" target="_blank">https://www.researchgate.net/profile/Alexandre_Santos10</a>
LinkedIn: <a href="https://br.linkedin.com/in/alexandre-dos-santos-87961635" target="_blank">https://br.linkedin.com/in/alexandre-dos-santos-87961635</a>
======================================================================
</pre>
<div>Em 28/12/2015 16:22, ASANTOS escreveu:<br>
</div>
<blockquote type="cite">require(raster)
<br>
require(sp) <br>
<br>
# RasterLayer inventado <br>
r <- raster(nrows=10, ncols=10) <br>
r <- setValues(r, 1:ncell(r)) <br>
plot(r) <br>
<br>
band2<- as(r, 'SpatialGridDataFrame') ### transforma em <br>
SpatialGridDataFrame <br>
<br>
<br>
##Função para conversão DN para radiância - LISS III
--------------------------- <br>
radconvL<-function(x, band = 2) <br>
{ <br>
BAND <- c("2", "3", "4", "5") <br>
band <- pmatch(band, BAND) <br>
<br>
if (<a href="http://is.na" target="_blank">is.na</a>(band)) <br>
stop("invalid band") <br>
<br>
Lmin = 0 <br>
Qmax = 127 <br>
x <- as.vector(as.matrix(x)) <br>
results <- x <br>
<br>
if(band == 2) { <br>
Lmax <- 120.64 <br>
} else if(band == 3) { <br>
Lmax <- 151.31 <br>
} else if(band == 4) { <br>
Lmax <- 157.57 <br>
} else if(band == 5) { <br>
Lmax <- 69.03 <br>
} <br>
<br>
<br>
x <- Lmin + ((Lmax-Lmin)*x)/Qmax <br>
if (class(results) == "SpatialGridDataFrame") <br>
results@data[, 1] <- x <br>
else if (is.data.frame(x)) <br>
results <- data.frame(matrix(x, nrow = nrow(results),
<br>
ncol = ncol(results))) <br>
else results <- x <br>
results <br>
} <br>
######-- <br>
<br>
teste<-radconvL(band2, band = 4) <br>
teste </blockquote>
<br>
</div>
<br>_______________________________________________<br>
R-br mailing list<br>
<a href="mailto:R-br@listas.c3sl.ufpr.br">R-br@listas.c3sl.ufpr.br</a><br>
<a href="https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br" rel="noreferrer" target="_blank">https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br</a><br>
Leia o guia de postagem (<a href="http://www.leg.ufpr.br/r-br-guia" rel="noreferrer" target="_blank">http://www.leg.ufpr.br/r-br-guia</a>) e forneça código mínimo reproduzível.<br></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div><font size="2" style="font-family:arial">###############################################################</font><br><span style="font-family:arial;font-size:small">## </span><span style="font-size:11px;text-align:center;background-color:rgb(239,239,239);color:rgb(150,150,150);font-family:Verdana,Arial,Helvetica,sans-serif;line-height:13px">Jônatan Dupont Tatsch</span></div><div><span style="font-family:arial;font-size:small">## </span><span style="color:rgb(150,150,150);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10.909090995788574px;line-height:12.997159004211426px;text-align:center;background-color:rgb(239,239,239)">Professor do Departamento de Física</span><font face="arial" style="font-size:small"><br></font></div><div><span style="font-family:arial;font-size:small">## </span><span style="font-family:arial;font-size:small"> </span><span style="color:rgb(150,150,150);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10.9090909957886px;line-height:12.9971590042114px;text-align:center;background-color:rgb(239,239,239)">Coordenador Substituto do Programa de Pós-Graduação em Meteorologia (PPGMET)</span><br></div><div><span style="font-size:small;font-family:arial">## </span><span style="color:rgb(150,150,150);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10.909090995788574px;line-height:12.997159004211426px;text-align:center;background-color:rgb(239,239,239)">Centro de Ciências Exatas e Naturais (CCNE)</span><br></div><div><span style="font-size:small;font-family:arial">## </span><span style="color:rgb(150,150,150);font-family:Verdana,Arial,Helvetica,sans-serif;font-size:10.909090995788574px;line-height:12.997159004211426px;text-align:center;background-color:rgb(239,239,239)">Universidade Federal de Santa Maria - UFSM</span></div><div><span style="font-family:arial;font-size:small">## </span><span style="font-size:11px;text-align:center;background-color:rgb(239,239,239);color:rgb(150,150,150);font-family:Verdana,Arial,Helvetica,sans-serif;line-height:13px">Faixa de Camobi, Prédio 13 - Campus UFSM - </span><span style="font-size:11px;text-align:center;background-color:rgb(239,239,239);color:rgb(150,150,150);font-family:Verdana,Arial,Helvetica,sans-serif;line-height:13px">Santa Maria, RS, Brasil - 97105-900</span><br></div><div style="font-family:arial;font-size:small">## <span style="font-size:11px;text-align:center;background-color:rgb(239,239,239);color:rgb(150,150,150);font-family:Verdana,Arial,Helvetica,sans-serif;line-height:13px">Telefone: +55(55)33012083</span><br></div><div style="font-family:arial;font-size:small">## <span style="font-size:11px;text-align:center;background-color:rgb(239,239,239);color:rgb(150,150,150);font-family:Verdana,Arial,Helvetica,sans-serif;line-height:13px"><a href="http://www.ufsm.br/meteorologia" target="_blank">www.ufsm.br/meteorologia</a></span></div><div style="font-family:arial;font-size:small">###############################################################</div></div></div></div></div>
</div>