mapme-initiative / mapme.biodiversity

Efficient analysis of spatial biodiversity datasets for global portfolios
https://mapme-initiative.github.io/mapme.biodiversity/dev
GNU General Public License v3.0
33 stars 7 forks source link

MULTIPOLYGONs in init_portfolio() #248

Closed KornTob closed 6 months ago

KornTob commented 6 months ago

Hello, I ran into an issue with the init_portfolio() function when supplying an sf object that contains POLYGON and MULTIPOLYGON objects. I see the help file for init_portfolio() states: "... its first argument that contains only geometry of type POLYGON or MULTIPOLYGON." I read it that it must be either of the two. When I supply my sf object, I get the error message:

Fehler in init_portfolio(mp_sf, years = 2010:2023) : Some assests are not of type POLYGON. Please use sf::st_cast() to cast to POLYGON.

The error is easy to solve with st_cast(), but I think the help file should be clear on that. Does it mean that all objects must be of the same type? Below a reproducable example:

`` require("sf"); require("terra")

mp_sf <- gadm(country="IRQ",level=2)

mp_sf <- st_as_sf(mp_sf)

unique(as.character(st_geometry_type(mp_sf))) # POLYGON and MULTYPOLYGON

sources <- init_portfolio(mp_sf, years = 2010:2023) # This throws the error

sources <- init_portfolio(st_cast(mp_sf,"POLYGON"), years = 2010:2023) # No problem when casting to polygon ``

goergen95 commented 6 months ago

Thanks for spotting this. You are absolutely right and here the documentation is out of sync with the implementation. The Quickstart is more to the point, in this regard. A PR is underway to correct this.