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

时间:2019-04-19 12:20:28

标签: r raster

我想将纯数据矩阵(不是表的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()函数,并如下进行分配。 我无法在res=7500中分配raster()参数,因为它返回了错误。

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)

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

dimensions看起来还不错,但是resolutionextent肯定是错误的。

该图层的域应为

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

是否还有其他方法可以将mx转换为具有给定CRS参数的栅格?

1 个答案:

答案 0 :(得分:1)

您需要根据坐标参考系统(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 m)

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 

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

范围可能大致正确,但是完全不能保证。数据提供商应该确实将其准确地提供给您。如果您实际上知道行数和列数,那么显然是错误的。

相关问题