我有一个大学和学院的形状档案,可以在这里找到:

https://hifld-geoplatform.opendata.arcgis.com/datasets/bc7ef39f9d2a4605b9d5aad0e050af11/explore?location=30.280984%2C-97.732610%2C14.74

目标是通过各个经纬度坐标数据集运行shapefile,以查看哪些坐标属于大学shapefile的范围.因此,这些坐标将存储在名为id_coordinates的数据集中

id_coordinates <- st_as_sf(id_coordinates, coords = c("id_longitude", "id_latitude"), crs = 4326)

然后我们打开shapefile本身:

# Set the file paths for the shapefiles
college_fp <- "Colleges_and_Universities_Campuses/CollegeUniversityCampuses.shp"

# Read in the shapefiles
college_sf <- st_read(college_fp) %>% filter(STATE == 'VA') 

然后我们将id_coordinates转换为与college_sf一致

id_coordinates_transform <- st_transform(pa_vf, st_crs(college_sf))

然后,我们将它们连接在一起,以查看哪些ID具有落入shapefile边界内的经度/长度:

results_join <- st_join(id_coordinates_transform, college_sf, join = st_within)

但是,如果我想在college_sf中找到的shapefile周围再创建一个半径为1英里的"缓冲区",我该怎么办呢?那会是什么样子?

编辑:使用st_buffer函数,但这似乎让它变得太大了?

buffer_radius <- 1609.34
college_sf_buffer <- st_buffer(college_sf, dist = buffer_radius)

推荐答案

您需要指定st_buffer的单位:

library(sf)
#> Linking to GEOS 3.9.3, GDAL 3.5.2, PROJ 8.2.1; sf_use_s2() is TRUE
library(tidyverse)

college_sf <- st_read(college_fp) |> filter(STATE == 'VA') 

college_sf_buffer <- st_buffer(college_sf, dist = units::set_units(1609.34, m))

这似乎给出了合理的结果:

college_sf_buffer |>
  ggplot() +
  geom_sf(fill = "red")

enter image description here

创建于2023-10-16年第reprex v2.0.2

R相关问答推荐

这两种创建S4对象的方法有何不同?

将coord_sf与geom_spatraster一起使用会更改分辨率

如何使用R以NASAGIBS.ViirsEarthAtNight2012风格绘制自定义 map

根据列中的数字移动单元格位置

过滤矩阵以获得R中的唯一组合

如何在四进制仪表板值框中显示值(使用shiny 的服务器计算)

根据列表中项目的名称多次合并数据框和列表

管道末端运行功能

为什么当我try 在收件箱中使用合并功能时会出现回收错误?

将年度数据插入月度数据

为什么观察不会被无功值变化触发?

如何在格子中添加双曲曲线

根据日期从参考帧中创建不同的帧

如何在分组条形图中移动相关列?

无法正确设置动态创建的Quarto标注的格式

以相同的方式对每个表进行排序

使用RSelenium在R中抓取Reddit时捕获多个标签

多元正态分布的计算

按组和连续id计算日期差

将数据从一列转换为按组累计计数的单个虚拟变量