aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/nodejs/main.js174
1 files changed, 79 insertions, 95 deletions
diff --git a/src/nodejs/main.js b/src/nodejs/main.js
index ce4518d..2656f3d 100644
--- a/src/nodejs/main.js
+++ b/src/nodejs/main.js
@@ -80,119 +80,103 @@ function rowToWay(row){
// #################### MAY be put to different module later
+var options = [
+ { short : 'c',
+ long : 'config',
+ description : 'Select configuration file',
+ value : true
+ }
+];
-// #################### my little clutch replacments
-
-
-var urlToXpathObj = function urlToXpathObj(url){
-
- // FIXME: more validaiton
- // filter stars in keys
- // filter no enough arguments
+//
+// {
+// object = node/way/relation/* ,
+// bbox = { left : 1.0 , right : 1.0 , top : 1.0, bottom : 1.0 }
+// tag = { key : [ ], value [ ] }
+// }
+
+
+function buildMainQuery(reqJso){
+
+ var id = 0;
+ var replacements = Array();
+
+ var selectMap = {
+ 'node' : 'id,user_id,tstamp,version,changeset_id,hstore_to_array(tags) as tags, ' +
+ 'X(geom) as lat, Y(geom) as lon',
+ 'way' : 'id,tstamp,version,changeset_id,nodes,user_id,hstore_to_array(tags) as tags ',
+ 'relation' : '' //FIXME: plz
+ }
+
+ // FIXME: help me i am not side effect free
+ function buildTagsQuery(map){
+
+ tagQueries = new Array();
+
+ for(tagkey in map){
+ tagQueries.push("tags @> hastore($" + id++ + ",$" + id++ + ")");
+ replacements.push(tagkey);
+ replacements.push(map[tagkey]);
+ }
- var parseKeyList = function(string){
- result = /(.+)(:?\|(.+))/.exec(string);
- result.shift();
- return result;
+ return tagQueries.join(" OR \n");
}
- var parseBboxList = function(string){
-
- result = /(.+)(:?,(.+)){3}/.exec(string):
-
- if(result.length != 4){
- throw "error";
+ // FIXME: help me i am not side effect free
+ function buildBbox(object,bbox){
+
+ var colName = {
+ node : 'geom',
+ way : 'linestring',
+ relation : '' // FIXME: whats my name
}
- result.shift();
+ bboxQueryStr = colName[object] + ' && st_setsrid(st_makebox2d( ' +
+ ' st_setsrid(st_makepoint($' + id++ + ', $' + id++ + '), 4326), ' +
+ ' st_setsrid(st_makepoint($' + id++ + ', $' + id++ + '), 4326) ' +
+ ' ), 4326) ';
+
+ for( direction in bbox ) {
+ replacments.push(bbox[direction]);
+ }
- return {
- 'left' : result[0];
- 'bottom' : result[1];
- 'right' : result[2];
- 'top' : result[3];
+ return bboxQueryStr;
}
- var xp = {};
-
- result = /\/(*|node|way|relation)(:?\[(.*)=(.*)\])*/.exec(url);
-
- xp.object=result[1];
-
- for(i=2;i<=result.length();i++){
- if(result[i]==="bbox"){
- xp.bbox = parseBboxValues(result[i+1]);
- } else {
- xp.tag ={};
- xp.tag.keys = parseKeyList(result[i]);
- xp.tag.values = parseKeyList(result[i+1]);
+ function explodeTags(keys,values){
+ var map = {};
+ for(key in keys) {
+ for(value in values) {
+ map[key]=value;
+ }
}
- i++;
+ return map;
}
-}
-
-
-
-
-
-
-
-// ################## end my little clutch replacments
-
-
-
+
+ query = "SELECT " + selectMap[object] + " FROM " + object + "s";
+
+ whereClauses = Array();
+ if(reqJson.bbox != undefined){
+ whereClauses.push(buildBbox(reqJson.bbox));
+ }
+
+ if(reqJson.tags != undefined){
+ tags = explodeTags(tags.keys,tags.values);
+ whereClauses.push(buildTagsQuery(tags));
+ }
+ if(whereClauses.length > 0) {
+ whereClauses.join(' AND ');
+ query += ' WHERE (' + whereClauses + ')';
+ }
-var options = [
- { short : 'c',
- long : 'config',
- description : 'Select configuration file',
- value : true
- }
-];
+ query += ';'
-function createWayBboxQuery(key, value, left, bottom, right, top) {
- return {
- text: 'SELECT id,tstamp,version,changeset_id,nodes,user_id,hstore_to_array(tags) as tags ' +
- 'FROM ways ' +
- 'WHERE ( ' +
- ' tags @> hstore($1, $2) AND ' +
- ' linestring && st_setsrid(st_makebox2d( ' +
- ' st_setsrid(st_makepoint($3, $4), 4326), ' +
- ' st_setsrid(st_makepoint($5, $6), 4326) ' +
- ' ), 4326) ' +
- ')',
- values: [key, value, left, bottom, right, top],
- name: 'way bbox query'
- };
+ return query;
}
-function createNodeBboxQuery(key, value, left, bottom, right, top) {
- return {
- text: 'SELECT id,user_id,tstamp,version,changeset_id,hstore_to_array(tags) as tags, X(geom) as lat, Y(geom) as lon ' +
- 'FROM nodes ' +
- 'WHERE ( ' +
- ' tags @> hstore($1, $2) AND ' +
- ' geom && st_setsrid(st_makebox2d( ' +
- ' st_setsrid(st_makepoint($3, $4), 4326), ' +
- ' st_setsrid(st_makepoint($5, $6), 4326) ' +
- ' ), 4326) ' +
- ')',
- values: [key, value, left, bottom, right, top],
- name: 'node bbox query'
- };
-}
-function createNodesForWayQuery(nodes) {
- return {
- text: 'SELECT id,tstamp,version,changeset_id,hstore_to_array(tags) as tags, X(geom) as lat, Y(geom) as lon ' +
- 'FROM nodes ' +
- 'WHERE (id = ANY($1))',
- values: [nodes],
- name: 'nodes for way'
- };
-}
function dbConnect(res, callback) {
pg.connect(config.connectionString, function(err, client) {