通过分配 LCC 投影将矩阵转换为栅格

Convert matrix to raster with assigning LCC projection

我想将纯数据矩阵(不是 table 的 xyz 类型)转换为栅格图层。每列和每行代表经度和纬度。

但是,在光栅化矩阵时,我很难在其上分配 CRS。

我的数据应该在 LCC 投影中投影。我知道的所有参数都在下面。

DX: 7500.f (meter)
DY: 7500.f (meter)
CEN_LAT: 37.99787f
CEN_LON: 127.4592f
TRUELAT1: 30.f
TRUELAT2: 60.f

所以我给mycrs分配了CRS()函数,如下分配。 我无法在 raster() 中分配 res=7500 参数,因为它 return 出错了。

mx <- matrix(rep(1, 13770), nrow=90, ncol=153) # reproducible example of mx
mycrs <- CRS("+proj=lcc +lat_1=30 +lat_2=60 +lat_0=37.99787 +lon_0=127.4592 +datum=WGS84 +units=m +no_defs")
r <- raster(mx, crs=mycrs)
class       : RasterLayer 
dimensions  : 90, 153, 13770  (nrow, ncol, ncell)
resolution  : 0.006535948, 0.01111111  (x, y)
extent      : 0, 1, 0, 1  (xmin, xmax, ymin, ymax)
coord. ref. : +proj=lcc +lat_1=30 +lat_2=60 +lat_0=37.99787 +lon_0=127.4592 +datum=WGS84 +units=m +no_defs +ellps=WGS84 +towgs84=0,0,0 
data source : in memory
names       : layer 
values      : 1, 1  (min, max)

嗯,控制台没有return任何警告,但是结果很尴尬。

dimensions好像没问题,但是resolutionextent一定是错的。

层的域应该像

(123.25, 43.23) ------- (131.78, 43.17)
       :                        :
       :                        :
(123.80, 32.73) ------- (131.01, 32.68)

是否有任何其他方法可以使用给定的 CRS 参数将 mx 转换为栅格?

您需要根据坐标参考系 (crs) 了解范围,在本例中为 llc。数据源应提供可用数据。您在 lon/lat 中有范围,但在 llc 中没有。我们可以估算一下:

library(raster)         
e <- extent(123.25, 131.78, 32.68, 43.23)
p <- as(e, "SpatialPolygons")
crs(p) <- "+proj=longlat +datum=WGS84"

library(rgdal)
llc <- "+proj=lcc +lat_1=30 +lat_2=60 +lat_0=37.99787 +lon_0=127.4592 +datum=WGS84"
pp <- spTransform(p, llc)

并创建一个 RasterLayer

r <- raster(pp)

现在设置分辨率(根据你提供的我知道是7500米)

res(r) <- 7500
r
#class      : RasterLayer 
#dimensions : 152, 105, 15960  (nrow, ncol, ncell)
#resolution : 7500, 7500  (x, y)
#extent     : -390412.6, 397087.4, -567400.8, 572599.2  (xmin, xmax, ymin, ymax)
#crs        : +proj=lcc +lat_1=30 +lat_2=60 +lat_0=37.99787 +lon_0=127.4592 +datum=WGS84 +ellps=WGS84 +towgs84=0,0,0 

这与您提供的行数和列数不匹配(但是您从哪里得到这些?)。

范围可能大致正确,但完全不能保证。确切地说,数据提供者应该真的把它给你。如果你真的知道行数和列数,那显然是错误的。