如何测量R中插入两个特征之间的SF Linestring的长度长度?
我有一个以林格格式的数据集和一个海洋测深的多轨道(具有深度信息的几行)。我的目的是测量每个深度范围(在两个多弹力之间)的这些线条的长度截面,并具有每个间隔的总和长度。
interval length
1 -2250 and -2500 5200.56 [m]
2 -2500 and -2750 xxxxxxx [m]
3 -2750 and -3000 xxxxxxx [m]
4 -3000 and -3250 xxxxxxx [m]
但是,当我使用st_intersection()时,我可以得到这一行的深度,但是除了有关深度的信息,例如 - 1500 m而不是间隔(例如:-1500 m至-1750 m)我无法测量长度为st_intersection()仅计数相交点。有办法在R中做到这一点吗?
数据集示例
library(sf)
library(dplyr)
#creating dataset
id <- c("A","A", "B","B","C","C")
lat <- c(-25.31157, -25.42952, -25.4253, -25.19177, -25.18697, -25.12748)
long <- c(-41.39523, -39.99665, -41.00311, -41.29756, -41.30314, -39.37707)
df <- dplyr::tibble(id = as.factor(id), lat, long)
#convert sf
df.sf = sf::st_as_sf(df,
coords = c("long","lat"),
crs = 4326)
#creating linestrings
lines <- df.sf %>%
dplyr::group_by(id) %>%
dplyr::summarise(do_union = FALSE) %>%
sf::st_cast("LINESTRING")
######attempt at something similar:
#intersect
intersection <- sf::st_intersection (bathy, lines) %>% sf::st_as_sf() %>%
dplyr::mutate(length=sf::st_length(.)) %>%
sf::st_drop_geometry()
#sum length per depth
output <- intersection %>%
group_by(depth) %>%
summarise(length = sum(length)) %>%
arrange(desc(length))
> output
depth length[m]
1 -2250 0 [m]
2 -2500 0 [m]
3 -2750 0 [m]
4 -3000 0 [m]
不幸的是,我无法在此处重新创建多线序列的子集,因此我在必要时放入github以下载Shapefile格式的子集,只需单击“”代码”,然后在“下载zip” 在此处输入链接描述。对象就是这样:
> bathy
Simple feature collection with 15690 features and 1 field
Geometry type: MULTILINESTRING
Dimension: XY
Bounding box: xmin: -53.37185 ymin: -35.77762 xmax: -25 ymax: 7.081626
Geodetic CRS: WGS 84
First 10 features:
PROFUNDIDA geometry
1 -50 MULTILINESTRING ((-52.4267 ...
2 -50 MULTILINESTRING ((-52.77632...
3 -75 MULTILINESTRING ((-51.04274...
4 -75 MULTILINESTRING ((-52.38656...
5 -100 MULTILINESTRING ((-51.07005...
6 -100 MULTILINESTRING ((-52.18633...
7 -200 MULTILINESTRING ((-51.97665...
8 -300 MULTILINESTRING ((-51.95862...
9 -400 MULTILINESTRING ((-51.94465...
10 -500 MULTILINESTRING ((-51.93161...
I have a dataset in linestring format and an ocean bathymetry multilinestring (several lines with depth information). My aim is to measure the length section of these linestrings at each depth range (between two multilinestrings) and to have the sum lengths per interval.
EXPECTED OUTPUT EXAMPLE
interval length
1 -2250 and -2500 5200.56 [m]
2 -2500 and -2750 xxxxxxx [m]
3 -2750 and -3000 xxxxxxx [m]
4 -3000 and -3250 xxxxxxx [m]
But, when I use st_intersection() I can get what depth this stretch of line is, but besides the information that comes about the depth being for example -1500 m instead of an interval, (example: -1500 m to -1750 m) I can't measure the length as st_intersection() only counts intersection points. Are there way to make this in r?
DATASET EXAMPLE
library(sf)
library(dplyr)
#creating dataset
id <- c("A","A", "B","B","C","C")
lat <- c(-25.31157, -25.42952, -25.4253, -25.19177, -25.18697, -25.12748)
long <- c(-41.39523, -39.99665, -41.00311, -41.29756, -41.30314, -39.37707)
df <- dplyr::tibble(id = as.factor(id), lat, long)
#convert sf
df.sf = sf::st_as_sf(df,
coords = c("long","lat"),
crs = 4326)
#creating linestrings
lines <- df.sf %>%
dplyr::group_by(id) %>%
dplyr::summarise(do_union = FALSE) %>%
sf::st_cast("LINESTRING")
######attempt at something similar:
#intersect
intersection <- sf::st_intersection (bathy, lines) %>% sf::st_as_sf() %>%
dplyr::mutate(length=sf::st_length(.)) %>%
sf::st_drop_geometry()
#sum length per depth
output <- intersection %>%
group_by(depth) %>%
summarise(length = sum(length)) %>%
arrange(desc(length))
> output
depth length[m]
1 -2250 0 [m]
2 -2500 0 [m]
3 -2750 0 [m]
4 -3000 0 [m]
I unfortunately couldn't recreate a subset of the multilinestring object here, so I put in my github to download a subset in shapefile format if necessary, just click on "CODE" and then on "download ZIP" enter link description here. The object is like this:
> bathy
Simple feature collection with 15690 features and 1 field
Geometry type: MULTILINESTRING
Dimension: XY
Bounding box: xmin: -53.37185 ymin: -35.77762 xmax: -25 ymax: 7.081626
Geodetic CRS: WGS 84
First 10 features:
PROFUNDIDA geometry
1 -50 MULTILINESTRING ((-52.4267 ...
2 -50 MULTILINESTRING ((-52.77632...
3 -75 MULTILINESTRING ((-51.04274...
4 -75 MULTILINESTRING ((-52.38656...
5 -100 MULTILINESTRING ((-51.07005...
6 -100 MULTILINESTRING ((-52.18633...
7 -200 MULTILINESTRING ((-51.97665...
8 -300 MULTILINESTRING ((-51.95862...
9 -400 MULTILINESTRING ((-51.94465...
10 -500 MULTILINESTRING ((-51.93161...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是一个粗略的答案,可能会有所帮助。如果您的数据较小,则更容易提供Reprex。只需选择绝对最小数据即可重现您的问题,它有助于。
在这种情况下,您所需要的只是一条路线的一线线,只有几个测深的衬里。我建议您大量子集,然后使用
datapasta
package> package>reprex
制作一个可以轻松发布的示例。假设
交集
是仅1linestring
与浴数据的交集,这可能有效:Here's a rough answer that might help. It would be easier to provide a reprex if your data was smaller. It helps to just pick the absolute minimum amount of data to reproduce your problem.
In this case, all you would need is one linestring for a path, and just a couple bathymetry linestrings. I suggest subsetting your data a lot, and then using the
datapasta
package orreprex
to make an example that can be posted easily.Assuming
intersection
is the intersection of just 1LINESTRING
with the bathy data, this might work: