【发布时间】:2020-12-01 03:20:09
【问题描述】:
我正在尝试计算海岸线的暴露指数。我在沿海点周围每 5 度创建一条线。我已经擦除了在陆地上相交的部分线条。但是,它会创建我不想要的线段。 我需要:
(1) 如果直接落入马达加斯加内陆,则排除整条线(红色)
(2) 选择直线的第一段 例如删除在岛屿或任何陆地之后继续的线条(绿色/蓝色)
(3) 确保我与每个样带线的点具有相同的 ID (稍后我会调整很多点)
我无法选择特定的线段(即,如果线段与点具有相同的坐标)以及选择要删除的整条线。
see transect lines and colour references
起始坐标
point
<- class : SpatialPointsDataFrame
features : 1
extent : 45.42639, 45.42639, -15.98098, -15.98098 (xmin, xmax, ymin, ymax)
crs : +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
variables : 5
names : layer, path, Nearest_Sl, StdEr_SL, ID
提取坐标和ID
for (j in 1:length(point)){
coords <- coordinates(point)
ID <- point$ID
}
x <- cbind(ID, coords)
从点计算线
library(sp)
library(geosphere)
library(spatstat)
library(maptools)
b=seq(0,355,5) # list bearings
# Calculate ending coordinate
for(i in 1:length(b)){
temp <- destPoint(p=coords,b=b[i],d=900000)# 900 km
if(i==1){
L <- cbind(x, temp)
} else {
L <- rbind(L,cbind(x, temp))
}}
### Extracting beginning and end
begin.coord <- data.frame(lon=c(L[,2]), lat=c(L[,3]))
end.coord <- data.frame(lon=c(L[,4]), lat=c(L[,5]))
### raw list to store Lines object
p <- psp(begin.coord[,1], begin.coord[,2], end.coord[,1], end.coord[,2], owin(range(c(begin.coord[,1], end.coord[,1])), range(c(begin.coord[,2], end.coord[,2]))))
### Create spatial lines
p<- as(p, "SpatialLines")
### Remove line segments that overlap with world polygon
testclip <- raster::erase(p,world)
结果行的信息
testclip <-
class : SpatialLines
features : 67
extent : 37.22043, 53.82955, -23.82036, -7.845263 (xmin, xmax, ymin, ymax)
crs : +init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0
### Example of 10th line with 6 segmented lines
str(testclip[10,])
Formal class 'SpatialLines' [package "sp"] with 3 slots
..@ lines :List of 1
.. ..$ :Formal class 'Lines' [package "sp"] with 2 slots
.. .. .. ..@ Lines:List of 6
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:2, 1:2] 45.4 48.8 -16 -12.6
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:2, 1:2] 48.8 48.8 -12.6 -12.6
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:2, 1:2] 48.9 49 -12.5 -12.4
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:2, 1:2] 49.1 49.2 -12.3 -12.2
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:2, 1:2] 49.2 49.2 -12.2 -12.1
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. .. ..$ :Formal class 'Line' [package "sp"] with 1 slot
.. .. .. .. .. .. ..@ coords: num [1:2, 1:2] 49.3 51.2 -12.1 -10.2
.. .. .. .. .. .. .. ..- attr(*, "dimnames")=List of 2
.. .. .. .. .. .. .. .. ..$ : NULL
.. .. .. .. .. .. .. .. ..$ : chr [1:2] "x" "y"
.. .. .. ..@ ID : chr "10"
..@ bbox : num [1:2, 1:2] 45.4 -16 51.2 -10.2
.. ..- attr(*, "dimnames")=List of 2
.. .. ..$ : chr [1:2] "x" "y"
.. .. ..$ : chr [1:2] "min" "max"
..@ proj4string:Formal class 'CRS' [package "sp"] with 1 slot
.. .. ..@ projargs: chr "+init=epsg:4326 +proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0"
Testclip@lines[10]
[[1]]
An object of class "Lines"
Slot "Lines":
[[1]]
An object of class "Line"
Slot "coords":
x y
[1,] 45.42639 -15.98098
[2,] 48.82687 -12.56570
[[2]]
An object of class "Line"
Slot "coords":
x y
[1,] 48.83505 -12.55749
[2,] 48.83534 -12.55720
[[3]]
An object of class "Line"
Slot "coords":
x y
[1,] 48.89905 -12.49321
[2,] 48.95112 -12.44091
[[4]]
An object of class "Line"
Slot "coords":
x y
[1,] 49.12860 -12.26266
[2,] 49.15358 -12.23757
[[5]]
An object of class "Line"
Slot "coords":
x y
[1,] 49.23665 -12.15414
[2,] 49.24262 -12.14814
[[6]]
An object of class "Line"
Slot "coords":
x y
[1,] 49.33568 -12.05468
[2,] 51.22424 -10.15790
Slot "ID":
[1] "10"
【问题讨论】:
-
这已被标记为“spatstat”,但它与 spatstat 包没有任何关系。
-
@AdrianBaddeley 我使用了 psp 函数,所以我想知道我的问题的第 (3) 部分如何确保创建的每一行都有点的 ID。目前,它计算 1:72 行作为 ID。
标签: r spatial sp spatstat geosphere