Comments (5)
Hey, I'm sorry I don't know of any immediate fixes off the top of my head. The code for downloading the data uses a virtual web browser to download the code and sometimes it can fail to correctly shut down the web browser when it finishes, which causes problems when you try and download more data. Could you please try restarting your computer and trying the code again (this will terminate the virtual web browser if it's still running)? Also, could you please type in traceback()
after running the code and copy in the output messages here so I can exactly exactly where it's going wrong?
from wdpar.
Thanks for the reply. I tried the first option of restarting my computer but it didn't work. The traceback() result:
15: stop(err)
14: checkError(res)
13: queryRD(qpath, "POST", qdata = serverOpts)
12: rd$open(silent = TRUE)
11: tryCatchList(expr, classes, parentenv, handlers)
10: tryCatch({
url <- character(0)
pjs <- wdman::phantomjs(verbose = FALSE)
rd <- RSelenium::remoteDriver(port = 4567L, browserName = "phantomjs")
rd$open(silent = TRUE)
rd$maxWindowSize()
rd$navigate(paste0("https://protectedplanet.net/country/",
x))
Sys.sleep(2)
elem <- rd$findElement(using = "css", ".link-with-icon--bold")
elem$clickElement()
Sys.sleep(2)
elem <- rd$findElement(using = "css", ".link-with-icon+ .link-with-icon")
elem$clickElement()
Sys.sleep(2)
src <- xml2::read_html(rd$getPageSource()[[1]][[1]], encoding = "UTF-8")
divs <- xml2::xml_find_all(src, ".//div")
divs <- divs[which(xml2::xml_attr(divs, "id") == "download-modal")]
attrs <- xml2::xml_attr(xml2::xml_find_all(divs, ".//a"),
"href")
url <- grep("shapefile", attrs, fixed = TRUE, value = TRUE)
}, finally = {
try(rd$close(), silent = TRUE)
try(rd$close(), silent = TRUE)
try(pjs$stop(), silent = TRUE)
try(pjs$stop(), silent = TRUE)
})
9: withCallingHandlers(expr, message = function(c) invokeRestart("muffleMessage"))
8: suppressMessages(tryCatch({
url <- character(0)
pjs <- wdman::phantomjs(verbose = FALSE)
rd <- RSelenium::remoteDriver(port = 4567L, browserName = "phantomjs")
rd$open(silent = TRUE)
rd$maxWindowSize()
rd$navigate(paste0("https://protectedplanet.net/country/",
x))
Sys.sleep(2)
elem <- rd$findElement(using = "css", ".link-with-icon--bold")
elem$clickElement()
Sys.sleep(2)
elem <- rd$findElement(using = "css", ".link-with-icon+ .link-with-icon")
elem$clickElement()
Sys.sleep(2)
src <- xml2::read_html(rd$getPageSource()[[1]][[1]], encoding = "UTF-8")
divs <- xml2::xml_find_all(src, ".//div")
divs <- divs[which(xml2::xml_attr(divs, "id") == "download-modal")]
attrs <- xml2::xml_attr(xml2::xml_find_all(divs, ".//a"),
"href")
url <- grep("shapefile", attrs, fixed = TRUE, value = TRUE)
}, finally = {
try(rd$close(), silent = TRUE)
try(rd$close(), silent = TRUE)
try(pjs$stop(), silent = TRUE)
try(pjs$stop(), silent = TRUE)
}))
7: try_and_find_url(x)
6: wdpa_url(x, wait = wait)
5: wdpa_fetch("France")
4: as_Spatial(wdpa_fetch("France"))
3: eval(lhs, parent, parent)
2: eval(lhs, parent, parent)
1: as_Spatial(wdpa_fetch("France")) %>% filter(WDPAID == wdpaid)
Hope this will help with the bug.
from wdpar.
Thanks! Yeah, it looks like something strange is happening with the virtual web browser (Phantom JS). This could be due firewall stuff - I don't know sorry. In terms of getting a working solution on your system, you could try something like the code below where we hard-code the download URL:
# load pacakges
library(sf)
library(wdpar)
# set parameters
wdpaid <- "555526224"
download_url <- "https://www.protectedplanet.net/downloads/WDPA_Aug2019_FRA?type=shapefile"
download_dir <- rappdirs::user_data_dir("wdpar")
# download the file
file_name <- basename(httr::HEAD(download_url)$url)
file_path <- file.path(download_dir, file_name)
curl::curl_download(download_url, file_path, quiet = FALSE)
# read the data
france_pa <- wdpa_read(file_path)
# subset the data
mpa <- france_pa %>% filter(WDPAID == wdpaid)
Please let me know if you have any problems with that. I'm working on a mobile phone hotspot connection at the moment so I can't test it myself.
from wdpar.
Cool. It works fine. Thanks for the help. Hopefully you get to fit the virtual browser issue and wdpa_fetch() pipeline as I imagine with such way means less code.
Thanks once again. Hopefully, one day I will understand all these stuff well enough to solve some of them.
from wdpar.
No worries - glad I could help.
from wdpar.
Related Issues (20)
- Feature Request: Add functionality to keep UNESCO sites and not yet implemented areas HOT 15
- HTTP error 404 in "global" query with wdpa_fetch HOT 3
- Fails to download country-level data HOT 2
- Fails package checks under noSuggests config
- Poor internet connection breaks wdpa_fetch HOT 9
- Port error HOT 10
- It takes forever to eraseoverlap for global dataset. HOT 22
- wdpa_fetch HOT 6
- I used the newest version of wdpar, still have this "side location conflict" HOT 7
- The package not run for previous download data, and do not start a new download data HOT 6
- GEOS version sensitivity HOT 7
- upcoming sf breaks wdpar HOT 6
- JOSS Review: Improve documentation on geo-processing steps and its effects on the original geometries HOT 12
- JOSS Review: Improve Statement of need / description of use-cases HOT 16
- JOSS Review - Add links to references cited in README HOT 3
- JOSS Review warning about out of date local data HOT 6
- JOSS Review: Add small POC about Performance claims HOT 7
- JOSS Review: Add statement about state of the field HOT 4
- wdpa_fetch() no longer works HOT 4
- Dissolve all MPAs in each country HOT 10
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wdpar.