[R-sig-Geo] Plotting NetCDF layer over a map as a raster...
Robert J. Hijmans
r.hijmans at gmail.com
Tue Oct 15 07:08:26 CEST 2013
It seems that the files has other variables than lon & lat that are
used. It looks like a projection is used, but then again, the axes
range suggests lon/lat. Can you show more info about the file contents
(e.g. print(varRaster) ) or str(ex.nc).
Even better if you can make the file available to me. In principle you
can of course make a RasterLayer from your x, y and z, particularly if
x and y are regularly spaced.
Robert
On Mon, Oct 14, 2013 at 11:04 AM, Guillermo E. Ponce-Campos
<geponce at gmail.com> wrote:
> Hello:
>
> I have been trying to plot a netcdf layer as a raster and have found one
> single issue that I'd like know if I'm doing something wrong. If I use the
> function "image" from raster package there's no problem at all, the thing
> is that I would like to handle this layer as a raster and be able to map it
> correctly or save it as a geotif.
>
> This is an example using both approaches to map the netcdf layer: as a
> raster and using "image(x,y,z...).
>
> library(ncdf)
>
> library(maptools)
>
> library(raster)
>
> varRaster<-raster("SMOS_File.nc", varname="Soil_Moisture")
>
> plot(varRaster)
> data(wrld_simpl)
> plot(wrld_simpl, add = TRUE)
>
> # Resulting plot (some offset is occurring by opening the layer as a raster
> --> http://bit.ly/19IFfA2
>
>
> #Using "image" there's no problem...
>
> ex.nc = open.ncdf("SMOS_File.nc")
>
> print(ex.nc)
> summary(ex.nc)
> y = get.var.ncdf( ex.nc, "lat")
> x = get.var.ncdf( ex.nc, "lon")
> z = get.var.ncdf( ex.nc, "Soil_Moisture")
>
> image(x,y,z, zlim=c(-0.9,1), col = heat.colors(37))
> plot(wrld_simpl, add = TRUE)
>
> # Resulting plot --> http://bit.ly/1cJ0vXo
>
> Is there anyway to handle the netcdf layer as a raster and be able to map
> it correctly. I already tried to write the raster as a geotif and open it
> in other software such as GRASS or ArcMap and is still showing up with the
> offset.
>
>
> Thanks for any help with this.
> Guillermo
>
> --
> *Guillermo E. Ponce-Campos*
> *PGP Key ID*: 0x57EDC060
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
More information about the R-sig-Geo
mailing list