【问题标题】:How to properly project and plot raster in R如何在 R 中正确投影和绘制栅格
【发布时间】:2014-12-17 21:20:03
【问题描述】:

我在等面积 Behrmann 投影中有一个栅格,我想将它投影到 Mollweide 投影和绘图。

但是,当我使用以下代码执行此操作时,绘图似乎不正确,因为地图延伸到两侧,并且有各种陆地的轮廓,我不希望它们出现。此外,地图延伸超出绘图窗口。

谁能帮我把这个画得很好?

谢谢!

使用的数据文件可以从this link下载。

这是我目前的代码:

require(rgdal)
require(maptools)
require(raster)

data(wrld_simpl)

mollCRS <- CRS('+proj=moll')
behrmannCRS <- CRS('+proj=cea +lat_ts=30')

sst <- raster("~/Dropbox/Public/sst.tif", crs=behrmannCRS)

sst_moll <- projectRaster(sst, crs=mollCRS)
wrld <- spTransform(wrld_simpl, mollCRS)

plot(sst_moll)
plot(wrld, add=TRUE)

【问题讨论】:

  • 请看this线程,我认为它处理同样的问题。
  • 谢谢!尽管所描述的问题听起来确实相同,但在我的情况下,建议的修复并没有改变任何东西。

标签: r gis r-raster


【解决方案1】:

好的,由于this 页面上的示例似乎有效,因此我尝试尽可能地模仿它。我认为出现问题是因为光栅图像的最左侧和最右侧重叠。如示例中所示,裁剪和对 Lat-Lon 的中间重投影似乎可以解决您的问题。

也许这种解决方法可以作为直接解决问题的更优雅解决方案的基础,因为重新投影光栅两次没有好处。

# packages
library(rgdal)
library(maptools)
library(raster)

# define projections
mollCRS <- CRS('+proj=moll')
behrmannCRS <- CRS('+proj=cea +lat_ts=30')

# read data
data(wrld_simpl)
sst <- raster("~/Downloads/sst.tif", crs=behrmannCRS)

# crop sst to extent of world to avoid overlap on the seam
world_ext = projectExtent(wrld_simpl, crs = behrmannCRS)
sst_crop = crop(x = sst, y=world_ext, snap='in')

# convert sst to longlat (similar to test file)
# somehow this gets rid of the unwanted pixels outside the ellipse
sst_longlat = projectRaster(sst_crop, crs = ('+proj=longlat'))

# then convert to mollweide
sst_moll <- projectRaster(sst_longlat, crs=mollCRS, over=T)
wrld <- spTransform(wrld_simpl, mollCRS)

# plot results
plot(sst_moll)
plot(wrld, add=TRUE)

【讨论】:

    猜你喜欢
    • 2020-12-30
    • 2017-09-22
    • 2022-12-23
    • 1970-01-01
    • 2014-05-30
    • 1970-01-01
    • 2015-07-27
    • 2020-08-03
    • 2022-11-25
    相关资源
    最近更新 更多