Skip to contents

Returns where each pair of lines meets: a point when they cross, and a line when they overlap along a shared stretch. ga_line_intersection() recycles y against x.

Usage

ga_line_intersection(x, y)

Arguments

x

a GeoArrow array of two point linestrings

y

a GeoArrow array of two point linestrings; length 1 or the same length as x

Value

a GeoArrow multipoint array of the same length as x

Details

ga_line_intersection() finds a point when the lines cross and a segment when they overlap. It returns both as a multipoint to give the column one type: one point for a crossing, and the two endpoints of the shared stretch for an overlap. So ga_n_coords() tells the two apart, and you can rebuild an overlap from its endpoints.

ga_line_intersection() needs single segments in both arguments, that is a LINE or a two point LINESTRING. It returns null for longer linestrings, other geometry types, and null rows, and for pairs that simply do not meet. Use ga_self_intersections() for a geometry with many segments.

References

line_intersection

See also

Other intersection: ga_self_intersections()

Examples

a <- sf::st_linestring(cbind(c(0, 2), c(0, 2)))
b <- sf::st_linestring(cbind(c(0, 2), c(2, 0)))
x <- geoarrow::as_geoarrow_array(sf::st_sfc(a))
y <- geoarrow::as_geoarrow_array(sf::st_sfc(b))

sf::st_as_sfc(geoarrow::as_geoarrow_vctr(ga_line_intersection(x, y)))
#> Geometry set for 1 feature 
#> Geometry type: MULTIPOINT
#> Dimension:     XY
#> Bounding box:  xmin: 1 ymin: 1 xmax: 1 ymax: 1
#> CRS:           NA
#> MULTIPOINT ((1 1))