Hello all,
I am having a most pesky issue as of recently - I am harvesting images off Mapillary (via RStudio 1.1.442) based on selection criteria. My curl request basically looks like this:
for (i in 1:nrow(spdf@data)){ #start loop to go through the rows in my dataset, which represent the plots, over which I am basing the search criteria
# get the lon and lat of centroid
lon<-spdf@data$centroidLon[i]
lat<-spdf@data$centroidLat[i]
#specify the growing season
start_season<-"2017-03-01"
end_season<-"2017-10-01"
# do the harvest through the mapillary api
res <-GET(paste0( "https://a.mapillary.com/v3/images/?",
"closeto=",lon,",",lat,
"&radius=",500,
"&start_time=",start_season,
"&end_time=",end_season,
"&per_page=",1,
"&client_id=",clientID))
# read the results as text
json <- content(res, as="text")
# read the result as JSON and store the results in the m_parse variable
m_parse<-fromJSON(json, simplifyVector=TRUE)
if (!is.null(m_parse$features$properties$key)){
# store the useful information from the m_parse variable into the spdf data frame
spdf@data$key[i]<-m_parse$features$properties$key
spdf@data$ca[i]<-m_parse$features$properties$ca
spdf@data$captured_at[i]<-m_parse$features$properties$captured_at
spdf@data$lon[i]<-m_parse$features$geometry$coordinates[[1]][1]
spdf@data$lat[i]<-m_parse$features$geometry$coordinates[[1]][2]
All is good, but every now and again I get the error:
No encoding supplied: defaulting to UTF-8.
Show Traceback
Rerun with Debug
Error: lexical error: invalid char in json text.
<html> <head><title>502 Bad Ga
(right here) ------^
This is problematic as the script is quite lengthy and is put into a function that runs it many times. So when it crashes somewhere in the middle due to this error, I have to run it all from the beginning.
I get what the error is telling me, but no matter which rjson
library I use, it still rears its ugly head (I usually use jsonlite
). This leads me to the conclusion that it might be an issue of deep nesting or some wrappers put around the data by the service providers.
Can anyone comment on this issue and how to work around it?
M