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

3 次查看(过去 30 天)
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);

回答(1 个)

Rik
Rik 2022-9-14
I suspect you need to apply percent encoding, as URLs are not allowed to contain spaces.
  2 个评论
Craig Atkinson
Craig Atkinson 2022-10-31
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 2022-10-31
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.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

产品


版本

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by