Skip to contents

Spatial join, spatial filter for sftime objects

Usage

# S3 method for sftime
st_join(
  x,
  y,
  join = st_intersects,
  ...,
  suffix = c(".x", ".y"),
  left = TRUE,
  largest = FALSE
)

# S3 method for sftime
st_filter(x, y, ..., .predicate = st_intersects)

Arguments

x

An object of class sftime or sf.

y

An object of class sftime or sf.

join

A geometry predicate function with the same profile as st_intersects; see details.

...

for st_join: arguments passed on to the join function or to st_intersection when largest is TRUE; for st_filter arguments passed on to the .predicate function, e.g. prepared, or a pattern for st_relate

suffix

length 2 character vector; see merge

left

logical; if TRUE return the left join, otherwise an inner join; see details. see also left_join

largest

logical; if TRUE, return x features augmented with the fields of y that have the largest overlap with each of the features of x; see https://github.com/r-spatial/sf/issues/578

.predicate

A geometry predicate function with the same profile as st_intersects; see details.

Value

An object of class sftime, joined based on geometry.

Details

Alternative values for argument join are:

A left join returns all records of the x object with y fields for non-matched records filled with NA values; an inner join returns only records that spatially match.

Examples

g1 <- st_sfc(st_point(c(1,1)), st_point(c(2,2)), st_point(c(3,3)))
x1 <- st_sftime(a = 1:3, geometry = g1, time = Sys.time())

g2 <- st_sfc(st_point(c(10,10)), st_point(c(2,2)), st_point(c(2,2)), st_point(c(3,3)))
x2 <- st_sftime(a = 11:14, geometry = g2, time = Sys.time())

## st_join

# left spatial join with st_intersects
st_join(x1, x2)
#> Spatiotemporal feature collection with 4 features and 3 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 1 ymin: 1 xmax: 3 ymax: 3
#> CRS:           NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2023-09-01 10:23:33.615864 to 2023-09-01 10:23:33.615864.
#>     a.x a.y              time.y    geometry              time.x
#> 1     1  NA                <NA> POINT (1 1) 2023-09-01 10:23:33
#> 2     2  12 2023-09-01 10:23:33 POINT (2 2) 2023-09-01 10:23:33
#> 2.1   2  13 2023-09-01 10:23:33 POINT (2 2) 2023-09-01 10:23:33
#> 3     3  14 2023-09-01 10:23:33 POINT (3 3) 2023-09-01 10:23:33

# inner spatial join with st_intersects
st_join(x1, x2, left = FALSE)
#> Spatiotemporal feature collection with 3 features and 3 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 2 ymin: 2 xmax: 3 ymax: 3
#> CRS:           NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2023-09-01 10:23:33.615864 to 2023-09-01 10:23:33.615864.
#>     a.x a.y              time.y    geometry              time.x
#> 2     2  12 2023-09-01 10:23:33 POINT (2 2) 2023-09-01 10:23:33
#> 2.1   2  13 2023-09-01 10:23:33 POINT (2 2) 2023-09-01 10:23:33
#> 3     3  14 2023-09-01 10:23:33 POINT (3 3) 2023-09-01 10:23:33

## st_filter

st_filter(x1, x2)
#> Spatiotemporal feature collection with 2 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 2 ymin: 2 xmax: 3 ymax: 3
#> CRS:           NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2023-09-01 10:23:33.615864 to 2023-09-01 10:23:33.615864.
#>   a    geometry                time
#> 1 2 POINT (2 2) 2023-09-01 10:23:33
#> 2 3 POINT (3 3) 2023-09-01 10:23:33
st_filter(x2, x1)
#> Spatiotemporal feature collection with 3 features and 1 field
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 2 ymin: 2 xmax: 3 ymax: 3
#> CRS:           NA
#> Time column with classes: 'POSIXct', 'POSIXt'.
#> Ranging from 2023-09-01 10:23:33.619911 to 2023-09-01 10:23:33.619911.
#>    a    geometry                time
#> 1 12 POINT (2 2) 2023-09-01 10:23:33
#> 2 13 POINT (2 2) 2023-09-01 10:23:33
#> 3 14 POINT (3 3) 2023-09-01 10:23:33