[R-br] Ler arquivo .zip

Luciano F. Sgarbi luciano.f.sgarbi em gmail.com
Sexta Abril 10 13:07:19 BRT 2015


Oi Jônatan.

Muito obrigado pela solução...

Agora a pouco eu tentei desempacotar os arquivos via terminal (linux) e ele
retornou a seguinte mensagem:

aa em aa:~/temp$  unzip -tq \*.zip
[SRTM_fB01_n000w177.zip]
End-of-central-directory signature not found.  Either this file is not
  a zipfile, or it constitutes one disk of a multi-part archive.  In the
  latter case the central directory and zipfile comment will be found on
  the last disk(s) of this archive.

Assumindo que era um erro no formato de arquivo,  eu cheguei até a seguinte
solução:

url2<-"
ftp://ftp.glcf.umd.edu/glcf/SRTM/media/GLCF.TSM.B3-010.00.Finished_B-01sec-Degree-United_States/Degree_Tiles/n000/SRTM_fB01_n000w177/SRTM_fB01_n000w177.tif.gz
"
file2<-'SRTM_fB01_n000w177'##Tamanho do arquivo: 66k
utils::download.file(url2,destfile=file2,mode='b',method='wget')
R.utils::gunzip(file2,paste(file2,'.tif',sep=''))
raster(paste(file2,'.tif',sep=''))


Mas se alguém tiver uma solução mais 'elegante', por favor, fique a vontade!
Abraços

Em 10 de abril de 2015 12:53, Jônatan <jdtatsch em gmail.com> escreveu:

