【问题标题】:Shapefiles do not overlay raster layer in R形状文件不会覆盖 R 中的栅格图层
【发布时间】:2019-11-10 20:52:08
【问题描述】:

我有数百个没有坐标参考系统的 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】:

    你需要先使用proj4string(meuse)crs(shapefile)<-crs string定义shape文件的投影,然后你可以使用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"))
    

    【讨论】:

    • spTranform 方法不适用于定义投影。我相信我失败了,因为 shapefile 的坐标不在 lonlat 中。 WorldClim 网站指出可用的栅格没有投影,并且使用纬度和经度 lonlat 坐标来定义栅格 CRS。根据空间参考网站link,longlat 相当于 EPGS4326。我试图为 EPGS4326 定义 shapefile 的投影但没有成功。
    • 我没有说:spTranform 方法可以用来定义投影。我说的是你需要为你的 shapefile 定义原始的crs(可以是否则而不是lonlat)。 EPGS4326 适用于 WorldCom,但如果它不适用于您的 shapefile,则与它无关!您必须为您的 shapefile 找到原始的 crs,这并不复杂。将其定义为它是什么,然后您就可以转换它了!!定义和转换不一样(看看我的 example 脚本)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-06-30
    • 2013-09-28
    • 1970-01-01
    • 1970-01-01
    • 2016-03-09
    • 2018-07-05
    相关资源
    最近更新 更多