最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

r - How to get intersecting values between two polygon layers? - Stack Overflow

programmeradmin0浏览0评论

I need help with R code to calculate intersecting area between two polygon layers. The first layer is polygons I created by making a 250m buffer around a points layer - I'm calling it "buffer" - it's a layer from a geopackage.

The second layer is one large polygon - called "zones". The zones polygon overlaps the buffer polygons and I want to calculate how much of the "zone" polygon lies within each buffer polygon. I have a field in my buffer polygon layer called "unique_id" that identifies each polygon.

I've tried the code below but it's not working as I end up with the exact same value for area and length in each row when it should be quite variable.

library(sf)
library(dplyr)
library(tidyr)
library(units)

points <- st_read("/Users/Documents/ArcGIS/points.gpkg",layer = "points")


# 250m buffer around each point with unique_id
buffer <- points %>%
  select(unique_id) %>%  
  st_buffer(dist = 250)

zones <- st_read("/Users/Documents/ArcGIS/Working.gdb",layer="zones_clipped")

# check that both layers have same coordinate reference system
st_crs(buffer) == st_crs(zones)
# TRUE

# check geometry types
st_geometry_type(buffer)
# polygons
st_geometry_type(zones)
# multipolygon

# create intersecting values between buffer and zones layers
zone_intersections <- buffer %>%
  group_by(unique_id) %>%  
  st_intersection(zones) %>%
  ungroup()

head(zone_intersections)

> head(zone_intersections)
Simple feature collection with 6 features and 3 fields
Geometry type: MULTIPOLYGON
Dimension:     XYZ
Bounding box:  xmin: 1051092 ymin: 430804.8 xmax: 1051526 ymax: 431173.9
z_range:       zmin: 0 zmax: 0
Projected CRS: NAD83 / BC Albers
# A tibble: 6 × 4
  unique_id Shape_Length Shape_Area                                                                                    geom
      <int>        <dbl>      <dbl>                                                                      <MULTIPOLYGON [m]>
1     12581    12330347. 600783573. Z (((1051439 430883 0, 1051429 430875 0, 1051418 430867.6 0, 1051407 430860.8 0, 105...
2     12582    12330347. 600783573. Z (((1051432 430874.1 0, 1051421 430867.3 0, 1051409 430861 0, 1051397 430855.4 0, 1...
3     12583    12330347. 600783573. Z (((1051413 430859.4 0, 1051401 430854.4 0, 1051389 430850 0, 1051376 430846.3 0, 1...
4     12584    12330347. 600783573. Z (((1051409 430849.3 0, 1051397 430843.7 0, 1051385 430838.7 0, 1051373 430834.3 0,...
5     12585    12330347. 600783573. Z (((1051395 430826.4 0, 1051383 430821.4 0, 1051374 430818.2 0, 1051374 430821.1 0,...
6     12870    12330347. 600783573. Z (((1051301 430988.4 0, 1051297 430993.6 0, 1051298 430993.5 0, 1051303 431000.3 0,...
> 

发布评论

评论列表(0)

  1. 暂无评论