aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Sulfrian <alexander@sulfrian.net>2011-01-12 16:44:31 +0100
committerAlexander Sulfrian <alexander@sulfrian.net>2011-01-12 16:44:31 +0100
commit280179806ad4426480032769f5296d3875044530 (patch)
treee78cc662ce1126d724d1042fbd2f6906303bf401
parenta1c5e0674a2431e8fef080ed0eea7e5eb8e0feab (diff)
downloadosm-xapi-280179806ad4426480032769f5296d3875044530.tar.gz
osm-xapi-280179806ad4426480032769f5296d3875044530.tar.xz
osm-xapi-280179806ad4426480032769f5296d3875044530.zip
some cleanup, tests with bo
-rw-r--r--src/nodejs/start.js73
1 files changed, 40 insertions, 33 deletions
diff --git a/src/nodejs/start.js b/src/nodejs/start.js
index 2cf923e..c664cfe 100644
--- a/src/nodejs/start.js
+++ b/src/nodejs/start.js
@@ -9,42 +9,49 @@ var http = require('http'),
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");
- }
-
- });
- }
-});
+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 = "";
+ // 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];
+ // }
- // 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];
- }
- return "SELECT * FROM \"" + table + "\" " + filter + ";";
+ 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));"
}
@@ -67,13 +74,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;
@@ -90,10 +97,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');