prioritizr / wdpar

Interface to the World Database on Protected Areas
https://prioritizr.github.io/wdpar
GNU General Public License v3.0
37 stars 5 forks source link

The package not run for previous download data, and do not start a new download data #49

Closed karolazvdo closed 2 years ago

karolazvdo commented 2 years ago

I've been trying to run the tutorial example, but the error happens since the first step to download data for mapping the protected areas.

mlt_raw_pa_data <- wdpa_fetch("Malta", wait = TRUE, download_dir = rappdirs::user_data_dir("wdpar")) Error in checkError(res) : Undefined error in httr call. httr output: Failed to connect to localhost port 4567: Connection refused lie_raw_data <- wdpa_fetch("Liechtenstein", wait = TRUE) Error in checkError(res) : Undefined error in httr call. httr output: Failed to connect to localhost port 4567: Connection refused

And even if I try to run the next steps with a data downloaded diretcly from the website of Protected Planet, it is not works.

shp_data <- st_transform(shp, 4326) Error in UseMethod("st_transform") : no applicable method for 'st_transform' applied to an object of class "c('SpatialPolygonsDataFrame', 'SpatialPolygons', 'Spatial', 'SpatialVector')"

jeffreyhanson commented 2 years ago

Hi @karolazvdo,

Thank you very much for reaching out!

Could you please confirm if you are using the CRAN version or GitHub version of the package? Because CRAN policies forbid frequent updates, the GitHub version of the package might have some updates that fix this issue. So, if you're using the CRAN version, could you please try the GitHub version (see here for instructions)? If that that doesn't work, could you please post your session information (output from running sessionInfo()) so I can get more information on your R setup?

Ah - may I ask how you're importing the Protected Planet data after downloading it? I would suggest using the wdpar::wdpa_read() function (see here for documentation). This function will read in the .zip file downloaded from Protected Planet (as an sf object). I might have this wrong, but based on the error message shown it seems like you might have imported the shapefile data as a SpatialPolygonsDataFrame object (e.g., using the rgdal::readOGR function or raster::shapefile() function) - is that right? If so, the reason for this error is that the st_transform() function is designed to work with sf objects (which are a different way R can store shapefiles, or spatial data in general). So, if you read in the data using wdpar::wdpa_read() then st_transform should work (alternatively, you could use sf::read_sf() to read shapefile/spatial data in as an sf object).

Does that help? Please let me know if anything I've written isn't clear, or if you have any further questions?

karolazvdo commented 2 years ago

Hi Jeff, Indeed, I have imported the shapefile previously downloaded from the website, as a SpatialPolygonsDataFrame(). Therefore, I had to map my results by other means. I have found your package recently, and I really like it. But the other path to import and work with it, I do not have succeeded. I'll leave here the output from sessionInfo() as requested. I had installed the package from the GitHub version as instructed.

mlt_raw_pa_data <- wdpa_fetch("Malta", wait = TRUE,download_dir = rappdirs::user_data_dir("wdpar")) Error in checkError(res) :

  • Undefined error in httr call. httr output: Failed to connect to localhost port 14557: Connection refused sessionInfo() R version 4.1.2 (2021-11-01) Platform: x86_64-w64-mingw32/x64 (64-bit)*Running under: Windows 10 x64 (build 22000) Matrix products: default

locale: [1] LC_COLLATE=Portuguese_Brazil.1252 LC_CTYPE=Portuguese_Brazil.1252 *[3] LC_MONETARY=Portuguese_Brazil.1252 LC_NUMERIC=C *[5] LC_TIME=Portuguese_Brazil.1252

*attached base packages:*[1] stats graphics grDevices utils datasets methods base

*other attached packages:*[1] ggmap_3.0.0 ggplot2_3.3.6 dplyr_1.0.8 wdpar_1.3.2.3 sf_1.0-7

