Filter löschen
Filter löschen

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

3 Ansichten (letzte 30 Tage)
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);

Antworten (1)

Rik
Rik am 14 Sep. 2022
I suspect you need to apply percent encoding, as URLs are not allowed to contain spaces.
  2 Kommentare
Craig Atkinson
Craig Atkinson am 31 Okt. 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 am 31 Okt. 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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Simulink finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by