diff --git a/R/geolocate_polygon.R b/R/geolocate_polygon.R index aad486c6..22ca6f2f 100644 --- a/R/geolocate_polygon.R +++ b/R/geolocate_polygon.R @@ -97,11 +97,11 @@ parse_polygon <- function(query, # to avoid any issues, any polygons are converted to multipolygons if(inherits(query, "sf") || inherits(query, "sfc")) { - if(length(query$geometry) < 2) { + if(length(sf::st_geometry(query)) < 2) { out_query <- build_wkt(query) } else { # multiple polygons - n_polygons <- length(query$geometry) + n_polygons <- length(sf::st_geometry(query)) c("Too many polygons.", i = "`galah_polygon` cannot accept more than 1 polygon at a time.", x = "{n_polygons} polygons detected in spatial object.") |> diff --git a/R/geolocate_radius.R b/R/geolocate_radius.R index 2dd410b7..20120767 100644 --- a/R/geolocate_radius.R +++ b/R/geolocate_radius.R @@ -57,8 +57,9 @@ parse_point_radius <- function(..., } # extract point coordinate values - lat <- sf::st_coordinates(coords)[1] - lon <- sf::st_coordinates(coords)[2] + # (`st_coordinates()` returns columns in X (longitude), Y (latitude) order) + lon <- sf::st_coordinates(coords)[1] + lat <- sf::st_coordinates(coords)[2] } else { # Coords are supplied as lon/lat arguments diff --git a/tests/testthat/test-geolocate_radius.R b/tests/testthat/test-geolocate_radius.R index f9baac30..35b465fe 100644 --- a/tests/testthat/test-geolocate_radius.R +++ b/tests/testthat/test-geolocate_radius.R @@ -29,7 +29,7 @@ test_that("`geolocate_radius()` assigns default radius when missing argument", { }) test_that("`geolocate_radius()` returns radius for sf_POINT object", { - point <- sf::st_sfc(sf::st_point(c(-33.66741, 151.3174)), + point <- sf::st_sfc(sf::st_point(c(151.3174, -33.66741)), crs = 4326) expected_object <- list(lat = -33.66741, lon = 151.3174,