loaded via a namespace (and not attached):

  • [1] tidyselect_1.1.2 terra_1.5-21 purrr_0.3.4 lattice_0.20-45 *
  • [5] colorspace_2.0-3 vctrs_0.3.8 generics_0.1.2 yaml_2.3.5 *
  • [9] XML_3.99-0.10 utf8_1.2.2 rlang_1.0.1 e1071_1.7-11 [13] pillar_1.7.0 glue_1.6.1 withr_2.5.0 DBI_1.1.2 [17] rappdirs_0.3.3 sp_1.5-0 semver_0.2.0 jpeg_0.1-9 [21] lifecycle_1.0.1 plyr_1.8.6 stringr_1.4.0 munsell_0.5.0 [25] binman_0.1.2 gtable_0.3.0 raster_3.5-15 caTools_1.18.2 [29] RgoogleMaps_1.4.5.3 codetools_0.2-18 wdman_0.2.5 ps_1.7.0 [33] curl_4.3.2 class_7.3-19 fansi_1.0.2 Rcpp_1.0.8.3 [37] KernSmooth_2.23-20 openssl_2.0.2 scales_1.2.0 classInt_0.4-7 [41] RSelenium_1.7.7 jsonlite_1.8.0 countrycode_1.4.0 askpass_1.1 [45] rjson_0.2.21 png_0.1-7 stringi_1.7.6 processx_3.6.0 [49] grid_4.1.2 cli_3.1.1 tools_4.1.2 bitops_1.0-7 [53] magrittr_2.0.2 proxy_0.4-27 tibble_3.1.6 crayon_1.5.1 [57] tidyr_1.2.0 pkgconfig_2.0.3 ellipsis_0.3.2 assertthat_0.2.1 *[61] httr_1.4.3 R6_2.5.1 units_0.8-0 compiler_4.1.2

Em ter., 14 de jun. de 2022 às 00:02, Jeff Hanson @.***> escreveu:

Hi @karolazvdo https://github.com/karolazvdo,

Thank you very much for reaching out!

Could you please confirm if you are using the CRAN version or GitHub version of the package? Because CRAN policies forbid frequent updates, the GitHub version of the package might have some updates that fix this issue. So, if you're using the CRAN version, could you please try the GitHub version (see here for instructions https://prioritizr.github.io/wdpar)? If that that doesn't work, could you please post your session information (output from running sessionInfo()) so I can get more information on your R setup?

Ah - may I ask how you're importing the Protected Planet data after downloading it? I would suggest using the wdpar::wdpa_read() function (see here for documentation https://prioritizr.github.io/wdpar/reference/wdpa_read.html). This function will read in the .zip file downloaded from Protected Planet (as an sf object). I might have this wrong, but based on the error message shown it seems like you might have imported the shapefile data as a SpatialPolygonsDataFrame object (e.g., using the rgdal::readOGR function or raster::shapefile() function) - is that right? If so, the reason for this error is that the st_transform() function is designed to work with sf objects (which are a different way R can store shapefiles, or spatial data in general). So, if you read in the data using wdpar::wdpa_read() then st_transform should work (alternatively, you could use sf::read_sf() to read shapefile/spatial data in as an sf object).

Does that help? Please let me know if anything I've written isn't clear, or if you have any further questions?

— Reply to this email directly, view it on GitHub https://github.com/prioritizr/wdpar/issues/49#issuecomment-1154656677, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYFXEPWZL2YWFKJFTU2CZFLVO7Y47ANCNFSM5YUNKQ4A . You are receiving this because you were mentioned.Message ID: @.***>

-- Karoline Azevedo, M.Sc. Biologist Phone: +55 (82) 99905-1210 Lattes/C.V. (Pt): http://lattes.cnpq.br/5407395559226556 ORCID ID (En): https://orcid.org/0000-0002-6302-4187

jeffreyhanson commented 2 years ago

Ah ok - yeah, thanks for trying the GitHub version. I sometimes encountered this error in earlier versions of the package if I accidently closed R while it was downloading the data - and the only way to fix that was restarting the computer, so maybe you could try that? Also, did the wdpa_read() function work?

jeffreyhanson commented 2 years ago

@karolazvdo, I just wanted to follow up and ask if that solved the issue?

karolazvdo commented 2 years ago

Hi, actually, once I already had the shapefiles downloaded from the website, I used the sf package to work with them. Even trying the github version or restarting the session, the functions from the wdpar package, like wdpa_read() or wdpa_fetch() unfortunately did not work.

Thanks for the concern.

Em seg., 4 de jul. de 2022 às 17:21, Jeff Hanson @.***> escreveu:

@karolazvdo https://github.com/karolazvdo, I just wanted to follow up and ask if that solved the issue?

— Reply to this email directly, view it on GitHub https://github.com/prioritizr/wdpar/issues/49#issuecomment-1174270539, or unsubscribe https://github.com/notifications/unsubscribe-auth/AYFXEPVMRVTZ3Z7UIB2MKG3VSNBVZANCNFSM5YUNKQ4A . You are receiving this because you were mentioned.Message ID: @.***>

-- Karoline Azevedo, M.Sc. Biologist Phone: +55 (82) 99905-1210 Lattes/C.V. (Pt): http://lattes.cnpq.br/5407395559226556 ORCID ID (En): https://orcid.org/0000-0002-6302-4187

jeffreyhanson commented 2 years ago

Ah ok - sorry I'm sorry we couldn't get it working on your computer. Is there anything else I can help with? If not, I'll close this issue.