简体   繁体   English

Landscapemetrics:范围不重叠错误

[英]landscapemetrics: extents do not overlap error

I am using the landscapemetrics package to calculate landscape metrics (eg, total area, total edge length, etc.) from an input raster.我正在使用landscapemetrics包从输入栅格计算景观指标(例如,总面积、总边长等)。 I am using the sample_lsm function to perform these calculations within circular buffers centered on GPS points.我正在使用sample_lsm函数在以 GPS 点为中心的圆形缓冲区内执行这些计算。 Here is my code:这是我的代码:

library(raster)
library(terra)
library(landscapemetrics)
library(landscapetools)

landscape <- raster("~/landscape.tif")
show(landscape)

class      : RasterLayer 
dimensions : 8940, 3863, 34535220  (nrow, ncol, ncell)
resolution : 30, 30  (x, y)
extent     : 1728090, 1843980, 1968180, 2236380  (xmin, xmax, ymin, ymax)
crs        : +proj=aea +lat_0=23 +lon_0=-96 +lat_1=29.5 +lat_2=45.5 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs 
source     : landscape.tif 
names      : landscape 
values     : 0, 255  (min, max)
attributes :
        ID      COUNT Red Green Blue Opacity NLCD.Land.Cover.Class
 from:   0 7853863229   0     0    0       0          Unclassified
  to : 255          0 255   255  255     255 

points <- read.csv("~/points.csv")
points <- data.matrix(points)
apply(points, 2, range)

     longitude latitude
[1,] -75.14847 39.51212
[2,] -74.13275 41.28174

x <- sample_lsm(landscape, 
                y = points, 
                plot_id = NULL, 
                shape = "circle", 
                size = 10000, 
                what = "lsm_c_te",  
                classes_max = NULL,
                verbose = FALSE)

I am receiving the following error:我收到以下错误:

Error in .local(x, y, ...) : extents do not overlap

My interpretation of this is that my input raster (landscape) and the GPS points I provided (points) are misaligned, but I don't know why.我对此的解释是我的输入栅格(风景)和我提供的 GPS 点(点)未对齐,但我不知道为什么。 Both of these objects were created in GIS (CRS is ESRI:102039) and loaded into R Studio.这两个对象都是在 GIS 中创建的(CRS 是 ESRI:102039)并加载到 R Studio 中。 Can someone help explain how to fix this?有人可以帮助解释如何解决这个问题吗?

It looks like your points have the longitude/latitude coordinate reference system (crs), but your raster has a different crs: +proj=aea +lat_0=23 +lon_0=-96 +lat_1=29.5 +lat_2=45.5 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs .看起来您的点具有经度/纬度坐标参考系 (crs),但您的栅格具有不同的 crs: +proj=aea +lat_0=23 +lon_0=-96 +lat_1=29.5 +lat_2=45.5 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs You need to transform the point data to the coordinate reference system of the raster (not the other way around).您需要将点数据转换为栅格的坐标参考系(而不是相反)。 You can do that like this:你可以这样做:

library(terra)
landscape <- rast("~/landscape.tif")
points <- read.csv("~/points.csv")
v <- vect(points, c("longitude", "latitude"), crs="+proj=longlat")
pv <- project(v, crs(landscape))

Check to see that the points now overlap with the raster检查点现在是否与栅格重叠

plot(landscape); points(pv) 

If you need the coordinates from SpatVector pv, you can get them like this:如果你需要 SpatVector pv 的坐标,你可以像这样得到它们:

newpoints <- crds(pv)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM