<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Obrigado Jonathan e Éder,<br>
<br>
Não ia conseguir jamais encontrar o erro ligado pmach() e
Éder ficou uma importante dica em sempre fazer um print() para ver
os elementos e resultados envolvidos para não incorrer em erros,<br>
<br>
Redobrados agradecimentos pessoal,<br>
<br>
Segue o problema resolvido:<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>
<br>
<br>
BAND <- c("2", "3", "4", "5")<br>
Band <- pmatch(band, BAND)<br>
<br>
if (is.na(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>
print(results)<br>
results<br>
}<br>
######--<br>
teste2<-radconvL(band2, band = 2)<br>
teste3<-radconvL(band2, band = 3)<br>
<pre class="moz-signature" 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: (+55) 65 8132-8112 (TIM) (+55) 65 9686-6970 (VIVO)
<a class="moz-txt-link-abbreviated" href="mailto:e-mails:alexandresantosbr@yahoo.com.br">e-mails:alexandresantosbr@yahoo.com.br</a>
<a class="moz-txt-link-abbreviated" href="mailto:alexandre.santos@cas.ifmt.edu.br">alexandre.santos@cas.ifmt.edu.br</a>
Lattes: <a class="moz-txt-link-freetext" href="http://lattes.cnpq.br/1360403201088680">http://lattes.cnpq.br/1360403201088680</a>
OrcID: orcid.org/0000-0001-8232-6722
Researchgate: <a class="moz-txt-link-freetext" href="https://www.researchgate.net/profile/Alexandre_Santos10">https://www.researchgate.net/profile/Alexandre_Santos10</a>
LinkedIn: <a class="moz-txt-link-freetext" href="https://br.linkedin.com/in/alexandre-dos-santos-87961635">https://br.linkedin.com/in/alexandre-dos-santos-87961635</a>
======================================================================
</pre>
<div class="moz-cite-prefix">Em 03/02/2016 19:56, Éder Comunello
escreveu:<br>
</div>
<blockquote
cite="mid:CABmC8gkinQbYrouwXMgviNrMh2xgp_YkVP8MOxRN=OmuvC1tVA@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_default"
style="font-family:verdana,sans-serif">Senhores, segue o
código rodando. O objeto "band" redundante foi alterado pra
"ver".</div>
<div class="gmail_default"
style="font-family:verdana,sans-serif"><br>
</div>
<div class="gmail_default" style="">
<div class="gmail_default"><font face="monospace, monospace">########################################################################</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace">require(raster);
require(sp)</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace">#
RasterLayer inventado</font></div>
<div class="gmail_default"><font face="monospace, monospace">r
<- raster(nrows=10, ncols=10)</font></div>
<div class="gmail_default"><font face="monospace, monospace">r
<- setValues(r, 1:ncell(r))</font></div>
<div class="gmail_default"><font face="monospace, monospace">plot(r)</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace">band2<-
as(r, 'SpatialGridDataFrame') ### transforma em
SpatialGridDataFrame</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace">##Função
para conversão DN para radiância - LISS III
---------------------------</font></div>
<div class="gmail_default"><font face="monospace, monospace">radconvL<-function(x,
band = 2)</font></div>
<div class="gmail_default"><font face="monospace, monospace">{</font></div>
<div class="gmail_default"><font face="monospace, monospace">
BAND <- c("2", "3", "4", "5")</font></div>
<div class="gmail_default"><font face="monospace, monospace">
ver <- pmatch(band, BAND)</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace">
if (<a moz-do-not-send="true" href="http://is.na">is.na</a>(ver))</font></div>
<div class="gmail_default"><font face="monospace, monospace">
stop("invalid band")</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace">
Lmin = 0</font></div>
<div class="gmail_default"><font face="monospace, monospace">
Qmax = 127</font></div>
<div class="gmail_default"><font face="monospace, monospace">
x <- as.vector(as.matrix(x))</font></div>
<div class="gmail_default"><font face="monospace, monospace">
results <- x</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace">
if(band == 2) {</font></div>
<div class="gmail_default"><font face="monospace, monospace">
Lmax <- 120.64</font></div>
<div class="gmail_default"><font face="monospace, monospace">
} else if(band == 3) {</font></div>
<div class="gmail_default"><font face="monospace, monospace">
Lmax <- 151.31</font></div>
<div class="gmail_default"><font face="monospace, monospace">
} else if(band == 4) {</font></div>
<div class="gmail_default"><font face="monospace, monospace">
Lmax <- 157.57</font></div>
<div class="gmail_default"><font face="monospace, monospace">
} else if(band == 5) {</font></div>
<div class="gmail_default"><font face="monospace, monospace">
Lmax <- 69.03</font></div>
<div class="gmail_default"><font face="monospace, monospace">
}</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace">
x <- Lmin + ((Lmax-Lmin)*x)/Qmax</font></div>
<div class="gmail_default"><font face="monospace, monospace">
if (class(results) == "SpatialGridDataFrame")</font></div>
<div class="gmail_default"><font face="monospace, monospace">
results@data[, 1] <- x</font></div>
<div class="gmail_default"><font face="monospace, monospace">
else if (is.data.frame(x))</font></div>
<div class="gmail_default"><font face="monospace, monospace">
results <- data.frame(matrix(x, nrow =
nrow(results),</font></div>
<div class="gmail_default"><font face="monospace, monospace">
ncol = ncol(results)))</font></div>
<div class="gmail_default"><font face="monospace, monospace">
else results <- x</font></div>
<div class="gmail_default"><font face="monospace, monospace">
print(paste(band, Lmax))</font></div>
<div class="gmail_default"><font face="monospace, monospace">
print(results)</font></div>
<div class="gmail_default"><font face="monospace, monospace">
return(results)</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace">}</font></div>
<div class="gmail_default"><font face="monospace, monospace">######--</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace">teste2<-radconvL(band2,
band = 2)</font></div>
<div class="gmail_default"><font face="monospace, monospace">teste2<-radconvL(band2,
band = 3)</font></div>
<div style="font-family:verdana,sans-serif"><br>
</div>
</div>
</div>
<div class="gmail_extra"><br clear="all">
<div>
<div class="gmail_signature">
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr"><font style="font-size:small"
face="arial, helvetica, sans-serif">
<div style="font-family:'trebuchet
ms',sans-serif;display:inline"></div>
================================================<br>
Éder Comunello</font>
<div style="font-size:small"><span
style="font-family:arial,helvetica,sans-serif">PhD
Student in Agricultural Systems
Engineering (USP/Esalq)</span><br>
</div>
<div><span style="font-size:small">Brazilian
Agricultural Research Corporation (</span><font
style="font-size:small" face="arial,
helvetica, sans-serif">Embrapa)</font>
<div style="font-size:small"><font face="arial,
helvetica, sans-serif">Dourados, MS, Brazil
[</font>22 16.5'S, 54 49.0'W<span
style="font-family:arial,helvetica,sans-serif">]</span></div>
<div>
<div><br>
</div>
<div><br>
</div>
</div>
<div style="font-size:small"><br>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<br>
<div class="gmail_quote">Em 3 de fevereiro de 2016 19:48, Éder
Comunello <span dir="ltr"><<a moz-do-not-send="true"
href="mailto:comunello.eder@gmail.com" target="_blank">comunello.eder@gmail.com</a>></span>
escreveu:<br>
<blockquote class="gmail_quote" style="margin:0 0 0
.8ex;border-left:1px #ccc solid;padding-left:1ex">
<div dir="ltr">
<div class="gmail_default"
style="font-family:verdana,sans-serif">Senhores, boa
noite!</div>
<div class="gmail_default"
style="font-family:verdana,sans-serif"><br>
</div>
<div class="gmail_default"
style="font-family:verdana,sans-serif">O problema é que
você sobrescreve "band" com o resultado de pmatch (1:4).
Pode observar que mesmo rodando com band 3:5 o resultado
tá errado.</div>
<div class="gmail_default"
style="font-family:verdana,sans-serif"><br>
</div>
<div class="gmail_default"
style="font-family:verdana,sans-serif">Inclua um
print(band) antes do if pra verificar. </div>
<div class="gmail_extra"><br clear="all">
<div>
<div>
<div dir="ltr">
<div>
<div dir="ltr">
<div>
<div dir="ltr"><font style="font-size:small"
face="arial, helvetica, sans-serif">
<div style="font-family:'trebuchet
ms',sans-serif;display:inline"></div>
================================================<span class="HOEnZb"><font
color="#888888"><br>
Éder Comunello</font></span></font><span
class="HOEnZb"><font color="#888888">
<div style="font-size:small"><span
style="font-family:arial,helvetica,sans-serif">PhD
Student in Agricultural Systems
Engineering (USP/Esalq)</span><br>
</div>
<div><span style="font-size:small">Brazilian
Agricultural Research Corporation
(</span><font
style="font-size:small"
face="arial, helvetica,
sans-serif">Embrapa)</font>
<div style="font-size:small"><font
face="arial, helvetica,
sans-serif">Dourados, MS, Brazil
[</font>22 16.5'S, 54 49.0'W<span
style="font-family:arial,helvetica,sans-serif">]</span></div>
<div>
<div><br>
</div>
<div><br>
</div>
</div>
</div>
</font></span></div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
R-br mailing list
<a class="moz-txt-link-abbreviated" href="mailto:R-br@listas.c3sl.ufpr.br">R-br@listas.c3sl.ufpr.br</a>
<a class="moz-txt-link-freetext" href="https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br">https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br</a>
Leia o guia de postagem (<a class="moz-txt-link-freetext" href="http://www.leg.ufpr.br/r-br-guia">http://www.leg.ufpr.br/r-br-guia</a>) e forne�a c�digo m�nimo reproduz�vel.</pre>
</blockquote>
<br>
</body>
</html>