paleolimbot / geos

Open Source Geometry Engine ('GEOS') R API
https://paleolimbot.github.io/geos/
Other
61 stars 8 forks source link

Return list of integers in matrix predicates #89

Open kadyb opened 1 year ago

kadyb commented 1 year ago
library("sf")
library("geos")

poly_sf = st_bbox(c(xmin = 0, xmax = 1, ymax = 0, ymin = 1), crs = st_crs(2180))
poly_sf = st_as_sfc(poly_sf)
pts_sf = st_sample(poly_sf, size = 10)
pts_geos = as_geos_geometry(pts_sf)
poly_geos = as_geos_geometry(poly_sf)

intersects_sf = sf::st_intersects(pts_sf, poly_sf)
typeof(intersects_sf[[1]])
#> [1] "integer"

intersects_geos = geos_intersects_matrix(pts_geos, poly_geos)
typeof(intersects_geos[[1]])
#> [1] "double"

Value A list() of integer vectors containing the indices of tree for which the predicate would return TRUE.

The documentation says a list of integers will be returned, but it's actually double. The second issue, functions with the _any suffix return a logical vector.

paleolimbot commented 1 year ago

I should update the documentation...returning double allows support for vectors with more than 2 billion points (as rare as that is). Is the fact that it's not an integer causing a problem somewhere?

kadyb commented 1 year ago

This is a good point. Integer has the advantage of taking up half the space than double. For example, {sf} just returns an integer, but like you said it won't work above 2 billion. The final decision is yours 😃