[R-sig-Geo] netCDF to raster

Robert J. Hijmans r.hijmans at gmail.com
Sat Nov 6 23:11:17 CET 2010


Dear Advait,

"netcdf does not really have a "projection" in GIS parlance". netcdf
is flexible file format in which you can store all kinds of data in
different ways. Climatologists and some others tend to follow the "CF"
(NetCDF Climate and Forecast Metadata Convention) conventions.
Unfortunately, they do not make use one of the standard projections
description formats. I have not taken the time yet to parse the CF
descriptions and into a proj.4 string. However, the projection
metadata is stored in the raster object that you create from a nc (CF)
file in the slot "prj"

r <- raster('ncfile')
r at prj

>From that you can construct a proj.4, in your case probably:

prj <- "+proj=lcc +lat_1=33 +lat_2=45 +lat_0=40 +lon_0=-96"

(see http://www.remotesensing.org/geotiff/proj_list/lambert_conic_conformal_2sp.html
)

and do:

projection(r) <- prj

and save the file.

Robert

On Sat, Nov 6, 2010 at 12:51 PM, Advait Godbole <advaitgodbole at gmail.com> wrote:
> Ok, so I was able to convert and visualize everything but the projections
> are skewed. Do I have to define a projection when reading it in via raster
> or using writeGDAL? I have a custom co-ordinate system which is a modified
> North American Lambert Conformal Conic (NAD 1983 datum) like so:
> False_Easting: 0.00000000
> False_Northing: 0.00000000
> Central_Meridian: -96.00000000
> Standard_Parallel_1: 33.00000000
> Standard_Parallel_2: 45.00000000
> Latitude_Of_Origin: 40.00000000
> Linear Unit: Meter
>
> I would presume that writeGDAL takes care of the projection but my hunch
> says otherwise since the netcdf does not really have a "projection" in GIS
> parlance if I am not mistaken.
>
> Thanks!
>
>
> On Sat, Nov 6, 2010 at 2:16 PM, Advait Godbole <advaitgodbole at gmail.com>wrote:
>
>> Thanks Mike and Sam. This worked perfectly - I am only now realizing how
>> powerful R and these libraries are. Very elegant and smooth!
>>
>> cheers,
>>
>> adv
>>
>>
>> On Sat, Nov 6, 2010 at 11:30 AM, Samuel Veloz <sdveloz at ucdavis.edu> wrote:
>>
>>> You can skip the second step in Michael's code and just write to a tif
>>> file using raster:
>>>
>>> r <- raster("ncfile.nc") #you may need to specify varname here (which
>>> band you are using)
>>> writeRaster(r,"r.tif")
>>>
>>> Sam
>>>
>>>
>>> On Sat, Nov 6, 2010 at 7: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
>>>>
>>>
>>>
>>
>>
>> --
>> advait godbole
>>
>
>
>
> --
> advait godbole
>
>        [[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
>



More information about the R-sig-Geo mailing list