R:如何设置兰伯特投影中的地图范围?

时间:2019-02-06 23:19:21

标签: r

我想绘制一个地图,该地图是从marmap包中获取的一个深水物体。我将投影转换为Lambert方位角相等面积投影,以绘制远距离飞行运动。我只是使用plot()来做到这一点,并且效果很好。

# Get data -> raster world map (bathymetry map)
world <- getNOAA.bathy(-180, 180, -90, 90, res = 15, keep = TRUE)

# Switch to raster
world.ras <- as.raster(world)

# Set the projection to Lambert Azimuthal Eqaul Area and project
my.proj <- "+proj=laea +x_0=0 +y_0=0 +lon_0=-30 +lat_0=40+ellps=GRS80"
world.ras.proj <- projectRaster(world.ras,crs = my.proj)

# Switch back to a bathy object
world.proj <- as.bathy(world.ras.proj)

# Set colors for oceans and land masses
blues <- c("lightsteelblue4", "lightsteelblue3",
           "lightsteelblue2", "lightsteelblue1")
greys <- c(grey(0.6), grey(0.93), grey(0.99))

#plot map
plot(world.proj, image = TRUE, land = TRUE, 
     lwd = 0.01,
     bpal = list(c(0, max(world.proj, na.rm = T), greys),
                 c(min(world.proj, na.rm = T), 0, blues)),
     deep = 0,
     shallow = 0,
     axes = FALSE, xlab = "", ylab = "")
plot(world.proj, n = 1,
     lwd=0.8,
     col="grey",
     add = TRUE)

但是,我不知道如何设置最终地图的范围(将其裁剪)。当然,如果仅导入具有需求范围的地图(见下文),则在将投影转换为Lambert时会得到圆锥形地图。

map <- getNOAA.bathy(-80, 10, 0, 80, res = 25, keep = TRUE)

我的问题:如何获得一个最终的矩形地图,其中将包含我需要的所有区域(xlim = -80,10和ylim = 80,0)?

另外:我还需要每20纬度/经度添加一个刻度。

建议将不胜感激!

1 个答案:

答案 0 :(得分:0)

您必须了解,在投影world时,原始坐标系(以十进制度为单位)被新的坐标系代替。您可以通过将坐标轴添加到绘图中来可视化此视图:

# Plot bathymetric/hypsometric map
plot(world.proj, image = TRUE, land = TRUE, lwd = 0.01,
     bpal = list(c(0, max(world.proj, na.rm = TRUE), greys),
                 c(min(world.proj, na.rm = TRUE), 0, blues)),
     deep = 0, shallow = 0,
     axes = TRUE, xlab = "", ylab = "")
# Add coastline
plot(world.proj, n = 1, lwd = 0.3, add = TRUE)

enter image description here

为了放大您感兴趣的区域(经度-80至10度和纬度0至80度),您需要将该区域的角坐标(以度表示)投影到同一投影中您用于地图的时间:

# Projection of the coordinates of the corners of the area of interest
corners <- data.frame(lon = c(-80, -80, 10, 10, -80), lat = c(0, 80, 80, 0, 0))
corners.proj <- project(as.matrix(corners), proj = my.proj)
lines(corners.proj, col = 2)

enter image description here

您现在要做的就是使用xlimylim来放大覆盖感兴趣区域的矩形:

# Plot bathymetric/hypsometric map
par(mar = c(0, 0, 0, 0))
plot(world.proj, image = TRUE, land = TRUE, lwd = 0.01,
     bpal = list(c(0, max(world.proj, na.rm = TRUE), greys),
                 c(min(world.proj, na.rm = TRUE), 0, blues)),
     deep = 0, shallow = 0,
     axes = FALSE, xlab = "", ylab = "",
     xlim = range(corners.proj[,1]), 
     ylim = range(corners.proj[,2]))
# Add coastline
plot(world.proj, n = 1, lwd = 0.3, add = TRUE)

# Highlight the area of interest for reference
lines(corners.proj, col = 2)

enter image description here

最后,还需要投影刻度,以便出现在投影的地图上。 graticule软件包提供了所需的所有工具:

# Plot bathymetric/hypsometric map
par(mar = c(0, 0, 0, 0)
plot(world.proj, image = TRUE, land = TRUE, lwd = 0.01,
     bpal = list(c(0, max(world.proj, na.rm = TRUE), greys),
                 c(min(world.proj, na.rm = TRUE), 0, blues)),
     deep = 0, shallow = 0,
     axes = FALSE, xlab = "", ylab = "",
     xlim = range(corners.proj[,1]), 
     ylim = range(corners.proj[,2]))
# Add coastline
plot(world.proj, n = 1, lwd = 0.3, add = TRUE)

library(graticule)

## specify where you want meridians and parallels
lons <- seq(-180, 180, by = 20)
lats <- seq(0, 80, by = 20)

## build the (projected graticules) lines
grat <- graticule(lons, lats, proj = my.proj)

## Add graticules to the plot
plot(grat, add = TRUE, lty = 5)

enter image description here

graticule vignette还有许多其他示例。