使用 SpatRaster 重新投影 SpatVector

问题描述 投票:0回答:1

我正在尝试遵循最佳实践并将 SpatVector 重新投影到 SpatRaster 的投影中,但生成的重新投影对象无法正常工作。我在下面设计了一个可重现的数据集。我在 R 4.4.2 下运行。

#Libraries:
library(terra)

#Make a raster file from scratch, with projection EPSG:4326:


t <- terra::rast(crs = "EPSG:4326", xmin = -124.7722, xmax = -67.0648, ymin = 25.0631, 
                 ymax = 49.396, nrows = 585, ncols = 1386)

#Make a SpatVector from scratch, with EPSG:4269:

e <- ext(-87.24353, -77.06105, 32.76981, 39.46601)
p <- as.polygons(e, crs = "EPSG:4269")

#Making a new vector object by reprojecting the spatvector with the projection of the spatraster:

sca_proj <- terra::project(p, terra::crs(t))

这会产生警告:


Warning messages:
1: In class(object) <- "environment" :
  Setting class(x) to "environment" sets attribute to NULL; result will no longer be an S4 object
2: PROJ: Cannot open https://cdn.proj.org/us_noaa_alhpgn.tif: schannel: CertGetCertificateChain trust error CERT_TRUST_IS_UNTRUSTED_ROOT (GDAL error 1) 
3: PROJ: Cannot open https://cdn.proj.org/us_noaa_inhpgn.tif: schannel: CertGetCertificateChain trust error CERT_TRUST_IS_UNTRUSTED_ROOT (GDAL error 1) 
4: PROJ: Cannot open https://cdn.proj.org/us_noaa_MD.tif: schannel: CertGetCertificateChain trust error CERT_TRUST_IS_UNTRUSTED_ROOT (GDAL error 1) 

绘图表明它不再是一个结构正确的多边形:


plot(sca_proj)

Error in x@ptr$linesNA() : negative length vectors are not allowed

我在这里做错了什么?

r plot raster spatial terra
1个回答
0
投票

这对我有用

library(terra)
#terra 1.8.5
r <- terra::rast(crs = "EPSG:4326", xmin = -124.7722, xmax = -67.0648, ymin = 25.0631, ymax = 49.396, nrows = 585, ncols = 1386)
p <- ext(-87.24353, -77.06105, 32.76981, 39.46601) |> as.polygons(crs = "EPSG:4269")
pr <- terra::project(p, r)

这涉及从 WGS84 到 NAD83 数据的转换(即使它们本质上是等效的):

crs(r, proj=T)
#[1] "+proj=longlat +datum=WGS84 +no_defs"
crs(p, proj=T)
#[1] "+proj=longlat +datum=NAD83 +no_defs"

为了能够进行基准转换,terra 需要 (GDAL) 下载参数文件。这对您不起作用,可能是因为防火墙或某些此类安全功能。这会导致这些警告

PROJ: Cannot open https://cdn.proj.org/us_noaa_alhpgn.tif: schannel: CertGetCertificateChain trust error CERT_TRUST_IS_UNTRUSTED_ROOT (GDAL error 1) 

并且无法进行投影。

© www.soinside.com 2019 - 2024. All rights reserved.