You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a = plantR:::shares_border(country = 'united kingdom', country2 = 'ireland')
a
NULL
`
The polis object is an integer of value 5L and poli_u of value 7L, which does not fit any of the conditions required to return the logical FALSE/TRUE.
polis <- nrow(v) + nrow(z)
poli_u <- nrow(y)
if (polis == poli_u)
return(FALSE)
if (poli_u < polis)
return(TRUE)
}
The issue arises due to geographical units with multiple polygons in the plantR::world object, e.g., United Kingdom, Somalia, Canada, Argentina...and so on.
> v
Simple feature collection with 2 features and 2 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 40.98105 ymin: -1.68325 xmax: 51.13387 ymax: 12.02464
Geodetic CRS: WGS 84
iso_a2 name geometry
12 SO somalia MULTIPOLYGON (((41.58513 -1...
171 <NA> somalia MULTIPOLYGON (((48.9482 11....
Due to that, I simplified the function to use sf::st_intersects instead of counting the number of polygons:
my_shares_border <- function(country1 = "ireland", country2 = "united kingdom") {
world <- world
w <- world
if (!country1 %in% w$name)
country1 <- plantR::prepLoc(plantR::prepCountry(country1))
if (!country2 %in% w$name)
country2 <- plantR::prepLoc(plantR::prepCountry(country2))
if (!country1 %in% w$name | !country2 %in% w$name)
stop(paste0("Country name(s) '", c(country1,
country2)[!c(country1,
country2) %in% w$name], "' not found"))
v <- w[w$name %in% c(country1), ]
z <- w[w$name %in% c(country2), ]
intersects <- sf::st_intersects(v, z, sparse = FALSE)[1, 1]
return(intersects)
}
a = my_shares_border(country1 = 'united kingdom', country2 = 'ireland')
a
If wanted, it's possible to add a buffer to each country before using sf::st_intersects
The text was updated successfully, but these errors were encountered:
ggrittz
changed the title
internal function share_borders return NULL
internal function shares_border return NULL
Feb 24, 2025
`
The
polis
object is an integer of value 5L andpoli_u
of value 7L, which does not fit any of the conditions required to return the logical FALSE/TRUE.The issue arises due to geographical units with multiple polygons in the
plantR::world
object, e.g., United Kingdom, Somalia, Canada, Argentina...and so on.Due to that, I simplified the function to use
sf::st_intersects
instead of counting the number of polygons:If wanted, it's possible to add a buffer to each country before using
sf::st_intersects
The text was updated successfully, but these errors were encountered: