wpgp / wopr

An R package and Shiny application to provide API access to the WorldPop Open Population Repository (WOPR)
https://apps.worldpop.org/woprVision
GNU General Public License v3.0
36 stars 7 forks source link

problem with getPop #21

Closed rafapereirabr closed 3 years ago

rafapereirabr commented 3 years ago

Hi all.

I'm having a problem with the wopr::getPop() function. It throws an error about the geometries class, even though my input is in the class require. Please see the reprex below.

ps. Congrats on such a fantastic project and set of packages!

reprex

library(sf)
library(geobr)
library(wopr)

# download area of interest
my_area <- geobr::read_state(code_state = 'DF')

class( st_geometry(my_area) )
> [1] "sfc_MULTIPOLYGON" "sfc" 

# get population estimate
pop <- wopr::getPop(feature = my_area,
                    country = 'BRA')

> Error in endpoint(features = feature, agesex = length(agesex_select) <  : 
                      Input feature geometries must be of class "sfc_POLYGON", "sfc_MULTIPOLYGON", "sfc_POINT", or "sfc_MULTIPOINT"
doug-leasure commented 3 years ago

Hi @rafapereirabr,

Thanks for raising this issue. The error message that you got was incorrect and I have now revised the message so that it will be more informative in the future. The problem was that our WOPR database does not contain population estimates for Brazil, and so you should now see this error message:

There are no data available for spatial queries for this country (BRA). Use wopr::getCatalogue(spatial_query=T) to get a list of data that can be queried using points or polygons. See https://wopr.worldpop.org for a list of all data available on WOPR.

The WorldPop Global project has created gridded population estimates that include Brazil. You should be able to get population estimates for your polygons using the wpCPR package developed by @bondarenkom .

Thanks again for raising the issue and let us know if you have any problems with wpCPR.

Best, -Doug

rafapereirabr commented 3 years ago

Thank you, @doug-leasure. This is very helpful. I thought Brazil was included because it is listed here. I guess I must have mixed things up.