编辑:问题实际上与如何将纬度/经度网格线添加到投影 map 有关。我更改了标题以匹配。
我在地理坐标中有一些图层。我想在 LCC 投影中绘制它们,但有一个地理(纬度/经度)网格。在 mapproj
中,我可以使用 map.grid()
添加一个网格,其限制由 lim
参数设置。它需要一个向量或一个范围对象:
a vector of 4 numbers specifying limits: c(lon.low, lon.high, lat.low, lat.high). lim can also be a list with a component named range, such as the result of map, from which limits are taken.
我通过使用裁剪多边形裁剪一个大的矢量图层来构建我的 map :
myPoly <- readOGR(dsn=".", layer="myPolygon") # just a shapefile in geographic coords
library(raster) # To convert an 'extent' object to a SpatialPolygons object
cp <- as(extent(146, 149, -39, -37.5), "SpatialPolygons")
proj4string(cp) <- CRS(proj4string(myPoly)) # copy from shapefile
# Transform and plot:
lcc <- CRS("+init=epsg:3111")
myPoly.proj <- spTransform(myPoly, lcc)
cp.proj <- spTransform(cp, lcc) # transform the clip box
myPoly.proj.clip <- gIntersection(myPoly.proj, cp.proj, byid=TRUE)
plot(myPoly.proj.clip)
# Then finally, add a lat/long grid:
map.grid(lim=as.vector(cp.proj@bbox), labels=TRUE)
最后一行不正确,因为返回的@bbox 是xmin、ymin、xmax、ymax,但需要在xmin、xmax、ymin、ymax 中。必须有一个简单的解决方案来解决这一切,但像往常一样我迷失在漩涡中。我可以手动创建一个限制向量,但真的吗?
最佳答案
编辑:OP 指出 rgdal::llgridlines
这是一个更好的解决方案。
您正在使用来自 sp/rgdal
的上下文,它使用与 mapproj/maps
不同的系统。
试试这个(未经测试):
library(rgdal)
gl <- gridlines(myPoly)
cp.gl <- spTransform(gl, lcc)
plot(cp.gl, add = TRUE)
请参阅 ?gridlines
了解更多关于将其与标签一起使用的信息。我发现只要您远离极地 map ,它就可以很好地工作。
关于r - 如何将经纬度网格添加到投影 map ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24624295/