R的传单中的光栅图像不能超过180

时间:2016-12-07 03:07:36

标签: r leaflet r-raster

我试图在传单上绘制新西兰的光栅,但我遇到了一些问题。我发现多边形和点/标记符合预期:

library(raster)
library(leaflet)
library(dplyr)
library(sp)

p1 <- SpatialPolygons(list(Polygons(list(Polygon(cbind(x = c(165, 165, 185, 185, 165), y = c(-50, -31, -31, -50, -50)))), 1)), proj4string=CRS("+init=epsg:4326"))
p2 <- data.frame(lng = runif(100, 165, 185), lat = runif(100, -50, -31))

leaflet() %>% 
    addTiles() %>% 
    addPolygons(data = p1) %>% 
    addMarkers(lat = p2$lat, lng = p2$lng)

最大经度为180的栅格将很好地绘制:

r <- raster(xmn = 165, xmx = 180, ymn = -50, ymx = -31, crs = "+init=epsg:4326", nrows = 50, ncols = 50)
r[] <- rnorm(ncell(r))
leaflet() %>% addTiles() %>% addRasterImage(r, opacity = 0.5)

但是一张经度超过180且覆盖整个新西兰的光栅并没有正确绘制:

r <- raster(xmn = 165, xmx = 185, ymn = -50, ymx = -31, crs = "+init=epsg:4326", nrows = 50, ncols = 50)
r[] <- rnorm(ncell(r))
leaflet() %>% addTiles() %>% addRasterImage(r, opacity = 0.5)

虽然我可以旋转光栅并让它进行绘图,但是它会分割光栅并将零件绘制成超过180,然后返回0:

r <- raster(xmn = 165, xmx = 185, ymn = -50, ymx = -31, crs = "+init=epsg:4326", nrows = 50, ncols = 50)
r[] <- rnorm(ncell(r))
leaflet() %>% addTiles() %>% addRasterImage(rotate(r), opacity = 0.5)

我想知道是否有其他人遇到过这个问题,如果是这样的话怎么解决它?

1 个答案:

答案 0 :(得分:0)

似乎在最近更新的传单中已对此进行了排序。现在,以下内容将按预期工作:

library(raster)
library(leaflet)

r <- raster(xmn = 165, xmx = 185, ymn = -50, ymx = -31, 
            crs = "+init=epsg:4326", nrows = 100, ncols = 100)
r[] <- rnorm(ncell(r))

leaflet() %>% addTiles() %>% addRasterImage(rotate(r), opacity = 0.5)

请注意,必须使用rotate