向R中的投影地图添加刻度

时间:2018-08-09 17:55:15

标签: r maps raster projection gridlines

如何在下面的地图ras中添加刻度:

library(sf)
library(raster)
library(rgdal)
library(rasterVis)
library(graticule)

## Only needed for downloading a raster example

rr <- getData('alt', country='CAN', mask=TRUE)

## Here is where the graticule routine starts
crs.longlat <- CRS("+init=epsg:4326")
ras = projectRaster(rr, crs = ('+proj=laea +lat_0=90 +lon_0=-100 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs'))

## Retrieve raster data
#r <- getRaster('temp', day = testDay, frames = 1)

## Here is where the graticule routine starts
prj <- CRS(projection(rr))
extLL <- projectExtent(ras, crs = crs.longlat)
extLL <- raster::extent(-141.1, -52.6, 41.6, 83.2)

lons <- pretty(c(xmin(extLL), xmax(extLL)))
lats <- pretty(c(ymin(extLL), ymax(extLL)))
## optionally, specify the extents of the meridians and parallels
## here we push them out a little on each side
xl <-  range(lons) + c(-0.4, 0.4)
yl <- range(lats) + c(-0.4, 0.4)
## build the lines with our precise locations and ranges
grat <- graticule(lons, lats, proj = prj,
                  xlim = xl, ylim = yl)
## Labels
labs <- graticule_labels(lons, lats,
                         xline = lons[2],
                         yline = lats[2],
                         proj = prj)
labsLon <- labs[labs$islon,]
labsLat <- labs[!labs$islon,]

library(colorRamps)
#brewer.pal(11,'RdYlBu')

col<-colorRampPalette(c("#0000FF", "#1919FF", "#3333FF", "#4C4CFF", 
                        "#6666FF", "#7F7FFF", "#9999FF", "#B2B2FF", "#FFCCCC", "#FFB2B2", "#FF9999", "#FF7F7F", 
                        "#FF6666", "#FF4C4C", "#FF3333", "#FF1A1A"))


## Display the raster
levelplot(ras,margin=F,col.regions=col)+
 ## and the graticule
 layer(sp.lines(grat)) +
 layer(sp.text(coordinates(labsLon),
               txt = parse(text = labsLon$lab),
               adj = c(1.1, -0.25),
               cex = 0.6)) +
 layer(sp.text(coordinates(labsLat),
               txt = parse(text = labsLat$lab),
               adj = c(-0.25, -0.25),
               cex = 0.6))

sf软件包st_graticule提供了一个很好的示例,但与levelplot不兼容。

通过借鉴以上示例,我尝试了@Oscar的代码并获得了此图像:

您将看到刻度未打印,并且轴仍然具有投影中的纬度和经度。

在保持latlon投影的同时,如何可能在此地图上打印常规graticuleras

enter image description here

0 个答案:

没有答案