Effacer les filtres
Effacer les filtres

How to format wkt (well known text string) as a normal string to build a webread input?

3 vues (au cours des 30 derniers jours)
Craig Atkinson
Craig Atkinson le 13 Sep 2022
Commenté : Rik le 31 Oct 2022
I am using an API to download some weather data, and I can get webread to work when I copy the example GET request, but I can't seem to figure out how to format the wkt portion of the request on my own.
For example, if I build the string like this, I will get a bad request error. If I copy the built string and replace the portion regarding wkt, then the code will run flawlessly. The equal sign is omitted, and the parenthesis are interpreted as some character value
% what wkt is supposed to look like in the string: &wkt=POINT(10+-50)
% what my wkt looks like in the string: &wktPOINT%2810+-50%29
api_key = 'EXAMPLE_KEY';
wkt = 'POINT(10 -50)'; % <-- this is the issue
attributes = ['dni','dni','ghi'];
names = '2017';
utc = 'false';
leap_day = 'false';
interval = '30';
full_name = 'Example Name';
email = 'example_email@gmail.com';
affiliation = 'Example Institution';
reason = 'Test';
mailing_list = 'false';
api_base = 'https://developer.nrel.gov/api/nsrdb/v2/solar/psm3-download.json?';
data_out_struct = webread(...
[ api_base '&api_key' api_key '&full_name' full_name '&email' email...
'&affiliation' affiliation '&reason' reason '&mailing_list' mailing_list...
'&wkt' wkt '&names' names '&attributes' attributes '&leap_day' leap_day...
'&utc' utc '&interval' interval]...
);
filename = 'Test_Downoad'
url = data_out_struct.outputs.downloadUrl;
websave(filename,url);

Réponses (1)

Rik
Rik le 14 Sep 2022
I suspect you need to apply percent encoding, as URLs are not allowed to contain spaces.
  2 commentaires
Craig Atkinson
Craig Atkinson le 31 Oct 2022
I've tried to accept this answer several times yet the page errors out. Not sure why that is, but you did initally solve my problem
Rik
Rik le 31 Oct 2022
That is odd. When something errors on this site, I generally retry a few hours later.
If it keeps erroring out, feel free to flag this thread so site admins can take a look.
Anyway, glad to be of help.

Connectez-vous pour commenter.

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Produits


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by