r - Convert output from sf::st_within to vector

前端 未结 3 1132
不思量自难忘°
不思量自难忘° 2021-01-13 19:34

Im trying to use the sf package in R to see if sf object is within another sf object with the st_within function. My issue is with the output of this function w

3条回答
  •  -上瘾入骨i
    2021-01-13 19:42

    Here is how you can get a logical vector from sparse geometry binary predicate:

    df$indicator <- st_within(df, box) %>% lengths > 0
    

    or to subset without creating a new variable:

    df <- df[st_within(df, box) %>% lengths > 0,]
    

    I cannot test on your large dataset unfortunately but please let me know if it is faster than matrix approach.

提交回复
热议问题