Shapefiles不会在R中覆盖栅格图层

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

我有数百个没有坐标参考系统的shapefile。我的目标是在WorldClim栅格图层上覆盖空间多边形。我以前没有任何问题地使用过这种方法。但是,这次我的shapefile中的坐标对我来说很奇怪。多边形内边界框和坐标的每个坐标均由8位数字组成,不带逗号或点号,以分隔小数点后十进制。这是以下形状之一的边界框:

SHP bbox: xmin:-17367529, xmax:17367529, ymin:-5997367 and ymax:7052489 

与WorldClim栅格图层的边界框明显不同。

WorldClim bbox: xmin=-180,xmax=180,ymin=-60 and ymax=90

[当我尝试使用plot命令将shapefile覆盖在栅格图层上时,没有任何反应。

plot(shapefile, add=T)

我知道这是一个投影问题。然后,我尝试使用CRS函数在shapefile中分配与WorldClim栅格图层相同的坐标系。但是,结果保持不变(即shapefile不在栅格上)。在序列中,我尝试使用rgdal包中的spTransform函数重新投影shapefile坐标。但是,由于shapefile没有任何参考系统,因此该功能无法正常工作,并且我不知道如何重新投影shapefile以便与栅格图层匹配。我已经研究了几天有关如何解决此问题的方法,并且我相信缺少参考系统是解决该问题的关键。但是,我无法克服这个问题,我想知道是否有人可以帮助您应对这种情况。

r geospatial coordinate-systems r-raster rgeo-shapefile
1个回答
2
投票

您需要先使用proj4string(meuse)crs(shapefile)<-crs string定义形状文件的投影,然后才能使用spTransform

library(rgdal)
data(meuse)
coordinates(meuse) <- c("x", "y")

这里您具有带有x和y的空间数据,但还没有crs!因此,如果您使用spTransform,它将失败。

summary(meuse) #proj4string : [NA] so below line fails!
meuse.utm <- spTransform(meuse, CRS("+proj=utm +zone=32 +datum=WGS84"))
# Error in spTransform(xSP, CRSobj, ...) : 
#   No transformation possible from NA reference system

要解决这个问题,如上所述,您首先需要定义投影如下:

proj4string(meuse) <- CRS(paste("+init=epsg:28992",
"+towgs84=565.237,50.0087,465.658,-0.406857,0.350733,-1.87035,4.0812"))
summary(meuse) #proj4string : epsg:28992...  and then you may use spTransform

然后:

meuse.utm <- spTransform(meuse, CRS("+proj=utm +zone=32 +datum=WGS84"))
© www.soinside.com 2019 - 2024. All rights reserved.