小编Jam*_*mes的帖子

如何在R中将地图正确添加到栅格图像

我正在尝试绘制海面温度数据并添加彩色的陆地图像,以使数据不会与混淆NAs。我尝试了多种方法来执行此操作,但是正如您将在下图中看到的那样,地图相对于数据未正确对齐。

为使此问题可重现,这是指向我正在使用的文件的保管箱的链接:https : //www.dropbox.com/s/e8pwgmnhvw4s0nf/sst.nc4?dl=0

这是我到目前为止开发的代码;

library(ncdf4)
library(raster)
library(mapdata)
library(mapproj)
library(rgeos)
library(ggplot2)
Run Code Online (Sandbox Code Playgroud)

通过ncdf4,rasterToPoints,map_data和ggplot2

eight = nc_open("Downloads/sst.nc4")
sst = ncvar_get(eight, "sst")
sst = raster(sst)
sst = t(flip(sst, 1)) # have to orient the data properly

# extract the dimensions and set the extent
lat.min = min(eight$dim$lat$vals)
lat.max = max(eight$dim$lat$vals)
lon.min = min(eight$dim$lon$vals)
lon.max = max(eight$dim$lon$vals)
sst = setExtent(sst, ext = c(lon.min, lon.max, lat.min, lat.max))

# provide proper projection
crs(sst) = "+init=epsg:4326"

# convert raster to points
sst.p <- rasterToPoints(sst) …
Run Code Online (Sandbox Code Playgroud)

r projection geospatial satellite-image

5
推荐指数
1
解决办法
621
查看次数

标签 统计

geospatial ×1

projection ×1

r ×1

satellite-image ×1