The raster package isn't able to read the data from this "GMT-style" NetCDF, since the structure of the variable is one-dimensional internally and you are supposed to deal with that yourself. I would stick with the ncdf4 package to read it, you'll have to scan into the "z" variable manually to reconstruct it as a matrix, or subset it.
Note that you should have a large object size with "d", since the nc_open function returns an index vector for each dimension (so one of them is length 89784000, you must have sufficient memory to deal with that - I would close/delete the "d" object once you read the "z", "dimension" and other values). I have code to read from these files, but I can't access it today - it's not that difficult though, you can probably do something like matrix(z, dimension[1], dimension[2]) but you'll have to fiddle to get the orientation right. On Fri, Mar 8, 2013 at 9:18 PM, Julian Burgos <jul...@hafro.is> wrote: > Dear list, > > I am having some troubles opening accessing a raster in the netCDF format. > The file is bathimetric data from GEBCO: > http://www.gebco.net/data_and_products/gridded_bathymetry_data/ > > If I use the ncdf4 package to open and access the data, I have no issues: > > library(ncdf4) > > d <- nc_open("gebco_08_-82_37_63_80.nc") > > z <- as.vector(ncvar_get(d,varid="z")) > > head(z) > [1] 19 40 61 83 106 128 > > > But if I try to use the raster package to access the file and create a > raster object, I get the following error: > > bat <- raster(file="gebco_08_-82_37_63_80",varname="z") > Error in .varName(nc, varname, warn = warn) : > varname: z does not exist in the file. Select one from: > > ... and no varnames are listed. > > > If I do not define a variable name and let the raster package choose it, I > get this: > > > bat <- raster(file="gebco_08_-82_37_63_80",varname="z") > Error in .varName(nc, varname, warn = warn) : > > The description of the netCDF file is as following: > > > d > [1] "File gebco_08_-82_37_63_80.nc (NC_FORMAT_CLASSIC):" > [1] "" > [1] " 6 variables:" > [1] " double x_range[side] " > [1] " units: user_x_unit" > [1] " double y_range[side] " > [1] " units: user_y_unit" > [1] " short z_range[side] " > [1] " units: user_z_unit" > [1] " double spacing[side] " > [1] " int dimension[side] " > [1] " short z[xysize] " > [1] " scale_factor: 1" > [1] " add_offset: 0" > [1] " node_offset: 1" > [1] "" > [1] " 2 dimensions:" > [1] " side Size:2" > [1] " xysize Size:89784000" > [1] "" > [1] " 2 global attributes:" > [1] " title: GEBCO_08 Grid" > [1] " source: 20100927" > > I am using R 15.2 on Linux (Fedora), raster 2.1-8, and ncdf4 version > ncdf4_1.6.1_20120411. > Any help will be welcomed! > > Julian > > -- > Julian Mariano Burgos, PhD > Hafrannsóknastofnunin/Marine Research Institute > Skúlagata 4, 121 ReykjavÃk, Iceland > SÃmi/Telephone : +354-5752037 > BréfsÃmi/Telefax: +354-5752001 > Netfang/Email: jul...@hafro.is > > _______________________________________________ > R-sig-Geo mailing list > R-sig-Geo@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-sig-geo > -- Michael Sumner Hobart, Australia e-mail: mdsum...@gmail.com [[alternative HTML version deleted]]
_______________________________________________ R-sig-Geo mailing list R-sig-Geo@r-project.org https://stat.ethz.ch/mailman/listinfo/r-sig-geo