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

조회 수: 2 (최근 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