[R-sig-Geo] SpatialGridDataFrame to netcdf grid

Roger Bivand Roger.Bivand at nhh.no
Mon Nov 12 22:21:08 CET 2007


On Mon, 12 Nov 2007, Sebastian P. Luque wrote:

> On Mon, 12 Nov 2007 08:56:30 +0100,
> "Edzer J. Pebesma" <edzer.pebesma at uni-muenster.de> wrote:
>
>> On linux, you should have the netCDF driver istalled; from gdalDrivers()
>> I see (on debian etch):
>
>>         name long_name create copy 42 netCDF Network Common Data Format
>> FALSE TRUE
>
>> Then, reading the documentation of writeGDAL:
>
>>      'create2GDAL' creates a GDAL data set from a SpatialGridDataFrame
>> object, in particular to be able to save to GDAL driver formats that
>> only permit copying rather than creation.
>
>> Which is the case for net netCDF format. Might work!
>
> Thank you, I also see the same output in gdalDrivers():
>
>        name                               long_name create  copy
> 43    netCDF              Network Common Data Format  FALSE  TRUE
>
>
> but then create2GDAL fails with:
>
> R> create2GDAL(locs.sub.ts, drivername="netCDF")
> Error in .local(.Object, ...) :
>
> 	GDAL Error 6: GDALDriver::Create() ... no create method implemented for this format.

No, see the example in the help file. Use this function to create a 
dataset that can be created:

xx <- create2GDAL(locs.sub.ts, drivername="GTiff")

then copy xx:

xxx <- copyDataset(xx, drivername="netCDF")

and finay save it:

saveDataset(xxx, tf)
GDAL.close(xx)
GDAL.close(xxx)
GDALinfo(tf)

Watching the R tempdir, you'll see files appearing, so one or other of the 
steps may not be needed, but you cannot create a netCDF file directly.

Roger

>
> I don't understand this message, given that create2GDAL() should be used
> when only copying is allowed for a driver (as reported by gdalDrivers(),
> and ?writeGDAL).  I'm using:
>
> ---<---------------cut here---------------start-------------->---
> R> sessionInfo()
> R version 2.6.0 (2007-10-03)
> x86_64-pc-linux-gnu
>
> locale:
> 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;LC_PAPER=en_CA.UTF-8;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] RColorBrewer_1.0-2 maptools_0.6-19    foreign_0.8-23     trip_1.0-4
> [5] rgdal_0.5-20       sp_0.9-17          gstat_0.9-40       maps_2.0-38
> [9] rcompgen_0.1-17    lattice_0.17-2
>
> loaded via a namespace (and not attached):
> [1] grid_2.6.0  tools_2.6.0
> ---<---------------cut here---------------end---------------->---
>
>
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, 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