[R-sig-Geo] netCDF to raster

Michael Sumner mdsumner at gmail.com
Sat Nov 6 15:31:16 CET 2010


How about this? Requires raster, ncdf, rgdal, and sp packages at least
so they must be installed.

library(raster)
## you will need to set some options here, but there are prompts
r <- raster("ncfile.nc")

sgdf <- as(r, "SpatialGridDataFrame")

writeGDAL(sgdf, "geotiff.tif")

See gdalDrivers() for the available formats, which can be set using
options to writeGDAL.

No doubt there will be variations and extra digging for you particular
data, but not far from this. Can you share the file?

Cheers, Mike.

On Sun, Nov 7, 2010 at 1:19 AM, Advait Godbole <advaitgodbole at gmail.com> wrote:
> Dear Members,
>
> I want to convert a 356 x 507 (lat,lon) 2D  netcdf file into a raster so
> that I can read it in to image analysis/GIS programs. I initially adopted an
> approach whereby I first used NCL to convert it to a Fortran unformatted
> binary and then convert it to a formatted sequential format using Fortran.
> This was then read in to ENVI as a "flt" file. I would like to know if there
> is an elegant way in R to directly convert to a geospatial raster, more so
> because I recently switched to using a different cluster and am running into
> i/o problems with all those binary conversions.
>
> Regards,
>
> --
> Advait Godbole, BE Mech
> Doctoral Student, Global Carbon Cycle Lab
> Earth and Atmospheric Sciences
> Purdue University
> West Lafayette, IN 47906
> USA
> voice: +1 317 730 5235
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



-- 
Michael Sumner
Institute for Marine and Antarctic Studies, University of Tasmania
Hobart, Australia
e-mail: mdsumner at gmail.com



More information about the R-sig-Geo mailing list