diff options
author | slomo <steve.harrison@gmx.net> | 2011-01-12 22:58:31 +0100 |
---|---|---|
committer | slomo <steve.harrison@gmx.net> | 2011-01-12 22:58:31 +0100 |
commit | 2d370398fe8b2329736d839504999186a1aee0aa (patch) | |
tree | 20a11acb9583a7e2846208aa5115eef3b873091c /src/nodejs/start.js | |
parent | 280179806ad4426480032769f5296d3875044530 (diff) | |
download | osm-xapi-2d370398fe8b2329736d839504999186a1aee0aa.tar.gz osm-xapi-2d370398fe8b2329736d839504999186a1aee0aa.tar.xz osm-xapi-2d370398fe8b2329736d839504999186a1aee0aa.zip |
some new tries
Diffstat (limited to 'src/nodejs/start.js')
-rw-r--r-- | src/nodejs/start.js | 79 |
1 files changed, 36 insertions, 43 deletions
diff --git a/src/nodejs/start.js b/src/nodejs/start.js index c664cfe..b92c757 100644 --- a/src/nodejs/start.js +++ b/src/nodejs/start.js @@ -6,52 +6,45 @@ var http = require('http'), querystring = require('querystring'); // config -var connectionString = "pg://user:pass@localhost/xapi" - - -function getDataBaseResult(tag,bbox,res) { - pg.connect(connectionString,function(err,client) { - var the_result; - - if (err) { - console.log(err); - } - else { - client.query(createQuery(tag,bbox),function(err,result) { - if (err) { - console.log(err); - } - else { - console.log(result); - res.write(result.rows); - res.end("\n"); - } - }); - } - }); +var connectionString = "pg://yves:test@localhost/xapi" + + +function getDataBaseResult(tag,bbox,res){ +pg.connect(connectionString,function(err,client){ + var the_result; + if(err){ + console.log(err); + } else { + client.query(createQuery(tag,bbox),function(err,result){ + if (err) { + console.log(err); + } else { + console.log(result); + res.write(result.rows); + res.end("/n"); + } + + }); + } +}); } function createQuery(tag,bbox){ // FIXME: validate - // var table = tag[0] + "#" + tag[1]; - // var filter = ""; - - // // input validation - // for(i=0;i<bbox.length;i++){ - // bbox[i] = parseFloat(bbox[i]); - // } - - // if(bbox){ - // filter = "WHERE longitude > " + bbox[0] + " AND longitude < " + bbox[1] + - // " AND latitude > " + bbox[2] + " AND latitude < " + bbox[3]; - // } + var table = tag[0] + "#" + tag[1]; + var filter = ""; + // input validation + for(i=0;i<bbox.length;i++){ + bbox[i] = parseFloat(bbox[i]); + } - return "SELECT id, tags, linestring \ - FROM ways \ - WHERE (tags @> '\"amenity\"=>\"pub\"' AND \ - lseg(linestring) @ box('(13.0882097323,52.3418234221)'::point,'(13.7606105539,52.6697240587)'::point));" + if(bbox){ + filter = "WHERE longitude > " + bbox[0] + " AND longitude < " + bbox[1] + + " AND latitude > " + bbox[2] + " AND latitude < " + bbox[3]; + } + return "SELECT * FROM \"" + table + "\" " + filter + ";"; } @@ -74,13 +67,13 @@ http.createServer(function (req, res) { } base_url_re.exec(req.url); var type = RegExp.$1, url_rest = querystring.unescape(RegExp.$2); - + var filters = []; while (v = filter_re.exec(url_rest)) { filters.push(v[1]); } console.log(filters); - + var tag; var bbox; @@ -97,10 +90,10 @@ http.createServer(function (req, res) { console.log(tag); console.log(bbox); - getDataBaseResult(tag,bbox,res); + getDataBaseResult(tag,bbox,res); res.writeHead(200, {'Content-Type': 'text/plain; charset=utf8', }); - + res.write('URL was: ' + req.url + '\n'); res.write('type: ' + type + '\n'); res.write('filters:\n'); |