Closed ntaxus closed 5 years ago
Thank you very much for reporting this. I'll take a look at this when I can and get back to you as soon as possible.
Thanks Jeffrey! Hope you can check it out soon. Best, N
Thanks again, I've just pushed a new version to GitHub (version 0.0.1.2) which should fix the bug. When I run the following code, the points appear in the cleaned data as buffered polygons:
# load packages
library(wdpar) # version 0.0.1.2
library(ggmap)
library(gridExtra)
# download and clean data
bol_raw_pa_data <- wdpa_fetch("Bolivia")
bol_pa_data <- wdpa_clean(bol_raw_pa_data)
# I changed the crs for plotting purpose only
bol_pa_data<-st_transform(bol_pa_data, "+proj=longlat +datum=WGS84 +no_defs")
# download map background
bg <- get_stamenmap(unname(st_bbox(bol_pa_data)), zoom = 4,
maptype = "watercolor", force = TRUE)
# make plot for raw data
rawplot <-
ggmap(bg) +
geom_sf(data = bol_raw_pa_data, fill = "#31A35480", inherit.aes = FALSE) +
theme(axis.title = element_blank()) +
ggtitle("RawData")+
geom_sf(data = bol_raw_pa_data[bol_raw_pa_data$WDPAID=="98183",],
fill = "black", inherit.aes = FALSE)
# make plot for cleaned data
cleanplot <-
ggmap(bg) +
geom_sf(data = bol_pa_data, fill = "#31A35480", inherit.aes = FALSE) +
theme(axis.title = element_blank()) +
ggtitle("CleanData")
# render plots
grid.arrange(rawplot, cleanplot, ncol = 2)
I think I've addressed the bug, so I've closed this issue. But if you're still experiencing this problems with the new version, please re-open it.
Thanks for your reply! Unfortunately, I have to say that I am still getting the same results (I used the code you posted here). Maybe I need to upload some package? Below the session info.
Also, I would like you to notice that there are some polygons missing after the cleaning process. In the example I posted above I shaded a polygon (WDPAID= 98183, name="Madidi") which is a National Park (not a UNESCO Biosphere Reserve) that should remain after the clean process, but it doesn't.
I am working with the Latin American countries and I found the same kind of problem with other countries as well. Thanks for your help! N
This is my session info:
R version 3.4.4 (2018-03-15) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.1 LTS
Matrix products: default BLAS: /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.7.1 LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.7.1
locale:
[1] LC_CTYPE=es_AR.UTF-8 LC_NUMERIC=C LC_TIME=es_AR.UTF-8 LC_COLLATE=es_AR.UTF-8 LC_MONETARY=es_AR.UTF-8
[6] LC_MESSAGES=es_AR.UTF-8 LC_PAPER=es_AR.UTF-8 LC_NAME=C LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=es_AR.UTF-8 LC_IDENTIFICATION=C
attached base packages: [1] stats graphics grDevices utils datasets methods base
other attached packages: [1] raster_2.8-4 sp_1.3-1 gridExtra_2.3 ggmap_2.6.2 ggplot2_3.1.0 usethis_1.4.0 devtools_2.0.1 wdpar_0.0.1.2 sf_0.7-2
loaded via a namespace (and not attached):
[1] httr_1.4.0 pkgload_1.0.2 maps_3.3.0 jsonlite_1.6 binman_0.1.1 assertthat_0.2.0 askpass_1.1 wdman_0.2.4
[9] countrycode_1.1.0 RSelenium_1.7.5 yaml_2.2.0 remotes_2.0.2 progress_1.2.0 sessioninfo_1.1.1 pillar_1.3.1 backports_1.1.3
[17] lattice_0.20-35 glue_1.3.0 digest_0.6.18 colorspace_1.4-0 plyr_1.8.4 XML_3.98-1.16 pkgconfig_2.0.2 purrr_0.2.5
[25] scales_1.0.0 processx_3.2.1 jpeg_0.1-8 tibble_2.0.1 openssl_1.2.1 withr_2.1.2 lazyeval_0.2.1 cli_1.0.1
[33] proto_1.0.0 magrittr_1.5 crayon_1.3.4 memoise_1.1.0 ps_1.3.0 fansi_0.4.0 fs_1.2.6 xml2_1.2.0
[41] lwgeom_0.1-5 class_7.3-14 pkgbuild_1.0.2 tools_3.4.4 prettyunits_1.0.2 hms_0.4.2 geosphere_1.5-7 RgoogleMaps_1.4.3
[49] stringr_1.3.1 munsell_0.5.0 bindrcpp_0.2.2 pingr_1.1.2 callr_3.1.1 compiler_3.4.4 e1071_1.7-0.1 caTools_1.17.1.1
[57] rlang_0.3.1 classInt_0.3-1 units_0.6-2 grid_3.4.4 rstudioapi_0.9.0 rjson_0.2.20 rappdirs_0.3.1 bitops_1.0-6
[65] codetools_0.2-15 gtable_0.2.0 DBI_1.0.0 curl_3.3 reshape2_1.4.3 R6_2.3.0 dplyr_0.7.8 utf8_1.1.4
[73] bindr_0.1.1 rprojroot_1.3-2 subprocess_0.8.3 semver_0.2.0 desc_1.2.0 stringi_1.2.4 Rcpp_1.0.0 mapproj_1.2.6
[81] png_0.1-7 tidyselect_0.2.5
Ok that's not right. Could you please upload an Rdata file containing the output so I can compare it with what I'm getting? For instance, by running saveRDS("bol_pa_data", "bol_pa.rds", compress = "xz")
and attaching the bol_pa_data.rds
file to a new post?
Sure! Find attached the raw and the clean data. I put them into a zip file since I wasn't allowed to upload xz files here. Is that OK? Thanks!
Yeah that's great - thank you!
Sorry there was a typo in the code I told you to use to save the data, and so the zip file doesn't contain the spatial data. Could you please export the output with saveRDS(bol_pa_data, "bol_pa.rds", compress = "xz")
and upload the file to GitHub? Sorry about this.
Also when I try running the code on my computer, Madidi national park remains in the cleaned data set.
# load packages
library(wdpar)
# download data
bol_raw_pa_data <- wdpa_fetch("Bolivia")
# verify raw data has Madidi
print(sum(bol_raw_pa_data$WDPAID == 98183) == 1)
#> TRUE
# clean data
bol_pa_data <- wdpa_clean(bol_raw_pa_data)
# verify cleaned data has Madidi
print(sum(bol_pa_data$WDPAID == 98183) == 1)
#> TRUE
I see that you're using R 3.4.4 - could you please try upgrading to R 3.5.2? I don't know why that would cause any problems, but if we can reduce the number of differences between our computing environments that will help me track down the problem.
Ok - the problem with Madidi National park is that it has two polygons in the raw data, and one of those polygons (the bigger one) is getting omitted in the cleaning process.
I've tracked down the problem with Madidi National park - I'll try and push a patch for it later today.
Ok, can you please try running the code below with the new version on GitHub (0.0.1.3)? Hopefully, htis fixes the problem with Madidi National park.
# load packages
library(wdpar) # version 0.0.1.3
library(ggmap)
library(Rmisc)
library(ggplot2)
# download and clean data
bol_raw_pa_data <- wdpa_fetch("Bolivia")
bol_pa_data <- wdpa_clean(bol_raw_pa_data)
# I changed the crs for plotting purpose only
bol_pa_data<-st_transform(bol_pa_data, "+proj=longlat +datum=WGS84 +no_defs")
# download map background
bg <- get_stamenmap(unname(st_bbox(bol_pa_data)), zoom = 4,
maptype = "watercolor", force = TRUE)
# make plot for raw data
rawplot <-
ggmap(bg) +
geom_sf(data = bol_raw_pa_data, fill = "#31A35480", inherit.aes = FALSE) +
theme(axis.title = element_blank()) +
ggtitle("RawData")+
geom_sf(data = bol_raw_pa_data[bol_raw_pa_data$WDPAID=="98183",],
fill = "black", inherit.aes = FALSE)
# make plot for cleaned data
cleanplot <-
ggmap(bg) +
geom_sf(data = bol_pa_data, fill = "#31A35480", inherit.aes = FALSE) +
theme(axis.title = element_blank()) +
ggtitle("CleanData")
# make plot
multiplot(rawplot, cleanplot, cols = 2)
Hi Jeffrey, I've checked out the outputs for several countries and everything seems to be OK. I'll let you know if I find any other mistake. Thanks! N
Brilliant - thank you so much for raising this issue and helping me fix it. I'll close this issue now, but please do open another issue (or reopen this one if you notice the same problem again) if you find anymore problems.
Also, I'll submit the updated version to CRAN on Feb 11th (CRAN prefers monthly updates), so this fix gets into the official version asap.
Excellent! :)
Hi there and congrats on this new tool! Checking out the data resulting from applying wdpa_clean function, I find that the areas represented as points in the WDPA data base are not being converted into polygons. The example you provide in the vignette works fine, but when I try with other countries it seems to be not working. Here a picture of the protected areas in Bolivia before and after applying the wdpa_clean function. PAs represented as points are in black. I also found that some of the polygon in the raw data are missing after the clean process (see the example shaded in the picture).
Any clue of what could be happening? Thanks! Nico
My code: bol_raw_pa_data <- wdpa_fetch("Bolivia") bol_pa_data <- wdpa_clean(bol_raw_pa_data) bol_pa_data<-st_transform(bol_pa_data,"+proj=longlat +datum=WGS84 +no_defs") #I changed the crs for plotting purpose only bg <- get_stamenmap(unname(st_bbox(bol_pa_data)), zoom = 4, maptype = "watercolor", force = TRUE)
rawplot<-ggmap(bg) + geom_sf(data = bol_raw_pa_data, fill = "#31A35480", inherit.aes = FALSE) + theme(axis.title = element_blank())+ ggtitle("RawData")+ geom_sf(data = bol_raw_pa_data[bol_raw_pa_data$WDPAID=="98183",], fill = "black", inherit.aes = FALSE)
cleanplot<-ggmap(bg) + geom_sf(data = bol_pa_data, fill = "#31A35480", inherit.aes = FALSE) + theme(axis.title = element_blank())+ ggtitle("CleanData")
multiplot(rawplot, cleanplot,cols = 2)