r - bbox 中的子集类 sfc_LINESTRING 和 sfc 对象
问题描述
例子:
bbox <- c(-0.1178, 51.4232, -0.0185, 51.5147) # I know it needs to be sf df object
# we have
df
#> Geometry set for 300 features
#> geometry type: LINESTRING
#> dimension: XY
#> bbox: xmin: -0.113894 ymin: 51.49739 xmax: -0.0764779 ymax: 51.59839
#> epsg (SRID): 4326
#> proj4string: +proj=longlat +datum=WGS84 +no_defs
#> LINESTRING (-0.113894 51.50631, -0.1135137 51.5...
#> LINESTRING (-0.0767875 51.59837, -0.0764779 51....
#> ....
我该怎么做
df[bbox]
并保留 bbox 内的线串。谢谢。
解决方案
这是一个使用来自 的sf
对象的示例tigris
,只是为了重现性。我正在使用康涅狄格州纽黑文县的城镇,以它进入的方式绘制它。然后我将它裁剪到我制作的边界框,使用st_crop
,我相信它是最近添加到sf
. 如果我将 bbox 作为形状,而不是坐标向量,我可以使用st_intersection
.
我没有方便的线串对象,但我认为它的工作方式相同。
library(tidyverse)
library(sf)
# selecting just to limit the amount of data in my sf
ct_sf <- tigris::county_subdivisions(state = "09", county = "09", cb = T, class = "sf") %>%
select(NAME, geometry)
plot(ct_sf)
crop_bbox <- c(xmin = -73, ymin = 41.2, xmax = -72.7, ymax = 41.5)
ct_cropped <- st_crop(ct_sf, crop_bbox)
plot(ct_cropped)
推荐阅读
- c++ - std::vector< base_class * > iterate using base but call derived classes function
- java - 如何访问膨胀布局内的 TextView 的值
- r - cSplit(data,“text”,“,”,“long”)之后如何管理重复项?
- android - Android Studio:已创建数据库但未创建表
- c++ - 即使输入是另一种数据类型,C++ cin.fail() 也会执行并移至下一行
- r - 无论是否不存在某些列,都在列集上设置数据帧
- excel - 根据单元格值添加/删除行
- c# - 在页面加载事件期间加载时,下拉列表控件被另一个控件覆盖
- c++ - 如何使 Visual Studio 在为一个配置编译时忽略某些代码行,但在其他配置中不忽略
- html - 多个 li 标签