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

发布于 2024-12-04 01:00:49 字数 1465 浏览 1 评论 0原文

我有一组坐标作为 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 

I have a set of coordinates as a SpatialPointsDataFrame object in R and I am clipping these points using a polygon to get only those points that are found within this polygon. I am doing this with the gIntersection function from the rgeos package. My problem is that the function only returns the coordinates of those points, and not the metadata associated with them. Is there some way to have gIntersection pass all data to the result, rather than only the coordinates?

Here is an example:

The SpatialPointsDataFrame representing species occurrence points:

> 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

Clipping those points to a polygon:

> 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 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦断已成空 2024-12-11 01:00:49

使用 gIntersects (不是 gIntersection)和 byid = TRUE 来获取缓冲区中的点的 TRUE/FALSE 向量。然后对点数据框进行子集化。工作完成了。

Use gIntersects (not gIntersection) with byid = TRUE to get a TRUE/FALSE vector of which points are in your buffer. Then subset your points data frame. Job done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文