如何获得不相交的积分,r
我在坐标系中有两组:A和B。B中的所有点都在A中。因此,我想选择不在B中的A中的点。 我正在使用SF库,但我有点困惑。
在这里,我显示了一个可再现的Exameple。考虑下一个数据。
fname <- system.file("shape/nc.shp", package="sf")
nc <- st_read(fname)
library(sp)
library(sf)
data(meuse)
coordinates(meuse) = ~x+y
因此,我从那里开始有接下来的两组A和B点A和B
A <- st_as_sf(meuse) %>% select(geometry) #155 obs
B <- filter(A, row_number()<= 100)%>% select(geometry) #100 obs
,我想挽救A中不在B(即剩下的55分)中的A中的点。
I have two sets of points in coordinate system: A and B. All points in B are in A. So I want to pick the points in A which are not in B.
I'm using the sf library, but I'm little stuck.
Here I show a reproducible exameple. Consider the next data.
fname <- system.file("shape/nc.shp", package="sf")
nc <- st_read(fname)
library(sp)
library(sf)
data(meuse)
coordinates(meuse) = ~x+y
So I have the next two set of points A and B
A <- st_as_sf(meuse) %>% select(geometry) #155 obs
B <- filter(A, row_number()<= 100)%>% select(geometry) #100 obs
Starting from there, I want to rescue the points in A that are not in B, i.e., the remaining 55 points.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您可以在%操作员中使用
%或
代码>。st_difference
函数。如果使用st_difference
,则可能需要ST_COMBINE
单独设置,如果这些点为sf
,则不是sfc
sfc这些方法可能会因您使用的数据类型而有所不同。它们只是点(SFC),还是与数据(SF)相关的点?
*Edit for your reproducible example:
Created on 2022-03-31 by the reprex package (v2.0.1)
Created on 2022-03-31 by the reprex package (v2.0.1)< /sup>
Looks like you can use the
%in%
operator or thest_difference
function. If usingst_difference
, you might need tost_combine
each set individually if the points aresf
but not if they'resfc
.The methods may differ a little depending on the type of data you're using. Are they just points(sfc), or are they points associated with data(sf)?
*Edit for your reproducible example:
Created on 2022-03-31 by the reprex package (v2.0.1)
Created on 2022-03-31 by the reprex package (v2.0.1)
使用 st_difference 完全没问题,但是在某些情况下,使用空间操作可能会很昂贵(时间和内存)。
因此,对于此示例,您可以考虑将数据视为
data.frame
,而不是空间对象,并使用“反连接”Using
st_difference
is perfectly fine, but, in some cases using spatial operations can be costly (in time and memory).So for this example you could consider treating the data as
data.frame
s, rather than spatial objects, and use an 'anti-join'