Skip to content

polygon order Error: Polygon with clockwise exterior ring: #848

Description

@beausoleilmo

I used a custom polygon in rgbif::occ_download and got this error

pol_wkt = "POLYGON ((-80.43372 47.0636, -79.81893 52.32097, -80.92362 54.72415, -77.77697 56.47879, -79.87082 58.54605, -79.32995 62.70702, -72.96321 63.06364, -68.36592 61.4554, -67.4021 59.34233, -65.65498 60.91404, -63.60196 60.7996, -62.17351 58.8368, -62.17406 55.19059, -63.23293 54.00381, -66.31831 54.06506, -65.16292 53.0203, -63.65638 53.62978, -58.17867 53.37907, -55.83661 52.0045, -60.70562 46.36289, -62.5469 46.18651, -64.336 47.45411, -66.34416 47.35701, -68.86137 46.63709, -70.35774 44.65409, -74.17295 44.31865, -79.22104 45.75107, -80.43372 47.0636))"

download_key <- rgbif::occ_download(
  rgbif::pred(key = "OCCURRENCE_STATUS", value = "present"),
  rgbif::pred_in(key = "BASIS_OF_RECORD", 
                 value = c("MACHINE_OBSERVATION", "HUMAN_OBSERVATION")),
  rgbif::pred_within(
    value = pol_wkt
  ),
  format = "SIMPLE_PARQUET"
)

Error: Polygon with clockwise exterior ring: POLYGON (([...]))

But this makes it work.

pol_wkt =   pol_wkt |> 
  sf::st_geometry() |>
  sf::st_make_valid() |>
  # Pts polygon 'CW' clockwise.
  lwgeom::st_force_polygon_cw() |>
  st_reverse() |> 
    # GBIF requires CRS epsg:4326 (WGS 84, latitude + longitude) 
    st_transform(crs = 4326) |> 
    # text only
    sf::st_as_text()

Should this be included in the function to make it easier when providing a polygon ?

packageVersion("rgbif")
[1] ‘3.8.1’

Might be related to this : #712

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions