【发布时间】:2018-04-15 04:12:43
【问题描述】:
我下载了一个显示叶绿素浓度的 netcdf 文件。我正在尝试将此信息绘制为 shapefile 地图上的栅格文件。当我绘制栅格图层时,我遇到了两件事
我不知道如何显示与叶绿素层的坐标 - 它不会让我将 lat 和 lon 转换为栅格层
我想将栅格图层覆盖在 shapefile 地图上……但似乎 NA 值也显示了一种颜色,所以它不会覆盖任何东西?
这是我目前的代码:
library(sp)
library(maptools)
library(RNetCDF)
library(ncdf4)
library(raster)
# retrieving chlorophyll info
attributes(mycdf$var)
attributes(mycdf$var$chlor_a)
# get lat lon info
attributes(mycdf$dim)
nc_lat <- ncvar_get(mycdf, attributes(mycdf$dim)$names[1])
nc_lon <- ncvar_get(mycdf, attributes(mycdf$dim)$names[2])
mycdf <- nc_open(file.choose(), verbose = TRUE, write = FALSE)
rasternew <- raster(chlor)
projection(rasternew)<- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84
+no_defs")
rasternew<- t(rasternew)
# get map
library(rworldmap)
library(rworldxtra)
newmap<- getMap(resolution = "high")
View(newmap)
projection(newmap)<- CRS("+proj=longlat +ellps=WGS84 +datum=WGS84
+no_defs")
# plot
brks <- c(0, 01, 0.2, 0.3, 0.4, 0.5)
col<- c("aliceblue", "lightblue", "green", "yellow", "orange", "red")
par(mfrow=c(1,1), font.axis = 4, mai = rep(.1,4), pin = c(5, 4))
plot(rasternew, breaks = brks, col=col, legend = F)
par(mfrow=c(1,1), new = TRUE, font.axis = 4, mai = rep(.1,4), pin =
c(5, 4))
plot(newmap, xlim=c(150,152), ylim=c(-12, -9), asp = 1, axes = F, col =
"lightgrey", yaxt = "n", xaxt = "n", add = T)
legend(x='bottomleft', legend = c("0", "0.1", "0.2", "0.3", "0.4",
"0.5"), fill = col)
【问题讨论】:
-
非常感谢@RobertH 的帮助。我只是让它太复杂了