为什么在使用R-package Raster绘制带有“image(x,y,z)”和“plot(raster)”的NetCDF图层时会得到不同的结果?

时间:2013-10-12 04:59:21

标签: r plot raster netcdf geotiff

这可能是非常简单的修复方法。

我想使用函数plot(raster)在NetCDF文件中绘制数据图层。我不知道为什么我会得到光栅偏斜/偏移(我的猜测是问题出在转换,分辨率?),如下图所示。

Incorrect map

如果我使用带有lat,lng,value矩阵的函数图像(x,y,z ...),我会得到正确的显示,如下所示:

Correct map

这是我正在使用的R中的代码:

library(ncdf)
library(raster)

# This is opening the NetCDF layer as a raster
varRaster<-raster("SMOS_File.nc", varname="Soil_Moisture")

# Showing the information of the raster
varRaster
class       : RasterLayer 
dimensions  : 586, 1383, 810438  (nrow, ncol, ncell)
resolution  : 0.2603037, 0.2916659  (x, y)
extent      : -180, 180, -85.4581, 85.4581  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=longlat +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 
data source : SMOS_File.nc 
names       : Retrieved.soil.moisture.value 
zvar        : Soil_Moisture 

plot(varRaster)
data(wrld_simpl)
plot(wrld_simpl, add = TRUE) #This produces the incorrect map 

# If I use the "image" function I can get the right overlay of the data

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) #This produces the correct map 

有关为何会发生这种情况的任何想法?我想使用光栅版本并将其保存为geotiff。

1 个答案:

答案 0 :(得分:0)

我假设netcdf图层是常规网格而不是。因此需要坐标系+转换(感谢Spacedman at gis.stackexchange.com)

数据提供者确认EASE坐标系 - EPSG代码3410

https://gis.stackexchange.com/questions/48518/how-to-re-project-ease-equal-area-scalable-earth-grid-with-a-25-km-cylindrica

从Spacedman帮助我解决这个问题的帖子

现在以下似乎有效...

library(ncdf)
library(raster)
library(maptools)
source("http://dl.dropboxusercontent.com/u/3394649/R_libs/ConversionFunctions.R") #Thanks to Spacedman at  https://gis.stackexchange.com/questions/48518/how-to-re-project-ease-equal-area-scalable-earth-grid-with-a-25-km-cylindrica

data(wrld_simpl)

varRaster <- ConvertGrid("SMOS_File.nc", "Soil_Moisture")

varRaster[varRaster < 0 ] <- NA
varRaster <- TransformTo(varRaster)

#With Plot
plot(varRaster)
plot(wrld_simpl, add = TRUE)

#Now with 'image'
image(varRaster, useRaster=TRUE)
plot(wrld_simpl, add = TRUE)

感谢您的帮助...

吉列尔莫