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:

  • location
  • 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.

 

R

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[1],'&lat=',coords[2],',&attributes=BLDFIE,SLTPPT,SNDPPT,CLYPPT'), flatten = TRUE)

 

Julia

In Julia, it is possible to use the HTTP package to query the service and then the JSON package to parse the response.

using HTTP
using JSON
coords = [45.5, 37.8]
resp = HTTP.request("GET", string("https://rest.soilgrids.org/query?lon=",coords[1] ,"&lat=", coords[2], "&attributes=BLDFIE,SLTPPT,SNDPPT,CLYPPT"))
JSON.parse(String(resp.body))

 

Python

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[0]) + "&lat=" + str(coords[1]) + "&attributes=BLDFIE,SLTPPT,SNDPPT,CLYPPT") 
resp.json()

 

Contact: