bbox 中的子集 class sfc_LINESTRING & sfc 对象
Subset class sfc_LINESTRING & sfc objects within a bbox
示例:
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 内的线串。谢谢
这是一个使用 tigris
中的 sf
对象的示例,只是为了可重现性。我正在使用康涅狄格州纽黑文县的城镇,按照它进来的方式绘制它。然后我将它裁剪到我制作的边界框,使用 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)
示例:
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 内的线串。谢谢
这是一个使用 tigris
中的 sf
对象的示例,只是为了可重现性。我正在使用康涅狄格州纽黑文县的城镇,按照它进来的方式绘制它。然后我将它裁剪到我制作的边界框,使用 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)