How to get result in json from overpass-turbo? - openstreetmap

Is it possible to get result in JSON from http://overpass-turbo.eu/ (or directly from openstreetmap) ?
My request is:
(
way
(around:2000,55.693309807744484,21.151986122131348)
[highway~"^(primary|secondary|tertiary|residential)$"]
[name];
>;);out;

You need to add this line in front of your statement:
[out:json]; ...

This is the query: http://overpass-api.de/api/interpreter?data=[out:json]%20;%20(%20way%20(around:2000,55.693309807744484,21.151986122131348)%20[highway~%22^(primary|secondary|tertiary|residential)$%22]%20[name];%20%3E;);%20out;
Yours was missing:
[out:json]
;
<your part>
and %20 before out;

Related

is there a way to optimize this kind of query?

I'm trying to fetch results with Overpass API, while I worked hard to find the right syntax, now I figured that there was different syntax for same results. But the difference of response time is important.
For now, my best way to request what I need is this query:
(
node["natural"~"peak|saddle|bay|beach|cape|glacier|reef|cliff|dunehill|valey|volcano"];
node["place"~"suburb|village|town|city"];
node["leisure"~"nature_reserve|park|track|summer_camp|stadium|marina|horse_riding|golf_course|beach_resort"]; rel["natural"~"peak|saddle|bay|beach|cape|glacier|reef|cliff|dunehill|valey|volcano"];
rel["place"~"suburb|village|town|city"];
rel["leisure"~"nature_reserve|park|track|summer_camp|stadium|marina|horse_riding|golf_course|beach_resort"];
);
(._;>;);
out body center tags;
while this same answer with this query will take double time of response:
(
node[natural=peak];
node[natural=saddle];
node[natural=bay];
node[natural=beach];
node[natural=cape];
node[natural=glacier];
node[natural=reef];
node[natural=cliff];
node[natural=dune];
node[natural=hill];
node[natural=valley];
node[natural=volcano];
node[tourism=wilderness_hut];
node[place=suburb];
node[place=village];
node[place=town];
node[place=city];
node[leisure=nature_reserve];
node[leisure=park];
node[leisure=track];
node[leisure=summer_camp];
node[leisure=stadium];
node[leisure=marina];
node[leisure=horse_riding];
node[leisure=golf_course];
node[leisure=beach_resort];
);
(._;>;);
out body;
(
rel[natural=peak];
rel[natural=saddle];
rel[natural=bay];
rel[natural=beach];
rel[natural=cape];
rel[natural=glacier];
rel[natural=reef];
rel[natural=cliff];
rel[natural=dune];
rel[natural=hill];
rel[natural=valley];
rel[natural=volcano];
rel[tourism=wilderness_hut];
rel[place=suburb];
rel[place=village];
rel[place=town];
rel[place=city];
rel[leisure=nature_reserve];
rel[leisure=park];
rel[leisure=track];
rel[leisure=summer_camp];
rel[leisure=stadium];
rel[leisure=marina];
rel[leisure=horse_riding];
rel[leisure=golf_course];
rel[leisure=beach_resort];
);
(._;>;);
out center tags;
Is there a way to improve the first query more than I already did? Thanks

Import URL return values

I'm trying to import data from a quantum random number generator and load it into a table:
https://qrng.anu.edu.au/API/jsonI.php?length=10&type=uint8&size=1
The results, if you were to run the URL in a browser, look exactly like this:
{"type":"uint8","length":10,"data":[76,104,98,90,47,116,250,86,43,108],"success":true}
It's just a string return that I can easily parse...but all I see when searching for how to do this is XML and JSON stuff. I don't need that. I just want to execute a simple URL and parse the string return value...but it's got me stumped.
You haven't provided enough sample data to offer a complete answer but here's some sample code that will get you close:
DECLARE #string VARCHAR(8000) = 'https://qrng.anu.edu.au/API/jsonI.php?length=10&type=uint8&size=1';
SELECT NewString =
'{'+STRING_AGG(CONCAT('"',SUBSTRING(s.Item,1,idx.N-1),'":')+
ISNULL(CAST(TRY_CAST(f.S AS INT) AS VARCHAR(8000)), CONCAT('"',f.S,'"')),',')+'}'
FROM (VALUES(SUBSTRING(#string,CHARINDEX('?',#string)+1,8000))) AS ns(NewString)
CROSS APPLY dbo.DelimitedSplit8K(ns.NewString,'&') AS s
CROSS APPLY (VALUES(CHARINDEX('=',s.Item))) AS idx(N)
CROSS APPLY (VALUES(SUBSTRING(s.Item,idx.N+1,8000))) AS f(S);
Returns:
{"length":10,"type":"uint8","size":1}

Storing Json response element in a variable using Karate

Storing the following json response in a variable
[{"Resort":"SANRS","ResvNameID":14396162,"ConfirmationNo":"86749976"},
{"Resort":"SANRS","ResvNameID":13123123,"ConfirmationNo":"98932423"}]
And def allres = response
And print allres.reservations[0].ResvNameID does not print anything? What's wrong here?
Your JSON path is wrong.
Try:
* print allres[0].ResvNameID
Output:
[print] 14396162

How to pass a null value received on msg.req.query to msg.payload

I am developing an application using Dashdb on Bluemix and nodered, my PHP application uses the call to webservice to invoke the node-red, whenever my function on PHP invokes the node to insert on table and the field GEO_ID is null, the application fails, I understand the issue, it seems the third parameter was not informed, I have just tried to check the param before and passing something like NULL but it continues not working.
See the code:
msg.account_id = msg.req.query.account_id;
msg.user_id = msg.req.query.user_id;
msg.geo_id=msg.req.query.geo_id;
msg.payload = "INSERT INTO ACCOUNT_USER (ACCOUNT_ID, USER_ID, GEO_ID) VALUES (?,?,?) ";
return msg;
And on Dashdb component I have set the parameter as below:
msg.account_id,msg.user_id,msg.geo_id
The third geo_id is the issue, I have tried something like the code below:
if(msg.req.query.geo_id===null){msg.geo_id=null}
or
if(msg.req.query.geo_id===null){msg.geo_id="null"}
The error I got is the one below:
dashDB query node: Error: [IBM][CLI Driver][DB2/LINUXX8664] SQL0420N Invalid character found in a character string argument of the function "DECIMAL". SQLSTATE=22018
I really appreciate if someone could help me on it .
Thanks,
Eduardo Diogo Garcia
Is it possible that msg.req.query.geo_id is set to an empty string?
In that case neither if statement above would get executed, and you would be trying to insert an empty string into a DECIMAL column. Maybe try something like this:
if (! msg.req.query.geo_id || msg.req.query.geo_id == '') {
msg.geo_id = null;
}

appending static variable within sql query

I am trying to use the late static binding concept during insertion but I am getting a syntax error when I am writing this statement:
I am using php version 5.3.8
$resultArray = $this->connection->query("insert into " static::$table "(title,link) values('hi','hello')");
Looks like you forgot some dots to concatenate static::$table with the rest of the query string. Try this:
$resultArray = $this->connection->query("insert into " . static::$table . "(title,link) values('hi','hello')");