<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Prezados Listeiros,<br>
<br>
Mais um problema com a minha função, apesar de eu especificar
ao final que <font face="monospace, monospace">class(results) ==
"SpatialGridDataFrame", </font><font face="monospace, monospace">o
resultado final não é um </font><br>
<font face="monospace, monospace">SpatialGridDataFrame </font>mas
um objeto numeric e não sei porque, alguém pode me ajudar?<br>
<br>
Segue a função nova desenvolvida com a ajuda do Éder:<br>
<br>
<div class="gmail_default"><font face="monospace, monospace">###
<code r></font></div>
<div class="gmail_default"><font face="monospace, monospace">require(raster)</font></div>
<div class="gmail_default"><font face="monospace, monospace">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">
Lmax <- switch(as.character(band), </font></div>
<div class="gmail_default"><font face="monospace, monospace">
"2" = 120.64,</font></div>
<div class="gmail_default"><font face="monospace, monospace">
"3" = 151.31,</font></div>
<div class="gmail_default"><font face="monospace, monospace">
"4" = 157.57,</font></div>
<div class="gmail_default"><font face="monospace, monospace">
"5" = 69.03,</font></div>
<div class="gmail_default"><font face="monospace, monospace">
NA)</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="monospace, monospace"> if
(<a href="http://is.na">is.na</a>(Lmax)) 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"> 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">
results</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">teste2<-radconvL(band2,
band = 2)</font></div>
<div class="gmail_default"><font face="monospace, monospace">teste3<-radconvL(band2,
band = 3)</font></div>
<div class="gmail_default"><font face="monospace, monospace">teste1<-radconvL(band2,
band = 1)</font></div>
<div class="gmail_default"><font face="monospace, monospace">###
</code></font></div>
<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 05/02/2016 09:58, Éder Comunello
escreveu:<br>
</div>
<blockquote
cite="mid:CABmC8gkq1fr0aLFJXeaTVZvkcLQRSj5aTRAs85FQH0yPb-74-A@mail.gmail.com"
type="cite">
<div dir="ltr">
<div class="gmail_default"
style="font-family:verdana,sans-serif">Alexandre, bom dia!</div>
<div class="gmail_default"
style="font-family:verdana,sans-serif"><br>
</div>
<div class="gmail_default"
style="font-family:verdana,sans-serif">Embora você já tenha
resolvido seu problema, lembrei de uma possibilidade de
melhoria para o código: o uso de switch() no lugar do bloco if
else.</div>
<div class="gmail_default"
style="font-family:verdana,sans-serif"><br>
</div>
<div class="gmail_default"><font face="monospace, monospace">###
<code r></font></div>
<div class="gmail_default" style="">
<div class="gmail_default"><font face="monospace, monospace">require(raster)</font></div>
<div class="gmail_default"><font face="monospace, monospace">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">
Lmax <- switch(as.character(band), </font></div>
<div class="gmail_default"><font face="monospace, monospace">
"2" = 120.64,</font></div>
<div class="gmail_default"><font face="monospace, monospace">
"3" = 151.31,</font></div>
<div class="gmail_default"><font face="monospace, monospace">
"4" = 157.57,</font></div>
<div class="gmail_default"><font face="monospace, monospace">
"5" = 69.03,</font></div>
<div class="gmail_default"><font face="monospace, monospace">
NA)</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>(Lmax))
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">
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">
results</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">teste2<-radconvL(band2,
band = 2)</font></div>
<div class="gmail_default"><font face="monospace, monospace">teste3<-radconvL(band2,
band = 3)</font></div>
<div class="gmail_default"><font face="monospace, monospace">teste1<-radconvL(band2,
band = 1)</font></div>
<div class="gmail_default"><font face="monospace, monospace">###
</code></font></div>
<div style="font-family:verdana,sans-serif"><br>
</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>
</div>
</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>