r - 在 R 中使用 rgeos 包中的 gIntersection 时保留元数据

标签 r gis clip

我有一组坐标作为 R 中的 SpatialPointsDataFrame 对象,我正在使用多边形裁剪这些点以仅获取在该多边形内找到的那些点。我正在使用 rgeos 包中的 gIntersection 函数执行此操作。我的问题是该函数只返回这些点的坐标,而不是与它们关联的元数据。有没有办法让 gIntersection 将所有数据传递给结果,而不仅仅是坐标?

下面是一个例子:

代表物种出现点的 SpatialPointsDataFrame:

> spexample
            coordinates SpAbbr InstitutionCode CatalogNumberText
1   (-76.8727, 3.66282) BanRot       EBIRD_COL       OBS81997559
2   (-76.9749, 3.71683) BanRot          AUDCLO       OBS89767945
3    (-76.884, 3.61609) BanRot          AUDCLO       OBS89769896
4   (-77.5167, 5.51667) BanRot            AMNH       Skin-123476
5   (-76.0334, 4.86669) BanRot            LACM             34848
6   (-78.4333, 1.43333) BanRot           LSUMZ             38939
7        (-78.55, 0.95) BanRot            ANSP            182799
8  (-79.2139, 0.471944) BanRot          AUDCLO       OBS58485973
9  (-78.5104, 0.895349) BanRot          AUDCLO       OBS84822747
10  (-78.3781, 1.51028) BanRot          AUDCLO       OBS67916517
11       (-75.15, 7.07) BanRot   8110002317-09         4743-5160

将这些点裁剪为多边形:
> gIntersection(spexample,bufferclip)
SpatialPoints:
          x         y
1 -78.55000 0.9500000
1 -78.51036 0.8953493
1 -78.43333 1.4333333
1 -78.37810 1.5102800
1 -76.97495 3.7168289
1 -76.88397 3.6160872
1 -76.87271 3.6628163
1 -76.03337 4.8666900
Coordinate Reference System (CRS) arguments: +proj=longlat +datum=WGS84
+ellps=WGS84 +towgs84=0,0,0 

最佳答案

使用带有 byid = TRUE 的 gIntersects(而不是 gIntersection)来获取缓冲区中哪些点的 TRUE/FALSE 向量。然后子集您的点数据框。任务完成。

关于r - 在 R 中使用 rgeos 包中的 gIntersection 时保留元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7368054/

相关文章:

r - 如何在 R 中绘制约束

gis - 将栅格 GIS 数据应用于补丁的更快方法 netlogo

r - R中多边形内点(shapefile)的选择和提取

android - 非透明像素上的 ImageView 颜色过滤器。夹子

html - 如图所示,使用纯 CSS 生成剪辑路径时出现问题

r - 基于分类变量,在 R 中从数据框中子集 n 行

r - 使用百分比创建马赛克图

c# - C#中2个纬度/经度点之间的方向

r - 如何计算大型数据集每分钟出现的次数

c++ - 本地版 Google Maps API