【问题标题】:match coordinates and projection of a raster layer and shapefile in R匹配R中栅格图层和shapefile的坐标和投影
【发布时间】:2021-03-15 15:58:35
【问题描述】:

我正在使用两个空间对象 - 一个栅格图层和一个研究区域的 shapefile。我正在尝试将我的栅格裁剪为我的 shapefile,但我无法让坐标系匹配。

这是我的空间对象的摘要:

栅格图层

> testxx
class      : RasterLayer 
dimensions : 450, 3245, 1460250  (nrow, ncol, ncell)
resolution : 0.1109257, 0.3826826  (x, y)
extent     : -179.9964, 179.9576, -89.98608, 82.22108  (xmin, xmax, ymin, ymax)
crs        : NA 
source     : memory
names      : layer 
values     : 5.389717e-06, 0.0002052335  (min, max)

形状文件

class       : SpatialPolygonsDataFrame 
features    : 1 
extent      : 5951759, 7591708, 649338.9, 2306575  (xmin, xmax, ymin, ymax)
crs         : +proj=longlat +datum=WGS84 +no_defs 
variables   : 8
names       : PRUID,  PRNAME, PRENAME, PRFNAME, PREABBR, PRFABBR, BUFF_DIST, ORIG_FID 
value       :    35, Ontario, Ontario, Ontario,    Ont.,    Ont.,     10000,        5 

这是我试过的代码:

# Add a coordinate system to the raster
crs(testxx) <- "+proj=longlat +datum=WGS84 +no_defs"

# change shapefile coordinate system 
aoi <- spTransform(on_shp, crs(testxx))

但坐标本身仍然不匹配 - shapefile 仍然以米为单位,而栅格以纬度和经度为单位。

谢谢!

【问题讨论】:

  • 您的光栅文件可能没有 WSG1984 坐标。所以你添加了错误的crs。试着找出正确的(也许是它的兰伯特保形圆锥,因为它经常在加拿大使用)。绘制您的栅格以查看它是否有意义。然后使用 spTransform()。

标签: r coordinates transform geospatial raster


【解决方案1】:

SpatialPolygonsDataFrame 的坐标参考系统显然是错误的。鉴于此extent

extent      : 5951759, 7591708, 649338.9, 2306575  (xmin, xmax, ymin, ymax)

不可能

crs         : +proj=longlat +datum=WGS84 +no_defs 

所以你需要找出它实际上是什么。要测试它是否正确,您可以将其设置为您认为的值,然后转换为 lon/lat 并查看是否在正确的位置结束。

【讨论】:

    猜你喜欢
    • 2017-02-17
    • 2017-05-05
    • 1970-01-01
    • 2014-05-30
    • 2018-12-19
    • 1970-01-01
    • 2016-11-02
    • 1970-01-01
    • 2021-09-11
    相关资源
    最近更新 更多