简体   繁体   English

与多个人创建空间线 Object

[英]Creating a Spatial Line Object with multiple individuals

I am trying to create a spatial line for multiple individuals in my dataset to then extract raster values across the line.我正在尝试为我的数据集中的多个人创建一条空间线,然后跨线提取栅格值。

I have tried a few things but unfortunately the code I am using is assigning all the line to one individual.我已经尝试了一些事情,但不幸的是我正在使用的代码将所有线路分配给一个人。

WD is the dataset which has 37 individuals in it. WD是其中有37个人的数据集。 x and y are the coordinates. x 和 y 是坐标。

line_obj <- sp::Line(cbind(WDm2$x,WDm2$y))

lines_obj <- sp::Lines(list(line_obj),ID=WDm2$DogName)
Error in sp::Lines(list(line_obj), ID = WDm2$DogName) : 
  Single ID required


firstLine <- sp::SpatialLines(list(lines_obj))

If anyone knows how to do this, I would appreciate the help.如果有人知道如何执行此操作,我将不胜感激。 thanks!谢谢!

I would like to be able to extract raster values along the lines.我希望能够沿线提取栅格值。

Some example data一些示例数据

x1 <- rbind(c(-180,-20), c(-140,55), c(10, 0), c(-140,-60))
x2 <- rbind(c(-10,0), c(140,60), c(160,0), c(140,-55))
x3 <- rbind(c(-125,0), c(0,60), c(40,5), c(15,-45))

Use raster::spLines使用raster::spLines

library(raster)
a <- spLines(x1, x2, x3, crs="+proj=longlat")
a
#class       : SpatialLines 
#features    : 3 
#extent      : -180, 160, -60, 60  (xmin, xmax, ymin, ymax)
#crs         : +proj=longlat 

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

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