Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should galah_geolocate handle shapefiles with multiple POLYGONs? #191

Open
daxkellie opened this issue Apr 20, 2023 · 0 comments
Open

Should galah_geolocate handle shapefiles with multiple POLYGONs? #191

daxkellie opened this issue Apr 20, 2023 · 0 comments
Labels
enhancement New feature or request

Comments

@daxkellie
Copy link
Collaborator

galah_geolocate() is able to filter records using shapefiles. However, it is only able to handle one POLYGON at a time. Although this works in many cases, the issue is that many shapefiles contain more than one POLYGON. For example, maps of regions or subregions require multiple POLYGON rows to draw each region's shape.

galah_geolocate errors when shapefiles are supplied with multiple POLYGON rows. For example, in this shapefile containing ACT suburbs, supplying one ACT suburb returns a result, but supplying two causes an error

# one suburb
> galah_call() |>
+   galah_identify("eolophus") |>
+   galah_geolocate(actsuburbs$geometry[1]) |>
+   atlas_species()
# A tibble: 1 × 10                                                                                                                                                               
  kingdom  phylum   class order          family     genus    species               author           species_guid                       verna…¹
  <chr>    <chr>    <chr> <chr>          <chr>      <chr>    <chr>                 <chr>            <chr>                              <chr>  
1 Animalia Chordata Aves  Psittaciformes Cacatuidae Eolophus Eolophus roseicapilla (Vieillot, 1817) https://biodiversity.org.au/afd/t… Galah  
# … with abbreviated variable name ¹​vernacular_name

# two suburbs
> galah_call() |>
+   galah_identify("eolophus") |>
+   galah_geolocate(actsuburbs$geometry[1:2]) |>
+   atlas_species()
Error in if (is.na(valid)) { : the condition has length > 1

Should galah_geolocate be able to handle shapefiles with multiple POLYGON rows? At the moment, if the user wanted a result for the entire area of the shapefile galah_geolocate(type = "bbox") is one work around for this, but would require additional filtering after a download.

> galah_call() |>
+   galah_identify("eolophus") |>
+   galah_geolocate(sf::st_bbox(actsuburbs$geometry[1:2]),
+                   type = "bbox") |>
+   atlas_species()
Data returned for bounding box:
xmin = 149.09752 xmax = 149.16046 ymin = -35.29685 ymax = -35.25041
# A tibble: 1 × 10                                                                                                                                                               
  kingdom  phylum   class order          family     genus    species               author           species_guid                       verna…¹
  <chr>    <chr>    <chr> <chr>          <chr>      <chr>    <chr>                 <chr>            <chr>                              <chr>  
1 Animalia Chordata Aves  Psittaciformes Cacatuidae Eolophus Eolophus roseicapilla (Vieillot, 1817) https://biodiversity.org.au/afd/t… Galah  
# … with abbreviated variable name ¹​vernacular_name

Alternatively, if the user wanted one query per POLYGON (in this case, one query per suburb), they could use purrr::map() to loop a query over each one. However, this requires some fairly advanced looping.

At the very least, it would be useful to update the error message to be more informative about this limitation of galah_geolocate(), but perhaps handling multiple POLYGONs is a functionality that should be added to galah_geolocate()?

@daxkellie daxkellie added the enhancement New feature or request label Jun 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant