为什么在使用“image(x,y,z)"绘制 NetCDF 图层时会得到不同的结果?和“绘图(光栅)"使用 R 包光栅? [英] Why do I get different results in plotting a NetCDF layer with "image(x,y,z)" and "plot (raster)" using R-package Raster?

查看:59
本文介绍了为什么在使用“image(x,y,z)"绘制 NetCDF 图层时会得到不同的结果?和“绘图(光栅)"使用 R 包光栅?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能很容易解决.

我想使用函数 plot(raster) 在地图上绘制来自 NetCDF 文件的数据层.我不知道为什么会出现栅格倾斜/偏移(我猜测问题出在转换、分辨率上?),如下图所示.

I want to plot over a map a data layer from a NetCDF file using the function plot(raster). I don't know why I'm getting a raster skewed/offset (My guess is that the problem is in the transformation, resolution?) as shown in the following image.

不正确的地图

如果我将函数 image(x,y,z...) 与 lat,lng, value 矩阵一起使用,我会得到正确的显示,如下所示:

If I use the function image(x,y,z...) with the lat,lng, value matrices I get the correct display as is shown here:

正确的地图

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

This is the code in R that I'm using:

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.

Any idea on why this could be happening? I'd like to use the raster version and save it as geotiff.

推荐答案

我假设 netcdf 层是一个常规网格,但它不是.所以需要坐标系+变换(感谢gis.stackexchange.com上的Spacedman)

I was assuming that the netcdf layer was a regular grid and it's not. So coordinate system + transformation is required (thanks to Spacedman at gis.stackexchange.com)

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

Data provider confirmed EASE coordinate system - EPSG code 3410

Spacedman 在 https://gis.stackexchange.com/questions/48518/how-to-re-project-ease-equal-area-scalable-earth-grid-with-a-25 公里圆柱体

The post that helped me with this from Spacedman at https://gis.stackexchange.com/questions/48518/how-to-re-project-ease-equal-area-scalable-earth-grid-with-a-25-km-cylindrica

现在以下似乎有效...

Now the following seems to work...

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)

感谢您的帮助...

吉列尔莫

这篇关于为什么在使用“image(x,y,z)"绘制 NetCDF 图层时会得到不同的结果?和“绘图(光栅)"使用 R 包光栅?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