How to format wkt (well known text string) as a normal string to build a webread input?
3 views (last 30 days)
Show older comments
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);
0 Comments
Answers (1)
Rik
on 14 Sep 2022
I suspect you need to apply percent encoding, as URLs are not allowed to contain spaces.
2 Comments
Rik
on 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.
See Also
Categories
Find more on Data Import and Analysis in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!