webread with json parameters

13 visualizaciones (últimos 30 días)
Filippo Natoli
Filippo Natoli el 9 de Dic. de 2020
Comentada: Filippo Natoli el 9 de Dic. de 2020
Hello,
I am trying to dowload climatic data from the ACIS Web Services (http://www.rcc-acis.org/docs_webservices.html). Specifically, I would need data for the average temperatures, at daily frequency, for each US state from 1960 until today.
My json parameter vector should be the following (e.g., for DC),
'{"state":"dc","sdate":"1960-01-01","edate":"2020-10-01","grid":"1","elems":[{"name":"avgt","interval":"dly","duration":"dly","area_reduce":"state_mean"}]}'
In Matlab I tried to use the webread function as follows
url = 'http://data.rcc-acis.org/GridData';
D1 = datetime(1999,01,01,'Format','yyyy-MM-dd');
D2 = datetime(2020,01,01,'Format','yyyy-MM-dd');
opzelem=['name','avgt','interval','dly','duration','dly','area_reduce','state_mean'];
scarico = webread(url,'state','DC','sdate',D1,'edate',D2,'grid','1','elems',opzelem);
but this returns the following error:
Error using readContentFromWebService (line 46)
The server returned the status 400 with message "Bad Request" in response to the request to URL
http://data.rcc-acis.org/GridData?state=DC&sdate=1999-01-01&edate=2020-01-01&grid=1&elems=nameavgtintervaldlydurationdlyarea_reducestate_mean.
Basically, I do not know how to include the "elems" options into webread. Using the jsondecode function to construct a struct array from the json parameter vector does not work either because webread only admits name-value pairs, not structures. Do you have any idea of how to solve it? thank you very much

Respuesta aceptada

Ive J
Ive J el 9 de Dic. de 2020
elems itself should be added as a nested struct to the input data, try this
headers = {'Content-Type' 'application/json'; 'Accept' 'application/json'};
options = weboptions('HeaderFields', headers, 'Timeout', 5000);
data = struct('state', "dc", 'sdate', "1990101", 'edate', "20200101", 'grid', "3");
data.elems = {struct('name', "maxt",'area_reduce', "state_mean")};
scarico = webwrite('http://data.rcc-acis.org/GridData', data, options);
  1 comentario
Filippo Natoli
Filippo Natoli el 9 de Dic. de 2020
Thanks Ive Ive, it works perfectly!

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by