Hello,
I have a question about interfacing with the Atlas of Living Australia
website: http://biocache.ala.org.au/#tab_simpleSearch
The following code works and I am able to download species observations.
The problem I am having is that I would like additional fields of data. If
I manually download records for a species from ALA then you can choose to
download all records (detailed). I cannot figure out how to automate this.
I specifically need the field “Locality”. If done correctly this
information would be present in the rawResponse data that is returned from
ALA.
Any help with this problem would be greatly appreciated.
Thanks,
Daisy
species<-"Vinca minor"
nRecords=FALSE
library(RCurl)
library(rjson)
sp <- strsplit(as.character(species)," ")[[1]]
h <- basicHeaderGatherer()
BaseALA_Data_URL <- "biocache.ala.org.au"
Referer <- ""
DataStr <-
paste0("/ws/webportal/occurrences?q=",sp[1],"+",sp[2])
message("Querying number of records...")
rawResponse <- getURL(paste0(BaseALA_Data_URL,DataStr), headerfunction
h$update)
ResponseCode <- as.integer(h$value()["status"])
if(ResponseCode == 200) {
jsres <- fromJSON(rawResponse)
} else {
message("No proper response.")
return(invisible())
}
nrecords <- jsres$totalRecords
if(nRecords)return(nrecords)
message("Downloading ", nrecords, " records.")
# Download all
DataStr <- paste0(DataStr, "&pageSize=", nrecords)
rawResponse <- getURL(paste0(BaseALA_Data_URL,DataStr), headerfunction
h$update)
if(ResponseCode == 200) {
jsres <- fromJSON(rawResponse)
} else {
message("No proper response.")
return(invisible())
}
totalRecords <- jsres$totalRecords
res <- lapply(jsres$occurrences,
function(x)c(nameSci=x$raw_scientificName,
latitude=x$decimalLatitude,
longitude=x$decimalLongitude))
res <- as.data.frame(do.call(rbind, res))
res$longitude <- as.numeric(as.character(res$longitude))
res$latitude <- as.numeric(as.character(res$latitude))
[[alternative HTML version deleted]]