[R-sig-Geo] small improvement for saveDataset() in rgdal

Roger Bivand Roger.Bivand at nhh.no
Tue Dec 18 10:53:13 CET 2012


Seb,

Thanks for a helpful example and patch - committed in SVN revision 411.

Best wishes,

Roger

On Fri, 14 Dec 2012, Sebastian P. Luque wrote:

> Hi,
>
> Some time ago I spent several hours trying to figure out why the
> following was failing¹:
>
> library(rgdal); library(adehabitatHR)
> data(puechabonsp)
> locs <- puechabonsp$relocs
> ## Estimation of UD for four animals
> (ud <- kernelUD(locs[, 1]))
> locs.gtiff <- create2GDAL(ud[[1]],
>                          drivername="GTiff")
> locs.aaigrid <- copyDataset(locs.gtiff,
>                            driver="AAIGrid")
> saveDataset(locs.aaigrid, "~/tmp/test.asc")
>
> which prints this:
>
> Error in .local(.Object, ...) : Dataset copy failed
>
> finding that this resulted from failure to expand the 'filename'
> argument in saveDataset().  Would it make sense to patch this function
> with:
>
> ---<--------------------cut here---------------start------------------->---
> *** /home/sluque/Scripts/R/src/rgdal/R/gdal.R	2012-12-14 15:05:25.000000000 -0600
> --- /home/sluque/Scripts/R/src/gdal.R	2012-12-14 15:05:11.000000000 -0600
> ***************
> *** 217,223 ****
>    new.obj <- new(new.class,
>                   handle = .Call('RGDAL_CopyDataset',
>                     dataset, getDriver(dataset),
> !                    FALSE, options, filename, PACKAGE="rgdal"))
>
>    if (returnNewObj) return(new.obj)
>    invisible(GDAL.close(new.obj))
> --- 217,223 ----
>    new.obj <- new(new.class,
>                   handle = .Call('RGDAL_CopyDataset',
>                     dataset, getDriver(dataset),
> !                    FALSE, options, normalizePath(filename), PACKAGE="rgdal"))
>
>    if (returnNewObj) return(new.obj)
>    invisible(GDAL.close(new.obj))
> ---<--------------------cut here---------------end--------------------->---
>
> ?  It tests fine on my system:
>
> R> sessionInfo()
> R version 2.15.2 (2012-10-26)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
> [1] LC_CTYPE=en_CA.UTF-8       LC_NUMERIC=C               LC_TIME=en_CA.UTF-8        LC_COLLATE=en_CA.UTF-8     LC_MONETARY=en_CA.UTF-8    LC_MESSAGES=en_CA.UTF-8 
> [7] LC_PAPER=C                 LC_NAME=C                  LC_ADDRESS=C               LC_TELEPHONE=C             LC_MEASUREMENT=en_CA.UTF-8 LC_IDENTIFICATION=C 
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base 
>
> other attached packages:
> [1] adehabitatHR_0.4.4  adehabitatLT_0.3.7  CircStats_0.2-4     boot_1.3-7          MASS_7.3-22         adehabitatMA_0.3.4  ade4_1.5-1          deldir_0.0-21       rgdal_0.7-25 
> [10] sp_1.0-2            slmisc_0.9.3        latticeExtra_0.6-24 RColorBrewer_1.0-5  lattice_0.20-10 
>
> loaded via a namespace (and not attached):
> [1] compiler_2.15.2 grid_2.15.2     tools_2.15.2 
>
>
> Cheers,
>
> --
> Seb
>
> ¹ https://stat.ethz.ch/pipermail/r-sig-ecology/2012-March/002895.html
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no


More information about the R-sig-Geo mailing list