> Eu sugiro dar uma olhada em ?getData do pacote raster.
>
>
>
> url2<-"
> ftp://ftp.glcf.umd.edu/glcf/SRTM/media/GLCF.TSM.B3-010.00.Finished_B-01sec-Degree-United_States/Degree_Tiles/n000/SRTM_fB01_n000w177/SRTM_fB01_n000w177.tif.gz
> "
>
> # file2<-'SRTM_fB01_n000w177'##Tamanho do arquivo: 66k
> file2 <- basename(url2)
>
> #
> utils::download.file(url2,destfile=paste(file2,".zip",sep=""),mode='b',method='wget')
> utils::download.file(url2, destfile = file2, mode='b', method='wget')
>
>
> #r2<-raster::raster(unzip(paste(file2,".zip",sep=""),paste(file2,".tif",sep="")))
> ## unzip: Extract files from or list a *zip archive*.
>
> ## alternativa com gunzip
> cmd <- paste("gunzip", file2)
> system(cmd)
> r2 <- raster::raster(gsub("\\.gz", "", file2))
>
>
> 2015-04-10 11:05 GMT-03:00 Luciano F. Sgarbi <luciano.f.sgarbi em gmail.com>:
>
>> Bom dia pessoal.
>>
>> Gostaria de saber se algum de vocês tem a solução para o seguinte
>> problema:
>>
>> Estou baixando uns arquivos raster (pelo R) e gostaria de salva-los em
>> uma pasta para posteriormente usá-los.
>>
>> O problema é que para um formato de arquivo e site eu estou conseguindo
>> (Exemplo 1 no código abaixo), entretanto, para o outro conjunto eu não
>> consigo ler os arquivos de jeito nenhum.
>>
>> Qualquer ajuda sera super bem vinda..
>>
>> ###
>>
>> ##Inicio: Exemplo 1
>> require(raster)
>> url1<-"
>> ftp://srtm.csi.cgiar.org/SRTM_v41/SRTM_Data_ArcASCII/srtm_03_08.zip"
>> file1<-'srtm_03_08'##Tamanho do arquivo: 395k
>>
>> utils::download.file(url1,destfile=paste(file1,".zip",sep=""),mode='b',method='wget')
>>
>> r1<-raster::raster(unzip(paste(file1,".zip",sep=""),paste(file1,".asc",sep="")))
>> r1
>> ##Fim: Exemplo 1
>>
>> ##Aqui está o problema
>> ##Tentativa 1
>> url2<-"
>> ftp://ftp.glcf.umd.edu/glcf/SRTM/media/GLCF.TSM.B3-010.00.Finished_B-01sec-Degree-United_States/Degree_Tiles/n000/SRTM_fB01_n000w177/SRTM_fB01_n000w177.tif.gz
>> "
>> file2<-'SRTM_fB01_n000w177'##Tamanho do arquivo: 66k
>>
>> utils::download.file(url2,destfile=paste(file2,".zip",sep=""),mode='b',method='wget')
>>
>> r2<-raster::raster(unzip(paste(file2,".zip",sep=""),paste(file2,".tif",sep="")))
>> zip.file.extract(paste(file2,".zip",sep=""),paste(file2,".tif",sep=""))
>>
>> ##Tentativa 2
>> temp<-tempfile()
>> utils::download.file(url2,destfile=temp,mode='b',method='wget')
>> raster::raster(temp)
>> raster(paste(temp,'/',file2,".tif",sep=""))
>>
>> ###Informações do OS
>>
>>                             sysname
>> release
>>                              "Linux"
>>  "3.2.0-39-generic-pae"
>>                                       version
>>          nodename
>> "#62-Ubuntu SMP Wed Feb 27 22:25:11 UTC 2013"
>>              "aa"
>>                                       machine
>>             login
>>                                        "i686"
>>         "unknown"
>>                                          user
>>    effective_user
>>                                          "aa"
>>              "aa"
>>
>> > sessionInfo()
>> R version 3.1.3 (2015-03-09)
>> Platform: i686-pc-linux-gnu (32-bit)
>> Running under: Ubuntu precise (12.04.5 LTS)
>>
>> locale:
>>  [1] LC_CTYPE=pt_BR.UTF-8       LC_NUMERIC=C
>> LC_TIME=pt_BR.UTF-8        LC_COLLATE=pt_BR.UTF-8
>>  [5] LC_MONETARY=pt_BR.UTF-8    LC_MESSAGES=pt_BR.UTF-8
>>  LC_PAPER=pt_BR.UTF-8       LC_NAME=C
>>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
>> LC_MEASUREMENT=pt_BR.UTF-8 LC_IDENTIFICATION=C
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods   base
>>
>> other attached packages:
>> [1] RCurl_1.95-4.1 bitops_1.0-6   rgdal_0.9-2    raster_2.2-31  sp_1.0-15
>>      downloader_0.3
>>
>> loaded via a namespace (and not attached):
>> [1] digest_0.6.4    grid_3.1.3      lattice_0.20-30 tools_3.1.3
>>
>>
>> --
>>
>> *Luciano F. Sgarbi*
>> * Currículo Lattes <http://lattes.cnpq.br/9788198135883354>*
>>
>> *Laboratório de Ecologia Teórica e Síntese**Departamento de
>> Ecologia, Instituto de Ciências Biológicas V.*
>> *Universidade Federal de Goiás, campus II, Goiânia-GO, Brasil*
>>
>> _______________________________________________
>> R-br mailing list
>> R-br em listas.c3sl.ufpr.br
>> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
>> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça
>> código mínimo reproduzível.
>>
>
>
>
> --
> ###############################################################
> ##  Jônatan Dupont Tatsch
> ##  Professor do Departamento de Física
> ##  Centro de Ciências Exatas e Naturais (CCNE)
> ##  Universidade Federal de Santa Maria
> ##  Faixa de Camobi, Prédio 13 - Campus UFSM - Santa Maria, RS, Brasil -
> 97105-900
> ##  Telefone: +55(55)33012083
> ##  www.ufsm.br/meteorologia
> ###############################################################
>
> _______________________________________________
> R-br mailing list
> R-br em listas.c3sl.ufpr.br
> https://listas.inf.ufpr.br/cgi-bin/mailman/listinfo/r-br
> Leia o guia de postagem (http://www.leg.ufpr.br/r-br-guia) e forneça
> código mínimo reproduzível.
>



-- 

*Luciano F. Sgarbi*
* Currículo Lattes <http://lattes.cnpq.br/9788198135883354>*

*Laboratório de Ecologia Teórica e Síntese**Departamento de
Ecologia, Instituto de Ciências Biológicas V.*
*Universidade Federal de Goiás, campus II, Goiânia-GO, Brasil*
-------------- Próxima Parte ----------
Um anexo em HTML foi limpo...
URL: <http://listas.inf.ufpr.br/pipermail/r-br/attachments/20150410/ea500058/attachment.html>


Mais detalhes sobre a lista de discussão R-br