Using the SoilGrids ReST interface
All the maps produced in SoilGrids are accessible through a ReST service, reachable at http://rest.soilgrids.org. The service accepts queries using the following parameters:
- variable (soil property, class, etc)
- standard depth level
Only the location is mandatory, with the other parameters used to narrow down the query. Passing only the location as parameter will obtain the complete information available for all variables. Please visit the service page for more details.
The ReST service is presently the most convenient way of accessing SoilGrids from a computer programme or a script. Below are some examples in various programming languages popular among Earth scientists.
For R there is the
jsonlite package, that automatically parses the JSON response returned by the service. It can be used like this:
require(jsonlite) coords <- c(45.5, 37.8) fromJSON(paste0('https://rest.soilgrids.org/query?lon=',coords,'&lat=',coords,',&attributes=BLDFIE,SLTPPT,SNDPPT,CLYPPT'), flatten = TRUE)
using HTTP using JSON coords = [45.5, 37.8] resp = HTTP.request("GET", string("https://rest.soilgrids.org/query?lon=",coords ,"&lat=", coords, "&attributes=BLDFIE,SLTPPT,SNDPPT,CLYPPT")) JSON.parse(String(resp.body))
In Python a request to the service can be made with the
requests package, which automatically parses the JSON response into a dictionary.
import requests coords = [45.5, 37.8] resp = requests.get("https://rest.soilgrids.org/query?lon=" + str(coords) + "&lat=" + str(coords) + "&attributes=BLDFIE,SLTPPT,SNDPPT,CLYPPT") resp.json()