From 8b44fe1d3a298ee0772b08e41eb1ffca7288e4bb Mon Sep 17 00:00:00 2001 From: slomo Date: Sat, 8 Jan 2011 17:35:14 +0100 Subject: initial c0mmunist --- README | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 README diff --git a/README b/README new file mode 100644 index 0000000..e69de29 -- cgit v1.2.3 From 4212cdd8d414512ed8169163dd22a7c18767e117 Mon Sep 17 00:00:00 2001 From: slomo Date: Sat, 8 Jan 2011 21:10:42 +0100 Subject: first toughts --- README | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/README b/README index e69de29..8d10021 100644 --- a/README +++ b/README @@ -0,0 +1,59 @@ +=============== +osm@spline Xapi +=============== + +Aim +============ + +We like to rewrite some parts of the XApi needed for our own application. Our +aim is not get a full implementation of the Xapi, but to answer only specific +requests, at low latency. For this subset of Xapi we want completly cover the +original api. + +Requests +============= + +This is a list of example requests, we want to optimize. + +* xapi.spline.de/api/0.6/node[amenity=*] +* xapi.spline.de/api/0.6/node[highway=busstop] +* xapi.spline.de/api/0.6/node[bbox=-6,50,2,61] +* xapi.spline.de/api/0.6/node[amenity=hospital][bbox=-6,50,2,61] + +a more formal description +------------------------- + +We serve the node endpoint, but no others. We implment the tag based filtering, +for only one tag and a bounding box. + +database shema +================ + +We keep data in a highly specioaliced shema, that allows us to prevent tables +growing to big. And supports our requests at maximum speed. + +| CREATE TABLE : ( +| {bigint id} +| {longitude float4}, +| {latitude float4}, +| {object varchar} +| ) PRIMARY KEY id; + +Implmentation +============= + +Teilprobleme: +.............. + +1. Database import + +mögliche Technologien: +* Osmosis- plugin +* selbst in python (Protobuf consumer, async pgsql schreiber) + + +2. Web API +.............. + +mögliche Technologien: +* node.js -- cgit v1.2.3 From 186c67f2b33b09d4df776e0fba19f1085a2da88d Mon Sep 17 00:00:00 2001 From: Robin Nehls Date: Sun, 9 Jan 2011 02:02:08 +0100 Subject: first code for the db import tool it only reads the osm header of pbf files for now, more will follow --- pbf2db/binarystream.py | 95 ++++++++++++++++++++ pbf2db/build_proto.sh | 3 + pbf2db/fileformat.proto | 49 +++++++++++ pbf2db/osmformat.proto | 225 ++++++++++++++++++++++++++++++++++++++++++++++++ pbf2db/pbf2db.py | 44 ++++++++++ 5 files changed, 416 insertions(+) create mode 100644 pbf2db/binarystream.py create mode 100755 pbf2db/build_proto.sh create mode 100644 pbf2db/fileformat.proto create mode 100644 pbf2db/osmformat.proto create mode 100755 pbf2db/pbf2db.py diff --git a/pbf2db/binarystream.py b/pbf2db/binarystream.py new file mode 100644 index 0000000..e1e0280 --- /dev/null +++ b/pbf2db/binarystream.py @@ -0,0 +1,95 @@ +from struct import * + +class BinaryStream: + def __init__(self, base_stream): + self.base_stream = base_stream + + def readByte(self): + return self.base_stream.read(1) + + def readBytes(self, length): + return self.base_stream.read(length) + + def readChar(self): + return self.unpack('b') + + def readUChar(self): + return self.unpack('B') + + def readBool(self): + return self.unpack('?') + + def readInt16(self): + return self.unpack('h', 2) + + def readUInt16(self): + return self.unpack('H', 2) + + def readInt32(self): + return self.unpack('i', 4) + + def readUInt32(self): + return self.unpack('I', 4) + + def readInt64(self): + return self.unpack('q', 8) + + def readUInt64(self): + return self.unpack('Q', 8) + + def readFloat(self): + return self.unpack('f', 4) + + def readDouble(self): + return self.unpack('d', 8) + + def readString(self): + length = self.readUInt16() + return self.unpack(str(length) + 's', length) + + def writeBytes(self, value): + self.base_stream.write(value) + + def writeChar(self, value): + self.pack('c', value) + + def writeUChar(self, value): + self.pack('C', value) + + def writeBool(self, value): + self.pack('?', value) + + def writeInt16(self, value): + self.pack('h', value) + + def writeUInt16(self, value): + self.pack('H', value) + + def writeInt32(self, value): + self.pack('i', value) + + def writeUInt32(self, value): + self.pack('I', value) + + def writeInt64(self, value): + self.pack('q', value) + + def writeUInt64(self, value): + self.pack('Q', value) + + def writeFloat(self, value): + self.pack('f', value) + + def writeDouble(self, value): + self.pack('d', value) + + def writeString(self, value): + length = len(value) + self.writeUInt16(length) + self.pack(str(length) + 's', value) + + def pack(self, fmt, data): + return self.writeBytes(pack(fmt, data)) + + def unpack(self, fmt, length = 1): + return unpack(fmt, self.readBytes(length))[0] diff --git a/pbf2db/build_proto.sh b/pbf2db/build_proto.sh new file mode 100755 index 0000000..53e9966 --- /dev/null +++ b/pbf2db/build_proto.sh @@ -0,0 +1,3 @@ +#!/bin/sh +protoc --python_out=. fileformat.proto +protoc --python_out=. osmformat.proto diff --git a/pbf2db/fileformat.proto b/pbf2db/fileformat.proto new file mode 100644 index 0000000..f1b540a --- /dev/null +++ b/pbf2db/fileformat.proto @@ -0,0 +1,49 @@ +/** Copyright (c) 2010 Scott A. Crosby. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + +package OSMPBF; + +// +// STORAGE LAYER: Storing primitives. +// + +message Blob { + optional bytes raw = 1; // No compression + optional int32 raw_size = 2; // When compressed, the uncompressed size + + // Possible compressed versions of the data. + optional bytes zlib_data = 3; + + // PROPOSED feature for LZMA compressed data. SUPPORT IS NOT REQUIRED. + optional bytes lzma_data = 4; + + // Formerly used for bzip2 compressed data. Depreciated in 2010. + optional bytes OBSOLETE_bzip2_data = 5 [deprecated=true]; // Don't reuse this tag number. +} + +/* A file contains an sequence of fileblock headers, each prefixed by +their length in network byte order, followed by a data block +containing the actual data. types staring with a "_" are reserved. +*/ + +message BlobHeader { + required string type = 1; + optional bytes indexdata = 2; + required int32 datasize = 3; +} + + diff --git a/pbf2db/osmformat.proto b/pbf2db/osmformat.proto new file mode 100644 index 0000000..eaad195 --- /dev/null +++ b/pbf2db/osmformat.proto @@ -0,0 +1,225 @@ +/** Copyright (c) 2010 Scott A. Crosby. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation, either version 3 of the + License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +*/ + +package OSMPBF; + +/* OSM Binary file format + +This is the master schema file of the OSM binary file format. This +file is designed to support limited random-access and future +extendability. + +A binary OSM file consists of a sequence of FileBlocks (please see +fileformat.proto). The first fileblock contains a serialized instance +of HeaderBlock, followed by a sequence of PrimitiveBlock blocks that +contain the primitives. + +Each primitiveblock is designed to be independently parsable. It +contains a string table storing all strings in that block (keys and +values in tags, roles in relations, usernames, etc.) as well as +metadata containing the precision of coordinates or timestamps in that +block. + +A primitiveblock contains a sequence of primitive groups, each +containing primitives of the same type (nodes, densenodes, ways, +relations). Coordinates are stored in signed 64-bit integers. Lat&lon +are measured in units nanodegrees. The default of +granularity of 100 nanodegrees corresponds to about 1cm on the ground, +and a full lat or lon fits into 32 bits. + +Converting an integer to a lattitude or longitude uses the formula: +$OUT = IN * granularity / 10**9$. Many encoding schemes use delta +coding when representing nodes and relations. + +*/ + +////////////////////////////////////////////////////////////////////////// +////////////////////////////////////////////////////////////////////////// + +/* Contains the file header. */ + +message HeaderBlock { + optional HeaderBBox bbox = 1; + /* Additional tags to aid in parsing this dataset */ + repeated string required_features = 4; + repeated string optional_features = 5; + + optional string writingprogram = 16; + optional string source = 17; // From the bbox field. +} + + +/** The bounding box field in the OSM header. BBOX, as used in the OSM +header. Units are always in nanodegrees -- they do not obey +granularity rules. */ + +message HeaderBBox { + required sint64 left = 1; + required sint64 right = 2; + required sint64 top = 3; + required sint64 bottom = 4; +} + + +/////////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////////// + + +message PrimitiveBlock { + required StringTable stringtable = 1; + repeated PrimitiveGroup primitivegroup = 2; + + // Granularity, units of nanodegrees, used to store coordinates in this block + optional int32 granularity = 17 [default=100]; + // Offset value between the output coordinates coordinates and the granularity grid in unites of nanodegrees. + optional int64 lat_offset = 19 [default=0]; + optional int64 lon_offset = 20 [default=0]; + +// Granularity of dates, normally represented in units of milliseconds since the 1970 epoch. + optional int32 date_granularity = 18 [default=1000]; + + + // Proposed extension: + //optional BBox bbox = XX; +} + +// Group of OSMPrimitives. All primitives in a group must be the same type. +message PrimitiveGroup { + repeated Node nodes = 1; + optional DenseNodes dense = 2; + repeated Way ways = 3; + repeated Relation relations = 4; + repeated ChangeSet changesets = 5; +} + + +/** String table, contains the common strings in each block. + + Note that we reserve index '0' as a delimiter, so the entry at that + index in the table is ALWAYS blank and unused. + + */ +message StringTable { + repeated bytes s = 1; +} + +/* Optional metadata that may be included into each primitive. */ +message Info { + optional int32 version = 1 [default = -1]; + optional int64 timestamp = 2; + optional int64 changeset = 3; + optional int32 uid = 4; + optional uint32 user_sid = 5; // String IDs +} + +/** Optional metadata that may be included into each primitive. Special dense format used in DenseNodes. */ +message DenseInfo { + repeated int32 version = 1 [packed = true]; + repeated sint64 timestamp = 2 [packed = true]; // DELTA coded + repeated sint64 changeset = 3 [packed = true]; // DELTA coded + repeated sint32 uid = 4 [packed = true]; // DELTA coded + repeated sint32 user_sid = 5 [packed = true]; // String IDs for usernames. DELTA coded +} + + +// THIS IS STUB DESIGN FOR CHANGESETS. NOT USED RIGHT NOW. +// TODO: REMOVE THIS? +message ChangeSet { + required int64 id = 1; +// +// // Parallel arrays. +// repeated uint32 keys = 2 [packed = true]; // String IDs. +// repeated uint32 vals = 3 [packed = true]; // String IDs. +// +// optional Info info = 4; + +// optional int64 created_at = 8; +// optional int64 closetime_delta = 9; +// optional bool open = 10; +// optional HeaderBBox bbox = 11; +} + + +message Node { + required sint64 id = 1; + // Parallel arrays. + repeated uint32 keys = 2 [packed = true]; // String IDs. + repeated uint32 vals = 3 [packed = true]; // String IDs. + + optional Info info = 4; // May be omitted in omitmeta + + required sint64 lat = 8; + required sint64 lon = 9; +} + +/* Used to densly represent a sequence of nodes that do not have any tags. + +We represent these nodes columnwise as five columns: ID's, lats, and +lons, all delta coded. When metadata is not omitted, + +We encode keys & vals for all nodes as a single array of integers +containing key-stringid and val-stringid, using a stringid of 0 as a +delimiter between nodes. + + ( ( )* '0' )* + */ + +message DenseNodes { + repeated sint64 id = 1 [packed = true]; // DELTA coded + + //repeated Info info = 4; + optional DenseInfo denseinfo = 5; + + repeated sint64 lat = 8 [packed = true]; // DELTA coded + repeated sint64 lon = 9 [packed = true]; // DELTA coded + + // Special packing of keys and vals into one array. May be empty if all nodes in this block are tagless. + repeated int32 keys_vals = 10 [packed = true]; +} + + +message Way { + required int64 id = 1; + // Parallel arrays. + repeated uint32 keys = 2 [packed = true]; + repeated uint32 vals = 3 [packed = true]; + + optional Info info = 4; + + repeated sint64 refs = 8 [packed = true]; // DELTA coded +} + +message Relation { + enum MemberType { + NODE = 0; + WAY = 1; + RELATION = 2; + } + required int64 id = 1; + + // Parallel arrays. + repeated uint32 keys = 2 [packed = true]; + repeated uint32 vals = 3 [packed = true]; + + optional Info info = 4; + + // Parallel arrays + repeated int32 roles_sid = 8 [packed = true]; + repeated sint64 memids = 9 [packed = true]; // DELTA encoded + repeated MemberType types = 10 [packed = true]; +} + diff --git a/pbf2db/pbf2db.py b/pbf2db/pbf2db.py new file mode 100755 index 0000000..c6089fc --- /dev/null +++ b/pbf2db/pbf2db.py @@ -0,0 +1,44 @@ +#!/usr/bin/python + +import osmformat_pb2 +import fileformat_pb2 +import sys +import socket +import zlib +from binarystream import BinaryStream + + +headerSizeMax = 64 * 1024 +bodySizeMax = 32*1024*1024 + +f = open("berlin.osm.pbf") +stream = BinaryStream(f) +headerSize = socket.ntohl(stream.readUInt32()); + +if headerSizeMax < headerSize: + raise ValueError("Header to long") + +headerbuff = stream.readBytes(headerSize) +blobheader = fileformat_pb2.BlobHeader() +blobheader.ParseFromString(headerbuff) +bodysize = blobheader.datasize + +if bodySizeMax < bodysize: + raise ValueError("Body to fat") + +blobbuff = stream.readBytes(bodysize) +blob = fileformat_pb2.Blob() +blob.ParseFromString(blobbuff) + +if blob.raw != "": + rawstr = blob.raw +else: + rawstr = zlib.decompress(blob.zlib_data) + +headerblock = osmformat_pb2.HeaderBlock() +headerblock.ParseFromString(rawstr) + +print "Source:",headerblock.source +print "Writingprog:",headerblock.writingprogram +print "required features:",headerblock.required_features + -- cgit v1.2.3 From 9adc1a65ba87963db5de9c3aa15604cf56121794 Mon Sep 17 00:00:00 2001 From: slomo Date: Sun, 9 Jan 2011 02:27:43 +0100 Subject: first node.js code --- src/nodejs/start.js | 105 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/nodejs/start.js diff --git a/src/nodejs/start.js b/src/nodejs/start.js new file mode 100644 index 0000000..2cf923e --- /dev/null +++ b/src/nodejs/start.js @@ -0,0 +1,105 @@ +// imports +var http = require('http'), + querystring = require('querystring'), + pg = require('pg'), + url = require('url'), + 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"); + } + + }); + } +}); +} + + +function createQuery(tag,bbox){ + // FIXME: validate + var table = tag[0] + "#" + tag[1]; + var filter = ""; + + // input validation + for(i=0;i " + bbox[2] + " AND latitude < " + bbox[3]; + } + return "SELECT * FROM \"" + table + "\" " + filter + ";"; +} + + +RegExp.escape= function(s) { + return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') +}; + + +var PATH_PREFIX = '/api/'; +var base_url_re = new RegExp('^' + RegExp.escape(PATH_PREFIX) + + '(node|way|relation|\\*)(.*)$') +var filter_re = /\[(\w+=[^\]]+)\]/g; + + +http.createServer(function (req, res) { + + if (!base_url_re.test(req.url)) { + res.writeHead(404, {'Content-Type': 'text/plain; charset=utf8'}); + res.end('Not Found\n'); + } + 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; + + for(i=0;i Date: Wed, 12 Jan 2011 16:44:31 +0100 Subject: some cleanup, tests with bo --- src/nodejs/start.js | 73 +++++++++++++++++++++++++++++------------------------ 1 file 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[2] + " AND latitude < " + bbox[3]; + // } - // input validation - for(i=0;i " + 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'); -- cgit v1.2.3 From 2d370398fe8b2329736d839504999186a1aee0aa Mon Sep 17 00:00:00 2001 From: slomo Date: Wed, 12 Jan 2011 22:58:31 +0100 Subject: some new tries --- src/nodejs/no1.js | 17 ++ src/nodejs/no2.js | 106 ++++++++ src/nodejs/start.js | 79 +++--- src/sql/exampleDatabase.test | 17 ++ src/sql/generateData.sh | 18 ++ src/sql/insert.sql | 600 +++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 794 insertions(+), 43 deletions(-) create mode 100644 src/nodejs/no1.js create mode 100644 src/nodejs/no2.js create mode 100644 src/sql/exampleDatabase.test create mode 100755 src/sql/generateData.sh create mode 100644 src/sql/insert.sql diff --git a/src/nodejs/no1.js b/src/nodejs/no1.js new file mode 100644 index 0000000..feb3dfb --- /dev/null +++ b/src/nodejs/no1.js @@ -0,0 +1,17 @@ +var clutch = require('clutch'); + +function helloSomeone(req, res, name,bbox, key, value) { + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end('obj:'+name+ ' bbox: '+ bbox + ' key:' +key +' value:'+value+'!\n'); +} + +function helloWorld(req, res) { + helloSomeone(req, res, 'World'); +} + +myRoutes = clutch.route404([['GET /hello/(\\w+)(\\[bbox=(\\d,\\d,\\d,\\d)\\])*\\[(\\w+)=(\\w+)\\]$', helloSomeone], + ['GET /hello/$', helloWorld]]); + + +var http = require('http'); +http.createServer(myRoutes).listen(3000, '127.0.0.1'); diff --git a/src/nodejs/no2.js b/src/nodejs/no2.js new file mode 100644 index 0000000..233b5e1 --- /dev/null +++ b/src/nodejs/no2.js @@ -0,0 +1,106 @@ +var users = [ + { name: 'tj' }, + { name: 'tim' } +]; + +function user(app) { + app.resource('/.:format?', { + 'get' : function(req, res, next) { + switch (req.params.format) { + case 'json': + var body = JSON.stringify(users); + res.writeHead(200, { + 'Content-Type': 'application/json', + 'Content-Length': body.length + }); + res.end(body); + break; + default: + var body = '
    ' + + users.map(function(user) { + return '
  • ' + user.name + '
  • '; + }).join('\n') + + '
'; + res.writeHead(200, { + 'Content-Type': 'text/html', + 'Content-Length': body.length + }); + res.end(body); + } + } + }); + + app.resource('/:id.:format', { + 'get' : function(req, res, next) { + var user = users[req.params.id]; + if (user && req.params.format === 'json') { + user = JSON.stringify(user); + res.writeHead(200, { + 'Content-Type': 'application/json', + 'Content-Length': user.length + }); + res.end(user); + } + else { + // When true is passed, provide control + // back to middleware, skipping route + // match attemps + next(true); + } + } + }) + + app.resource('/\\[:id/:op?', { + 'get' : function(req, res) { + var body = users[req.params.id] + ? users[req.params.id].name + : 'User ' + req.params.id + ' does not exist'; + body = (req.params.op || 'view') + 'ing ' + body; + res.writeHead(200, { + 'Content-Type': 'text/html', + 'Content-Length': body.length + }); + res.end(body, 'utf8'); + } + }) +} + + +function main(app) { + app.resource('/', { + 'get' : function(req, res) { + var examples = [ + '/users', + '/users.json', + '/users/0 (or /users/0/view)', + '/users/0/edit', + '/users/0.json' + ]; + var body = 'Visit one of the following:
    ' + + examples.map(function(str) { + return '
  • ' + str + '
  • ' + }).join('\n') + + '
'; + res.writeHead(200, { + 'Content-Type': 'text/html', + 'Content-Length': body.length + }); + res.end(body, 'utf8'); + } + }); +} + + +var connect = require('connect'); +var resource = require('resource-router'); + +var server = connect.createServer( + connect.logger({ buffer: true }), + connect.cache(), + connect.gzip() + ); + +server.use('/users', resource(user)); +server.use(resource(main)); +server.listen(3000); +console.log('Connect server listening on port 3000'); 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[2] + " AND latitude < " + bbox[3]; - // } + var table = tag[0] + "#" + tag[1]; + var filter = ""; + // input validation + for(i=0;i '\"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'); diff --git a/src/sql/exampleDatabase.test b/src/sql/exampleDatabase.test new file mode 100644 index 0000000..a585ea6 --- /dev/null +++ b/src/sql/exampleDatabase.test @@ -0,0 +1,17 @@ +CREATE TABLE "anamnity#pub" ( + id bigint PRIMARY KEY, + longitude float4, + latitude float4, + object varchar); + +CREATE TABLE "highway#tohell" ( + id bigint PRIMARY KEY, + longitude float4, + latitude float4, + object varchar); + +CREATE TABLE "anamnity#resturant" ( + id bigint PRIMARY KEY, + longitude float4, + latitude float4, + object varchar); diff --git a/src/sql/generateData.sh b/src/sql/generateData.sh new file mode 100755 index 0000000..7c4276e --- /dev/null +++ b/src/sql/generateData.sh @@ -0,0 +1,18 @@ +#! /bin/bash +rm -f insert.sql +touch insert.sql + +for i in `seq 1 100`; do + echo "INSERT INTO \"anamnity#pub\" VALUES + ( $i , $i.5 , $i.7, 'pub nr $i'); " >> insert.sql +done + +for i in `seq 1 100`; do + echo "INSERT INTO \"highway#tohell\" VALUES + ( $i , $i.5 , $i.7, 'highway nr $i'); " >> insert.sql +done + +for i in `seq 1 100`; do + echo "INSERT INTO \"anamnity#resturant\" VALUES + ( $i , $i.5 , $i.7, 'restuarant nr $i'); " >> insert.sql +done diff --git a/src/sql/insert.sql b/src/sql/insert.sql new file mode 100644 index 0000000..737d06f --- /dev/null +++ b/src/sql/insert.sql @@ -0,0 +1,600 @@ +INSERT INTO "anamnity#pub" VALUES + ( 1 , 1.5 , 1.7, 'pub nr 1'); +INSERT INTO "anamnity#pub" VALUES + ( 2 , 2.5 , 2.7, 'pub nr 2'); +INSERT INTO "anamnity#pub" VALUES + ( 3 , 3.5 , 3.7, 'pub nr 3'); +INSERT INTO "anamnity#pub" VALUES + ( 4 , 4.5 , 4.7, 'pub nr 4'); +INSERT INTO "anamnity#pub" VALUES + ( 5 , 5.5 , 5.7, 'pub nr 5'); +INSERT INTO "anamnity#pub" VALUES + ( 6 , 6.5 , 6.7, 'pub nr 6'); +INSERT INTO "anamnity#pub" VALUES + ( 7 , 7.5 , 7.7, 'pub nr 7'); +INSERT INTO "anamnity#pub" VALUES + ( 8 , 8.5 , 8.7, 'pub nr 8'); +INSERT INTO "anamnity#pub" VALUES + ( 9 , 9.5 , 9.7, 'pub nr 9'); +INSERT INTO "anamnity#pub" VALUES + ( 10 , 10.5 , 10.7, 'pub nr 10'); +INSERT INTO "anamnity#pub" VALUES + ( 11 , 11.5 , 11.7, 'pub nr 11'); +INSERT INTO "anamnity#pub" VALUES + ( 12 , 12.5 , 12.7, 'pub nr 12'); +INSERT INTO "anamnity#pub" VALUES + ( 13 , 13.5 , 13.7, 'pub nr 13'); +INSERT INTO "anamnity#pub" VALUES + ( 14 , 14.5 , 14.7, 'pub nr 14'); +INSERT INTO "anamnity#pub" VALUES + ( 15 , 15.5 , 15.7, 'pub nr 15'); +INSERT INTO "anamnity#pub" VALUES + ( 16 , 16.5 , 16.7, 'pub nr 16'); +INSERT INTO "anamnity#pub" VALUES + ( 17 , 17.5 , 17.7, 'pub nr 17'); +INSERT INTO "anamnity#pub" VALUES + ( 18 , 18.5 , 18.7, 'pub nr 18'); +INSERT INTO "anamnity#pub" VALUES + ( 19 , 19.5 , 19.7, 'pub nr 19'); +INSERT INTO "anamnity#pub" VALUES + ( 20 , 20.5 , 20.7, 'pub nr 20'); +INSERT INTO "anamnity#pub" VALUES + ( 21 , 21.5 , 21.7, 'pub nr 21'); +INSERT INTO "anamnity#pub" VALUES + ( 22 , 22.5 , 22.7, 'pub nr 22'); +INSERT INTO "anamnity#pub" VALUES + ( 23 , 23.5 , 23.7, 'pub nr 23'); +INSERT INTO "anamnity#pub" VALUES + ( 24 , 24.5 , 24.7, 'pub nr 24'); +INSERT INTO "anamnity#pub" VALUES + ( 25 , 25.5 , 25.7, 'pub nr 25'); +INSERT INTO "anamnity#pub" VALUES + ( 26 , 26.5 , 26.7, 'pub nr 26'); +INSERT INTO "anamnity#pub" VALUES + ( 27 , 27.5 , 27.7, 'pub nr 27'); +INSERT INTO "anamnity#pub" VALUES + ( 28 , 28.5 , 28.7, 'pub nr 28'); +INSERT INTO "anamnity#pub" VALUES + ( 29 , 29.5 , 29.7, 'pub nr 29'); +INSERT INTO "anamnity#pub" VALUES + ( 30 , 30.5 , 30.7, 'pub nr 30'); +INSERT INTO "anamnity#pub" VALUES + ( 31 , 31.5 , 31.7, 'pub nr 31'); +INSERT INTO "anamnity#pub" VALUES + ( 32 , 32.5 , 32.7, 'pub nr 32'); +INSERT INTO "anamnity#pub" VALUES + ( 33 , 33.5 , 33.7, 'pub nr 33'); +INSERT INTO "anamnity#pub" VALUES + ( 34 , 34.5 , 34.7, 'pub nr 34'); +INSERT INTO "anamnity#pub" VALUES + ( 35 , 35.5 , 35.7, 'pub nr 35'); +INSERT INTO "anamnity#pub" VALUES + ( 36 , 36.5 , 36.7, 'pub nr 36'); +INSERT INTO "anamnity#pub" VALUES + ( 37 , 37.5 , 37.7, 'pub nr 37'); +INSERT INTO "anamnity#pub" VALUES + ( 38 , 38.5 , 38.7, 'pub nr 38'); +INSERT INTO "anamnity#pub" VALUES + ( 39 , 39.5 , 39.7, 'pub nr 39'); +INSERT INTO "anamnity#pub" VALUES + ( 40 , 40.5 , 40.7, 'pub nr 40'); +INSERT INTO "anamnity#pub" VALUES + ( 41 , 41.5 , 41.7, 'pub nr 41'); +INSERT INTO "anamnity#pub" VALUES + ( 42 , 42.5 , 42.7, 'pub nr 42'); +INSERT INTO "anamnity#pub" VALUES + ( 43 , 43.5 , 43.7, 'pub nr 43'); +INSERT INTO "anamnity#pub" VALUES + ( 44 , 44.5 , 44.7, 'pub nr 44'); +INSERT INTO "anamnity#pub" VALUES + ( 45 , 45.5 , 45.7, 'pub nr 45'); +INSERT INTO "anamnity#pub" VALUES + ( 46 , 46.5 , 46.7, 'pub nr 46'); +INSERT INTO "anamnity#pub" VALUES + ( 47 , 47.5 , 47.7, 'pub nr 47'); +INSERT INTO "anamnity#pub" VALUES + ( 48 , 48.5 , 48.7, 'pub nr 48'); +INSERT INTO "anamnity#pub" VALUES + ( 49 , 49.5 , 49.7, 'pub nr 49'); +INSERT INTO "anamnity#pub" VALUES + ( 50 , 50.5 , 50.7, 'pub nr 50'); +INSERT INTO "anamnity#pub" VALUES + ( 51 , 51.5 , 51.7, 'pub nr 51'); +INSERT INTO "anamnity#pub" VALUES + ( 52 , 52.5 , 52.7, 'pub nr 52'); +INSERT INTO "anamnity#pub" VALUES + ( 53 , 53.5 , 53.7, 'pub nr 53'); +INSERT INTO "anamnity#pub" VALUES + ( 54 , 54.5 , 54.7, 'pub nr 54'); +INSERT INTO "anamnity#pub" VALUES + ( 55 , 55.5 , 55.7, 'pub nr 55'); +INSERT INTO "anamnity#pub" VALUES + ( 56 , 56.5 , 56.7, 'pub nr 56'); +INSERT INTO "anamnity#pub" VALUES + ( 57 , 57.5 , 57.7, 'pub nr 57'); +INSERT INTO "anamnity#pub" VALUES + ( 58 , 58.5 , 58.7, 'pub nr 58'); +INSERT INTO "anamnity#pub" VALUES + ( 59 , 59.5 , 59.7, 'pub nr 59'); +INSERT INTO "anamnity#pub" VALUES + ( 60 , 60.5 , 60.7, 'pub nr 60'); +INSERT INTO "anamnity#pub" VALUES + ( 61 , 61.5 , 61.7, 'pub nr 61'); +INSERT INTO "anamnity#pub" VALUES + ( 62 , 62.5 , 62.7, 'pub nr 62'); +INSERT INTO "anamnity#pub" VALUES + ( 63 , 63.5 , 63.7, 'pub nr 63'); +INSERT INTO "anamnity#pub" VALUES + ( 64 , 64.5 , 64.7, 'pub nr 64'); +INSERT INTO "anamnity#pub" VALUES + ( 65 , 65.5 , 65.7, 'pub nr 65'); +INSERT INTO "anamnity#pub" VALUES + ( 66 , 66.5 , 66.7, 'pub nr 66'); +INSERT INTO "anamnity#pub" VALUES + ( 67 , 67.5 , 67.7, 'pub nr 67'); +INSERT INTO "anamnity#pub" VALUES + ( 68 , 68.5 , 68.7, 'pub nr 68'); +INSERT INTO "anamnity#pub" VALUES + ( 69 , 69.5 , 69.7, 'pub nr 69'); +INSERT INTO "anamnity#pub" VALUES + ( 70 , 70.5 , 70.7, 'pub nr 70'); +INSERT INTO "anamnity#pub" VALUES + ( 71 , 71.5 , 71.7, 'pub nr 71'); +INSERT INTO "anamnity#pub" VALUES + ( 72 , 72.5 , 72.7, 'pub nr 72'); +INSERT INTO "anamnity#pub" VALUES + ( 73 , 73.5 , 73.7, 'pub nr 73'); +INSERT INTO "anamnity#pub" VALUES + ( 74 , 74.5 , 74.7, 'pub nr 74'); +INSERT INTO "anamnity#pub" VALUES + ( 75 , 75.5 , 75.7, 'pub nr 75'); +INSERT INTO "anamnity#pub" VALUES + ( 76 , 76.5 , 76.7, 'pub nr 76'); +INSERT INTO "anamnity#pub" VALUES + ( 77 , 77.5 , 77.7, 'pub nr 77'); +INSERT INTO "anamnity#pub" VALUES + ( 78 , 78.5 , 78.7, 'pub nr 78'); +INSERT INTO "anamnity#pub" VALUES + ( 79 , 79.5 , 79.7, 'pub nr 79'); +INSERT INTO "anamnity#pub" VALUES + ( 80 , 80.5 , 80.7, 'pub nr 80'); +INSERT INTO "anamnity#pub" VALUES + ( 81 , 81.5 , 81.7, 'pub nr 81'); +INSERT INTO "anamnity#pub" VALUES + ( 82 , 82.5 , 82.7, 'pub nr 82'); +INSERT INTO "anamnity#pub" VALUES + ( 83 , 83.5 , 83.7, 'pub nr 83'); +INSERT INTO "anamnity#pub" VALUES + ( 84 , 84.5 , 84.7, 'pub nr 84'); +INSERT INTO "anamnity#pub" VALUES + ( 85 , 85.5 , 85.7, 'pub nr 85'); +INSERT INTO "anamnity#pub" VALUES + ( 86 , 86.5 , 86.7, 'pub nr 86'); +INSERT INTO "anamnity#pub" VALUES + ( 87 , 87.5 , 87.7, 'pub nr 87'); +INSERT INTO "anamnity#pub" VALUES + ( 88 , 88.5 , 88.7, 'pub nr 88'); +INSERT INTO "anamnity#pub" VALUES + ( 89 , 89.5 , 89.7, 'pub nr 89'); +INSERT INTO "anamnity#pub" VALUES + ( 90 , 90.5 , 90.7, 'pub nr 90'); +INSERT INTO "anamnity#pub" VALUES + ( 91 , 91.5 , 91.7, 'pub nr 91'); +INSERT INTO "anamnity#pub" VALUES + ( 92 , 92.5 , 92.7, 'pub nr 92'); +INSERT INTO "anamnity#pub" VALUES + ( 93 , 93.5 , 93.7, 'pub nr 93'); +INSERT INTO "anamnity#pub" VALUES + ( 94 , 94.5 , 94.7, 'pub nr 94'); +INSERT INTO "anamnity#pub" VALUES + ( 95 , 95.5 , 95.7, 'pub nr 95'); +INSERT INTO "anamnity#pub" VALUES + ( 96 , 96.5 , 96.7, 'pub nr 96'); +INSERT INTO "anamnity#pub" VALUES + ( 97 , 97.5 , 97.7, 'pub nr 97'); +INSERT INTO "anamnity#pub" VALUES + ( 98 , 98.5 , 98.7, 'pub nr 98'); +INSERT INTO "anamnity#pub" VALUES + ( 99 , 99.5 , 99.7, 'pub nr 99'); +INSERT INTO "anamnity#pub" VALUES + ( 100 , 100.5 , 100.7, 'pub nr 100'); +INSERT INTO "highway#tohell" VALUES + ( 1 , 1.5 , 1.7, 'highway nr 1'); +INSERT INTO "highway#tohell" VALUES + ( 2 , 2.5 , 2.7, 'highway nr 2'); +INSERT INTO "highway#tohell" VALUES + ( 3 , 3.5 , 3.7, 'highway nr 3'); +INSERT INTO "highway#tohell" VALUES + ( 4 , 4.5 , 4.7, 'highway nr 4'); +INSERT INTO "highway#tohell" VALUES + ( 5 , 5.5 , 5.7, 'highway nr 5'); +INSERT INTO "highway#tohell" VALUES + ( 6 , 6.5 , 6.7, 'highway nr 6'); +INSERT INTO "highway#tohell" VALUES + ( 7 , 7.5 , 7.7, 'highway nr 7'); +INSERT INTO "highway#tohell" VALUES + ( 8 , 8.5 , 8.7, 'highway nr 8'); +INSERT INTO "highway#tohell" VALUES + ( 9 , 9.5 , 9.7, 'highway nr 9'); +INSERT INTO "highway#tohell" VALUES + ( 10 , 10.5 , 10.7, 'highway nr 10'); +INSERT INTO "highway#tohell" VALUES + ( 11 , 11.5 , 11.7, 'highway nr 11'); +INSERT INTO "highway#tohell" VALUES + ( 12 , 12.5 , 12.7, 'highway nr 12'); +INSERT INTO "highway#tohell" VALUES + ( 13 , 13.5 , 13.7, 'highway nr 13'); +INSERT INTO "highway#tohell" VALUES + ( 14 , 14.5 , 14.7, 'highway nr 14'); +INSERT INTO "highway#tohell" VALUES + ( 15 , 15.5 , 15.7, 'highway nr 15'); +INSERT INTO "highway#tohell" VALUES + ( 16 , 16.5 , 16.7, 'highway nr 16'); +INSERT INTO "highway#tohell" VALUES + ( 17 , 17.5 , 17.7, 'highway nr 17'); +INSERT INTO "highway#tohell" VALUES + ( 18 , 18.5 , 18.7, 'highway nr 18'); +INSERT INTO "highway#tohell" VALUES + ( 19 , 19.5 , 19.7, 'highway nr 19'); +INSERT INTO "highway#tohell" VALUES + ( 20 , 20.5 , 20.7, 'highway nr 20'); +INSERT INTO "highway#tohell" VALUES + ( 21 , 21.5 , 21.7, 'highway nr 21'); +INSERT INTO "highway#tohell" VALUES + ( 22 , 22.5 , 22.7, 'highway nr 22'); +INSERT INTO "highway#tohell" VALUES + ( 23 , 23.5 , 23.7, 'highway nr 23'); +INSERT INTO "highway#tohell" VALUES + ( 24 , 24.5 , 24.7, 'highway nr 24'); +INSERT INTO "highway#tohell" VALUES + ( 25 , 25.5 , 25.7, 'highway nr 25'); +INSERT INTO "highway#tohell" VALUES + ( 26 , 26.5 , 26.7, 'highway nr 26'); +INSERT INTO "highway#tohell" VALUES + ( 27 , 27.5 , 27.7, 'highway nr 27'); +INSERT INTO "highway#tohell" VALUES + ( 28 , 28.5 , 28.7, 'highway nr 28'); +INSERT INTO "highway#tohell" VALUES + ( 29 , 29.5 , 29.7, 'highway nr 29'); +INSERT INTO "highway#tohell" VALUES + ( 30 , 30.5 , 30.7, 'highway nr 30'); +INSERT INTO "highway#tohell" VALUES + ( 31 , 31.5 , 31.7, 'highway nr 31'); +INSERT INTO "highway#tohell" VALUES + ( 32 , 32.5 , 32.7, 'highway nr 32'); +INSERT INTO "highway#tohell" VALUES + ( 33 , 33.5 , 33.7, 'highway nr 33'); +INSERT INTO "highway#tohell" VALUES + ( 34 , 34.5 , 34.7, 'highway nr 34'); +INSERT INTO "highway#tohell" VALUES + ( 35 , 35.5 , 35.7, 'highway nr 35'); +INSERT INTO "highway#tohell" VALUES + ( 36 , 36.5 , 36.7, 'highway nr 36'); +INSERT INTO "highway#tohell" VALUES + ( 37 , 37.5 , 37.7, 'highway nr 37'); +INSERT INTO "highway#tohell" VALUES + ( 38 , 38.5 , 38.7, 'highway nr 38'); +INSERT INTO "highway#tohell" VALUES + ( 39 , 39.5 , 39.7, 'highway nr 39'); +INSERT INTO "highway#tohell" VALUES + ( 40 , 40.5 , 40.7, 'highway nr 40'); +INSERT INTO "highway#tohell" VALUES + ( 41 , 41.5 , 41.7, 'highway nr 41'); +INSERT INTO "highway#tohell" VALUES + ( 42 , 42.5 , 42.7, 'highway nr 42'); +INSERT INTO "highway#tohell" VALUES + ( 43 , 43.5 , 43.7, 'highway nr 43'); +INSERT INTO "highway#tohell" VALUES + ( 44 , 44.5 , 44.7, 'highway nr 44'); +INSERT INTO "highway#tohell" VALUES + ( 45 , 45.5 , 45.7, 'highway nr 45'); +INSERT INTO "highway#tohell" VALUES + ( 46 , 46.5 , 46.7, 'highway nr 46'); +INSERT INTO "highway#tohell" VALUES + ( 47 , 47.5 , 47.7, 'highway nr 47'); +INSERT INTO "highway#tohell" VALUES + ( 48 , 48.5 , 48.7, 'highway nr 48'); +INSERT INTO "highway#tohell" VALUES + ( 49 , 49.5 , 49.7, 'highway nr 49'); +INSERT INTO "highway#tohell" VALUES + ( 50 , 50.5 , 50.7, 'highway nr 50'); +INSERT INTO "highway#tohell" VALUES + ( 51 , 51.5 , 51.7, 'highway nr 51'); +INSERT INTO "highway#tohell" VALUES + ( 52 , 52.5 , 52.7, 'highway nr 52'); +INSERT INTO "highway#tohell" VALUES + ( 53 , 53.5 , 53.7, 'highway nr 53'); +INSERT INTO "highway#tohell" VALUES + ( 54 , 54.5 , 54.7, 'highway nr 54'); +INSERT INTO "highway#tohell" VALUES + ( 55 , 55.5 , 55.7, 'highway nr 55'); +INSERT INTO "highway#tohell" VALUES + ( 56 , 56.5 , 56.7, 'highway nr 56'); +INSERT INTO "highway#tohell" VALUES + ( 57 , 57.5 , 57.7, 'highway nr 57'); +INSERT INTO "highway#tohell" VALUES + ( 58 , 58.5 , 58.7, 'highway nr 58'); +INSERT INTO "highway#tohell" VALUES + ( 59 , 59.5 , 59.7, 'highway nr 59'); +INSERT INTO "highway#tohell" VALUES + ( 60 , 60.5 , 60.7, 'highway nr 60'); +INSERT INTO "highway#tohell" VALUES + ( 61 , 61.5 , 61.7, 'highway nr 61'); +INSERT INTO "highway#tohell" VALUES + ( 62 , 62.5 , 62.7, 'highway nr 62'); +INSERT INTO "highway#tohell" VALUES + ( 63 , 63.5 , 63.7, 'highway nr 63'); +INSERT INTO "highway#tohell" VALUES + ( 64 , 64.5 , 64.7, 'highway nr 64'); +INSERT INTO "highway#tohell" VALUES + ( 65 , 65.5 , 65.7, 'highway nr 65'); +INSERT INTO "highway#tohell" VALUES + ( 66 , 66.5 , 66.7, 'highway nr 66'); +INSERT INTO "highway#tohell" VALUES + ( 67 , 67.5 , 67.7, 'highway nr 67'); +INSERT INTO "highway#tohell" VALUES + ( 68 , 68.5 , 68.7, 'highway nr 68'); +INSERT INTO "highway#tohell" VALUES + ( 69 , 69.5 , 69.7, 'highway nr 69'); +INSERT INTO "highway#tohell" VALUES + ( 70 , 70.5 , 70.7, 'highway nr 70'); +INSERT INTO "highway#tohell" VALUES + ( 71 , 71.5 , 71.7, 'highway nr 71'); +INSERT INTO "highway#tohell" VALUES + ( 72 , 72.5 , 72.7, 'highway nr 72'); +INSERT INTO "highway#tohell" VALUES + ( 73 , 73.5 , 73.7, 'highway nr 73'); +INSERT INTO "highway#tohell" VALUES + ( 74 , 74.5 , 74.7, 'highway nr 74'); +INSERT INTO "highway#tohell" VALUES + ( 75 , 75.5 , 75.7, 'highway nr 75'); +INSERT INTO "highway#tohell" VALUES + ( 76 , 76.5 , 76.7, 'highway nr 76'); +INSERT INTO "highway#tohell" VALUES + ( 77 , 77.5 , 77.7, 'highway nr 77'); +INSERT INTO "highway#tohell" VALUES + ( 78 , 78.5 , 78.7, 'highway nr 78'); +INSERT INTO "highway#tohell" VALUES + ( 79 , 79.5 , 79.7, 'highway nr 79'); +INSERT INTO "highway#tohell" VALUES + ( 80 , 80.5 , 80.7, 'highway nr 80'); +INSERT INTO "highway#tohell" VALUES + ( 81 , 81.5 , 81.7, 'highway nr 81'); +INSERT INTO "highway#tohell" VALUES + ( 82 , 82.5 , 82.7, 'highway nr 82'); +INSERT INTO "highway#tohell" VALUES + ( 83 , 83.5 , 83.7, 'highway nr 83'); +INSERT INTO "highway#tohell" VALUES + ( 84 , 84.5 , 84.7, 'highway nr 84'); +INSERT INTO "highway#tohell" VALUES + ( 85 , 85.5 , 85.7, 'highway nr 85'); +INSERT INTO "highway#tohell" VALUES + ( 86 , 86.5 , 86.7, 'highway nr 86'); +INSERT INTO "highway#tohell" VALUES + ( 87 , 87.5 , 87.7, 'highway nr 87'); +INSERT INTO "highway#tohell" VALUES + ( 88 , 88.5 , 88.7, 'highway nr 88'); +INSERT INTO "highway#tohell" VALUES + ( 89 , 89.5 , 89.7, 'highway nr 89'); +INSERT INTO "highway#tohell" VALUES + ( 90 , 90.5 , 90.7, 'highway nr 90'); +INSERT INTO "highway#tohell" VALUES + ( 91 , 91.5 , 91.7, 'highway nr 91'); +INSERT INTO "highway#tohell" VALUES + ( 92 , 92.5 , 92.7, 'highway nr 92'); +INSERT INTO "highway#tohell" VALUES + ( 93 , 93.5 , 93.7, 'highway nr 93'); +INSERT INTO "highway#tohell" VALUES + ( 94 , 94.5 , 94.7, 'highway nr 94'); +INSERT INTO "highway#tohell" VALUES + ( 95 , 95.5 , 95.7, 'highway nr 95'); +INSERT INTO "highway#tohell" VALUES + ( 96 , 96.5 , 96.7, 'highway nr 96'); +INSERT INTO "highway#tohell" VALUES + ( 97 , 97.5 , 97.7, 'highway nr 97'); +INSERT INTO "highway#tohell" VALUES + ( 98 , 98.5 , 98.7, 'highway nr 98'); +INSERT INTO "highway#tohell" VALUES + ( 99 , 99.5 , 99.7, 'highway nr 99'); +INSERT INTO "highway#tohell" VALUES + ( 100 , 100.5 , 100.7, 'highway nr 100'); +INSERT INTO "anamnity#resturant" VALUES + ( 1 , 1.5 , 1.7, 'restuarant nr 1'); +INSERT INTO "anamnity#resturant" VALUES + ( 2 , 2.5 , 2.7, 'restuarant nr 2'); +INSERT INTO "anamnity#resturant" VALUES + ( 3 , 3.5 , 3.7, 'restuarant nr 3'); +INSERT INTO "anamnity#resturant" VALUES + ( 4 , 4.5 , 4.7, 'restuarant nr 4'); +INSERT INTO "anamnity#resturant" VALUES + ( 5 , 5.5 , 5.7, 'restuarant nr 5'); +INSERT INTO "anamnity#resturant" VALUES + ( 6 , 6.5 , 6.7, 'restuarant nr 6'); +INSERT INTO "anamnity#resturant" VALUES + ( 7 , 7.5 , 7.7, 'restuarant nr 7'); +INSERT INTO "anamnity#resturant" VALUES + ( 8 , 8.5 , 8.7, 'restuarant nr 8'); +INSERT INTO "anamnity#resturant" VALUES + ( 9 , 9.5 , 9.7, 'restuarant nr 9'); +INSERT INTO "anamnity#resturant" VALUES + ( 10 , 10.5 , 10.7, 'restuarant nr 10'); +INSERT INTO "anamnity#resturant" VALUES + ( 11 , 11.5 , 11.7, 'restuarant nr 11'); +INSERT INTO "anamnity#resturant" VALUES + ( 12 , 12.5 , 12.7, 'restuarant nr 12'); +INSERT INTO "anamnity#resturant" VALUES + ( 13 , 13.5 , 13.7, 'restuarant nr 13'); +INSERT INTO "anamnity#resturant" VALUES + ( 14 , 14.5 , 14.7, 'restuarant nr 14'); +INSERT INTO "anamnity#resturant" VALUES + ( 15 , 15.5 , 15.7, 'restuarant nr 15'); +INSERT INTO "anamnity#resturant" VALUES + ( 16 , 16.5 , 16.7, 'restuarant nr 16'); +INSERT INTO "anamnity#resturant" VALUES + ( 17 , 17.5 , 17.7, 'restuarant nr 17'); +INSERT INTO "anamnity#resturant" VALUES + ( 18 , 18.5 , 18.7, 'restuarant nr 18'); +INSERT INTO "anamnity#resturant" VALUES + ( 19 , 19.5 , 19.7, 'restuarant nr 19'); +INSERT INTO "anamnity#resturant" VALUES + ( 20 , 20.5 , 20.7, 'restuarant nr 20'); +INSERT INTO "anamnity#resturant" VALUES + ( 21 , 21.5 , 21.7, 'restuarant nr 21'); +INSERT INTO "anamnity#resturant" VALUES + ( 22 , 22.5 , 22.7, 'restuarant nr 22'); +INSERT INTO "anamnity#resturant" VALUES + ( 23 , 23.5 , 23.7, 'restuarant nr 23'); +INSERT INTO "anamnity#resturant" VALUES + ( 24 , 24.5 , 24.7, 'restuarant nr 24'); +INSERT INTO "anamnity#resturant" VALUES + ( 25 , 25.5 , 25.7, 'restuarant nr 25'); +INSERT INTO "anamnity#resturant" VALUES + ( 26 , 26.5 , 26.7, 'restuarant nr 26'); +INSERT INTO "anamnity#resturant" VALUES + ( 27 , 27.5 , 27.7, 'restuarant nr 27'); +INSERT INTO "anamnity#resturant" VALUES + ( 28 , 28.5 , 28.7, 'restuarant nr 28'); +INSERT INTO "anamnity#resturant" VALUES + ( 29 , 29.5 , 29.7, 'restuarant nr 29'); +INSERT INTO "anamnity#resturant" VALUES + ( 30 , 30.5 , 30.7, 'restuarant nr 30'); +INSERT INTO "anamnity#resturant" VALUES + ( 31 , 31.5 , 31.7, 'restuarant nr 31'); +INSERT INTO "anamnity#resturant" VALUES + ( 32 , 32.5 , 32.7, 'restuarant nr 32'); +INSERT INTO "anamnity#resturant" VALUES + ( 33 , 33.5 , 33.7, 'restuarant nr 33'); +INSERT INTO "anamnity#resturant" VALUES + ( 34 , 34.5 , 34.7, 'restuarant nr 34'); +INSERT INTO "anamnity#resturant" VALUES + ( 35 , 35.5 , 35.7, 'restuarant nr 35'); +INSERT INTO "anamnity#resturant" VALUES + ( 36 , 36.5 , 36.7, 'restuarant nr 36'); +INSERT INTO "anamnity#resturant" VALUES + ( 37 , 37.5 , 37.7, 'restuarant nr 37'); +INSERT INTO "anamnity#resturant" VALUES + ( 38 , 38.5 , 38.7, 'restuarant nr 38'); +INSERT INTO "anamnity#resturant" VALUES + ( 39 , 39.5 , 39.7, 'restuarant nr 39'); +INSERT INTO "anamnity#resturant" VALUES + ( 40 , 40.5 , 40.7, 'restuarant nr 40'); +INSERT INTO "anamnity#resturant" VALUES + ( 41 , 41.5 , 41.7, 'restuarant nr 41'); +INSERT INTO "anamnity#resturant" VALUES + ( 42 , 42.5 , 42.7, 'restuarant nr 42'); +INSERT INTO "anamnity#resturant" VALUES + ( 43 , 43.5 , 43.7, 'restuarant nr 43'); +INSERT INTO "anamnity#resturant" VALUES + ( 44 , 44.5 , 44.7, 'restuarant nr 44'); +INSERT INTO "anamnity#resturant" VALUES + ( 45 , 45.5 , 45.7, 'restuarant nr 45'); +INSERT INTO "anamnity#resturant" VALUES + ( 46 , 46.5 , 46.7, 'restuarant nr 46'); +INSERT INTO "anamnity#resturant" VALUES + ( 47 , 47.5 , 47.7, 'restuarant nr 47'); +INSERT INTO "anamnity#resturant" VALUES + ( 48 , 48.5 , 48.7, 'restuarant nr 48'); +INSERT INTO "anamnity#resturant" VALUES + ( 49 , 49.5 , 49.7, 'restuarant nr 49'); +INSERT INTO "anamnity#resturant" VALUES + ( 50 , 50.5 , 50.7, 'restuarant nr 50'); +INSERT INTO "anamnity#resturant" VALUES + ( 51 , 51.5 , 51.7, 'restuarant nr 51'); +INSERT INTO "anamnity#resturant" VALUES + ( 52 , 52.5 , 52.7, 'restuarant nr 52'); +INSERT INTO "anamnity#resturant" VALUES + ( 53 , 53.5 , 53.7, 'restuarant nr 53'); +INSERT INTO "anamnity#resturant" VALUES + ( 54 , 54.5 , 54.7, 'restuarant nr 54'); +INSERT INTO "anamnity#resturant" VALUES + ( 55 , 55.5 , 55.7, 'restuarant nr 55'); +INSERT INTO "anamnity#resturant" VALUES + ( 56 , 56.5 , 56.7, 'restuarant nr 56'); +INSERT INTO "anamnity#resturant" VALUES + ( 57 , 57.5 , 57.7, 'restuarant nr 57'); +INSERT INTO "anamnity#resturant" VALUES + ( 58 , 58.5 , 58.7, 'restuarant nr 58'); +INSERT INTO "anamnity#resturant" VALUES + ( 59 , 59.5 , 59.7, 'restuarant nr 59'); +INSERT INTO "anamnity#resturant" VALUES + ( 60 , 60.5 , 60.7, 'restuarant nr 60'); +INSERT INTO "anamnity#resturant" VALUES + ( 61 , 61.5 , 61.7, 'restuarant nr 61'); +INSERT INTO "anamnity#resturant" VALUES + ( 62 , 62.5 , 62.7, 'restuarant nr 62'); +INSERT INTO "anamnity#resturant" VALUES + ( 63 , 63.5 , 63.7, 'restuarant nr 63'); +INSERT INTO "anamnity#resturant" VALUES + ( 64 , 64.5 , 64.7, 'restuarant nr 64'); +INSERT INTO "anamnity#resturant" VALUES + ( 65 , 65.5 , 65.7, 'restuarant nr 65'); +INSERT INTO "anamnity#resturant" VALUES + ( 66 , 66.5 , 66.7, 'restuarant nr 66'); +INSERT INTO "anamnity#resturant" VALUES + ( 67 , 67.5 , 67.7, 'restuarant nr 67'); +INSERT INTO "anamnity#resturant" VALUES + ( 68 , 68.5 , 68.7, 'restuarant nr 68'); +INSERT INTO "anamnity#resturant" VALUES + ( 69 , 69.5 , 69.7, 'restuarant nr 69'); +INSERT INTO "anamnity#resturant" VALUES + ( 70 , 70.5 , 70.7, 'restuarant nr 70'); +INSERT INTO "anamnity#resturant" VALUES + ( 71 , 71.5 , 71.7, 'restuarant nr 71'); +INSERT INTO "anamnity#resturant" VALUES + ( 72 , 72.5 , 72.7, 'restuarant nr 72'); +INSERT INTO "anamnity#resturant" VALUES + ( 73 , 73.5 , 73.7, 'restuarant nr 73'); +INSERT INTO "anamnity#resturant" VALUES + ( 74 , 74.5 , 74.7, 'restuarant nr 74'); +INSERT INTO "anamnity#resturant" VALUES + ( 75 , 75.5 , 75.7, 'restuarant nr 75'); +INSERT INTO "anamnity#resturant" VALUES + ( 76 , 76.5 , 76.7, 'restuarant nr 76'); +INSERT INTO "anamnity#resturant" VALUES + ( 77 , 77.5 , 77.7, 'restuarant nr 77'); +INSERT INTO "anamnity#resturant" VALUES + ( 78 , 78.5 , 78.7, 'restuarant nr 78'); +INSERT INTO "anamnity#resturant" VALUES + ( 79 , 79.5 , 79.7, 'restuarant nr 79'); +INSERT INTO "anamnity#resturant" VALUES + ( 80 , 80.5 , 80.7, 'restuarant nr 80'); +INSERT INTO "anamnity#resturant" VALUES + ( 81 , 81.5 , 81.7, 'restuarant nr 81'); +INSERT INTO "anamnity#resturant" VALUES + ( 82 , 82.5 , 82.7, 'restuarant nr 82'); +INSERT INTO "anamnity#resturant" VALUES + ( 83 , 83.5 , 83.7, 'restuarant nr 83'); +INSERT INTO "anamnity#resturant" VALUES + ( 84 , 84.5 , 84.7, 'restuarant nr 84'); +INSERT INTO "anamnity#resturant" VALUES + ( 85 , 85.5 , 85.7, 'restuarant nr 85'); +INSERT INTO "anamnity#resturant" VALUES + ( 86 , 86.5 , 86.7, 'restuarant nr 86'); +INSERT INTO "anamnity#resturant" VALUES + ( 87 , 87.5 , 87.7, 'restuarant nr 87'); +INSERT INTO "anamnity#resturant" VALUES + ( 88 , 88.5 , 88.7, 'restuarant nr 88'); +INSERT INTO "anamnity#resturant" VALUES + ( 89 , 89.5 , 89.7, 'restuarant nr 89'); +INSERT INTO "anamnity#resturant" VALUES + ( 90 , 90.5 , 90.7, 'restuarant nr 90'); +INSERT INTO "anamnity#resturant" VALUES + ( 91 , 91.5 , 91.7, 'restuarant nr 91'); +INSERT INTO "anamnity#resturant" VALUES + ( 92 , 92.5 , 92.7, 'restuarant nr 92'); +INSERT INTO "anamnity#resturant" VALUES + ( 93 , 93.5 , 93.7, 'restuarant nr 93'); +INSERT INTO "anamnity#resturant" VALUES + ( 94 , 94.5 , 94.7, 'restuarant nr 94'); +INSERT INTO "anamnity#resturant" VALUES + ( 95 , 95.5 , 95.7, 'restuarant nr 95'); +INSERT INTO "anamnity#resturant" VALUES + ( 96 , 96.5 , 96.7, 'restuarant nr 96'); +INSERT INTO "anamnity#resturant" VALUES + ( 97 , 97.5 , 97.7, 'restuarant nr 97'); +INSERT INTO "anamnity#resturant" VALUES + ( 98 , 98.5 , 98.7, 'restuarant nr 98'); +INSERT INTO "anamnity#resturant" VALUES + ( 99 , 99.5 , 99.7, 'restuarant nr 99'); +INSERT INTO "anamnity#resturant" VALUES + ( 100 , 100.5 , 100.7, 'restuarant nr 100'); -- cgit v1.2.3 From 7d9e6e0d1bd45bedc030a287330c50cde7769f56 Mon Sep 17 00:00:00 2001 From: Philipp Borgers Date: Thu, 13 Jan 2011 01:49:48 +0100 Subject: fuck you regex... database request possible. we have to learn regex!!! --- src/nodejs/no1.js | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 75 insertions(+), 7 deletions(-) diff --git a/src/nodejs/no1.js b/src/nodejs/no1.js index feb3dfb..1a250be 100644 --- a/src/nodejs/no1.js +++ b/src/nodejs/no1.js @@ -1,17 +1,85 @@ + var clutch = require('clutch'); +var pg = require('pg') + +var connectionString = "pg://user:password@host/database"; + + +function createNodeBboxQuery(key, value, left, bottom, right, top) { + return "SELECT * from nodes WHERE (tags @> '\"" + key + + "\"=>\"" + value + "\"'" + + " AND POINT(geom) @ polygon(box('(" + left + + "," + bottom +")'::point,'(" + + + right + "," + top + ")'::point)));"; +} + + + +function nodeWorldHandler(req, res, key, value) { + + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end(' key:' +key +' value:'+value+'\n'); +} +function nodeBboxHandler(req, res, key, value, left, bottom, right, top) { + pg.connect(connectionString, function(err,client) { + + if (err) { + console.log(err); + } + else { + console.log(createNodeBboxQuery(key, value, left, bottom, right, top)); + /*client.query(createNodeBboxQuery(key, value, left, bottom, right, top), function(err,result) { + + if (err) { + console.log(err); + } + else { + console.log(result.rows); + for(row in result.rows.length) { + console.log(row); + } + } + });*/ + } + + + + }); + + + + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end( 'bbox: '+ left + bottom + right + top + ' key:' +key +' value:'+value+'!\n'); +} + +function wayWorldHandler(req, res, key, value) { + + res.writeHead(200, {'Content-Type': 'text/plain'}); + res.end(' key:' +key +' value:'+value+'!\n'); +} +function wayBboxHandler(req, res, key, value, bbox, left, bottom, right, top) { +} -function helloSomeone(req, res, name,bbox, key, value) { +function relationWorldHandler(req, res, key, value) { + res.writeHead(200, {'Content-Type': 'text/plain'}); - res.end('obj:'+name+ ' bbox: '+ bbox + ' key:' +key +' value:'+value+'!\n'); + res.end(' key:' +key +' value:'+value+'!\n'); } +function relationBboxHandler(req, res, key, value, left, bottom, right, top) { -function helloWorld(req, res) { - helloSomeone(req, res, 'World'); } -myRoutes = clutch.route404([['GET /hello/(\\w+)(\\[bbox=(\\d,\\d,\\d,\\d)\\])*\\[(\\w+)=(\\w+)\\]$', helloSomeone], - ['GET /hello/$', helloWorld]]); +myRoutes = clutch.route404([ + //['GET /api/(\\w+)(\\[bbox=(\\d,\\d,\\d,\\d)\\])*\\[(\\w+)=(\\w+)\\]$', helloSomeone], + ['GET /api/node\\[(\\w+)=(\\w+)\\]$',nodeWorldHandler], + ['GET /api/node\\[(\\w+)=(\\w+)\\]\\[bbox=(\\d+(\\.\\d+)?),(\\d+),(\\d+),(\\d+)\\]$',nodeBboxHandler], + ['GET /api/node\\[(\\w+)=(\\w+)\\]\\[bbox=(\\d+\\.\\d+),(\\d+),(\\d+),(\\d+)\\]$',nodeBboxHandler], + ['GET /api/way\\[(\\w+)=(\\w+)\\]$',wayWorldHandler], + ['GET /api/way\\[(\\w+)=(\\w+)\\]\\[bbox=(\\d),(\\d),(\\d),(\\d)\\]$',wayBboxHandler], + ['GET /api/relation\\[(\\w+)=(\\w+)\\]$',relationWorldHandler], + ['GET /api/relation\\[(\\w+)=(\\w+)\\](\\[bbox=(\\d),(\\d),(\\d),(\\d)\\])$',relationBboxHandler], + ]); var http = require('http'); -http.createServer(myRoutes).listen(3000, '127.0.0.1'); +http.createServer(myRoutes).listen(8080, 'localhost'); -- cgit v1.2.3 From 73990eee3cd27767800b5713b378d552cdbe6276 Mon Sep 17 00:00:00 2001 From: Philipp Borgers Date: Thu, 13 Jan 2011 19:32:17 +0100 Subject: fight against regex succesful, fixed database request, added xmlbuilder, return xml --- src/nodejs/no1.js | 61 ++++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 49 insertions(+), 12 deletions(-) diff --git a/src/nodejs/no1.js b/src/nodejs/no1.js index 1a250be..8eb86d7 100644 --- a/src/nodejs/no1.js +++ b/src/nodejs/no1.js @@ -1,16 +1,22 @@ var clutch = require('clutch'); var pg = require('pg') +var builder = require('xmlbuilder') var connectionString = "pg://user:password@host/database"; function createNodeBboxQuery(key, value, left, bottom, right, top) { - return "SELECT * from nodes WHERE (tags @> '\"" + key + /* + * return "SELECT * from nodes WHERE (tags @> '\"" + key + "\"=>\"" + value + "\"'" + " AND POINT(geom) @ polygon(box('(" + left + "," + bottom +")'::point,'(" + + right + "," + top + ")'::point)));"; + */ + + return "SELECT id,tstamp,version,changeset_id, X(geom) as lat, Y(geom) as lon FROM nodes WHERE (tags @> hstore('" + key + "','" + value + "') AND geom && st_setsrid(st_makebox2d(st_setsrid(st_makepoint(" + + left + "," + bottom + "),4326), st_setsrid(st_makepoint(" + right + "," + top + "),4326)),4326));"; } @@ -25,37 +31,67 @@ function nodeBboxHandler(req, res, key, value, left, bottom, right, top) { if (err) { console.log(err); + res.writeHead(404,{}); + res.end('\n'); } else { console.log(createNodeBboxQuery(key, value, left, bottom, right, top)); - /*client.query(createNodeBboxQuery(key, value, left, bottom, right, top), function(err,result) { + client.query(createNodeBboxQuery(key, value, left, bottom, right, top), function(err,result) { if (err) { console.log(err); + res.writeHead(404,{}); + res.end('\n'); } else { console.log(result.rows); - for(row in result.rows.length) { - console.log(row); + + res.writeHead(200, {'Content-Type': 'text/plain'}); + //res.write("lala"); + res.write(""); + for(var i=0; i"); + res.write(""); + //console.log(result.rows[i].id); + */ + var node = builder.begin('node') + .att('id', result.rows[i].id) + .att('timetamp', result.rows[i].tstamp) + .att('version', result.rows[i].version) + .att('changeset', result.rows[i].changeset_id) + .att('lat', result.rows[i].lat) + .att('lon', result.rows[i].lon); + + + + res.write(builder.toString()); + } + res.write(""); + res.end(); } - });*/ + }); } }); + + //console.log(createNodeBboxQuery(key, value, left, bottom, right, top)); - - - res.writeHead(200, {'Content-Type': 'text/plain'}); - res.end( 'bbox: '+ left + bottom + right + top + ' key:' +key +' value:'+value+'!\n'); + //res.writeHead(200, {'Content-Type': 'text/plain'}); + //res.end( 'bbox: '+ left + bottom + right + top + ' key:' +key +' value:'+value+'!\n'); } function wayWorldHandler(req, res, key, value) { res.writeHead(200, {'Content-Type': 'text/plain'}); - res.end(' key:' +key +' value:'+value+'!\n'); + } function wayBboxHandler(req, res, key, value, bbox, left, bottom, right, top) { } @@ -72,8 +108,9 @@ function relationBboxHandler(req, res, key, value, left, bottom, right, top) { myRoutes = clutch.route404([ //['GET /api/(\\w+)(\\[bbox=(\\d,\\d,\\d,\\d)\\])*\\[(\\w+)=(\\w+)\\]$', helloSomeone], ['GET /api/node\\[(\\w+)=(\\w+)\\]$',nodeWorldHandler], - ['GET /api/node\\[(\\w+)=(\\w+)\\]\\[bbox=(\\d+(\\.\\d+)?),(\\d+),(\\d+),(\\d+)\\]$',nodeBboxHandler], - ['GET /api/node\\[(\\w+)=(\\w+)\\]\\[bbox=(\\d+\\.\\d+),(\\d+),(\\d+),(\\d+)\\]$',nodeBboxHandler], + //['GET /api/node\\[(\\w+)=(\\w+)\\]\\[bbox=(\\d+(\\.\\d+)?),(\\d+),(\\d+),(\\d+)\\]$',nodeBboxHandler], + ['GET /api/node\\[(\\w+)=(\\w+)\\]\\[bbox=(\\d+(?:\\.\\d+)?),(\\d+(?:\\.\\d+)?),(\\d+(?:\\.\\d+)?),(\\d+(?:\\.\\d+)?)\\]$',nodeBboxHandler], + //['GET /api/node\\[(\\w+)=(\\w+)\\]\\[bbox=(\\d+\\.\\d+),(\\d+),(\\d+),(\\d+)\\]$',nodeBboxHandler], ['GET /api/way\\[(\\w+)=(\\w+)\\]$',wayWorldHandler], ['GET /api/way\\[(\\w+)=(\\w+)\\]\\[bbox=(\\d),(\\d),(\\d),(\\d)\\]$',wayBboxHandler], ['GET /api/relation\\[(\\w+)=(\\w+)\\]$',relationWorldHandler], -- cgit v1.2.3 From 29e49724d6ea4408bd94dbe0f90ac298a813b338 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 21 Jan 2011 15:38:46 +0100 Subject: removed old files --- src/nodejs/start.js | 107 ---------------------------------------------------- 1 file changed, 107 deletions(-) delete mode 100644 src/nodejs/start.js diff --git a/src/nodejs/start.js b/src/nodejs/start.js deleted file mode 100644 index 52c0748..0000000 --- a/src/nodejs/start.js +++ /dev/null @@ -1,107 +0,0 @@ -// imports -var http = require('http'), - querystring = require('querystring'), - pg = require('pg'), - url = require('url'), - 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"); - } - }); - } - }); -} - - -function createQuery(tag,bbox){ - // FIXME: validate - var table = tag[0] + "#" + tag[1]; - var filter = ""; - - // input validation - for(i=0;i " + bbox[2] + " AND latitude < " + bbox[3]; - } - return "SELECT * FROM \"" + table + "\" " + filter + ";"; -} - - -RegExp.escape= function(s) { - return s.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&') -}; - - -var PATH_PREFIX = '/api/'; -var base_url_re = new RegExp('^' + RegExp.escape(PATH_PREFIX) + - '(node|way|relation|\\*)(.*)$') -var filter_re = /\[(\w+=[^\]]+)\]/g; - - -http.createServer(function (req, res) { - - if (!base_url_re.test(req.url)) { - res.writeHead(404, {'Content-Type': 'text/plain; charset=utf8'}); - res.end('Not Found\n'); - } - 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; - - for(i=0;i Date: Fri, 21 Jan 2011 15:57:13 +0100 Subject: added log4js --- src/nodejs/no1.js | 20 ++++++++++++++------ src/nodejs/package.json | 19 ++++++++++--------- 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/nodejs/no1.js b/src/nodejs/no1.js index 7fcdf93..f55f736 100644 --- a/src/nodejs/no1.js +++ b/src/nodejs/no1.js @@ -2,26 +2,34 @@ var clutch = require('clutch'); var pg = require('pg'); var builder = require('xmlbuilder'); -var config = require('./config.json'); + + // load config +var config = require('./config.json'); process.argv.forEach( function (val,index, array){ if(val=="-c"){ path = array[index+1]; - console.log(path[0]); if( path[0] != '/'){ path = __dirname + '/' + path; } config = require(path); } }); - var connectionString = config['connectionString']; -console.log("server starting..."); -console.log("Connection String: " + connectionString); + + +//set up logger +var log4js = require('log4js')(); //note the need to call the function +//log4js.addAppender(log4js.fileAppender('osm-xapi.log'), 'cheese'); + +var logger = log4js.getLogger('global'); +logger.setLevel('ALL'); + +logger.info("server starting..."); function toISO8601(date) { //2007-03-31T00:09:22+01:00 @@ -268,4 +276,4 @@ myRoutes = clutch.route404([ var http = require('http'); http.createServer(myRoutes).listen(config.port, config.host); -console.log("Started server at " + config.host + ":" + config.port ); +logger.info("Started server at " + config.host + ":" + config.port ); diff --git a/src/nodejs/package.json b/src/nodejs/package.json index cbe341f..3ff8b8b 100644 --- a/src/nodejs/package.json +++ b/src/nodejs/package.json @@ -1,11 +1,12 @@ -{ "name" : "xapi-osm-spline" -, "version" : "0.0.1" -, "description" : "An osm xapi implementation" -, "autor" : "osm@spline (http://osm.spline.de)" -, "files" : ["."] -, "dependencies" : - { "pg" : "*" - , "clutch" : "*" - , "xmlbuilder" : "*" +{ 'name' : 'xapi-osm-spline' +, 'version' : '0.0.1' +, 'description' : 'An osm xapi implementation' +, 'autor' : 'osm@spline (http://osm.spline.de)' +, 'files' : ['.'] +, 'dependencies' : + { 'pg' : '*' + , 'clutch' : '*' + , 'xmlbuilder' : '*' + , 'log4js' : '*' } } -- cgit v1.2.3 From f7857666f01591e50c9ef377651710da3455eef4 Mon Sep 17 00:00:00 2001 From: Alexander Sulfrian Date: Fri, 21 Jan 2011 15:58:36 +0100 Subject: removed trailing whitespaces --- src/nodejs/no1.js | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/nodejs/no1.js b/src/nodejs/no1.js index 3b3f8a0..b66940b 100644 --- a/src/nodejs/no1.js +++ b/src/nodejs/no1.js @@ -47,12 +47,12 @@ function toISO8601(date) { ].join(''); } function createWayBboxQuery(key, value, left, bottom, right, top) { - return "SELECT id,tstamp,version,changeset_id, nodes, user_id, hstore_to_array(tags) as tags FROM ways WHERE (tags @> hstore('" + key + "','" + value + "') AND linestring && st_setsrid(st_makebox2d(st_setsrid(st_makepoint(" + + return "SELECT id,tstamp,version,changeset_id, nodes, user_id, hstore_to_array(tags) as tags FROM ways WHERE (tags @> hstore('" + key + "','" + value + "') AND linestring && st_setsrid(st_makebox2d(st_setsrid(st_makepoint(" + left + "," + bottom + "),4326), st_setsrid(st_makepoint(" + right + "," + top + "),4326)),4326));"; } function createNodeBboxQuery(key, value, left, bottom, right, top) { - return "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('" + key + "','" + value + "') AND geom && st_setsrid(st_makebox2d(st_setsrid(st_makepoint(" + + return "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('" + key + "','" + value + "') AND geom && st_setsrid(st_makebox2d(st_setsrid(st_makepoint(" + left + "," + bottom + "),4326), st_setsrid(st_makepoint(" + right + "," + top + "),4326)),4326));"; } @@ -71,14 +71,14 @@ function nodeBboxHandler(req, res, key, value, left, bottom, right, top) { //console.log(createNodeBboxQuery(key, value, left, bottom, right, top)); var success = false; var query = client.query(createNodeBboxQuery(key, value, left, bottom, right, top)); - + query.on('error', function(err) { - + console.log(err); res.writeHead(404,{}); res.end('\n'); }); - + query.on('end', function() { //console.log("end event\n"); if(success) { @@ -92,17 +92,17 @@ function nodeBboxHandler(req, res, key, value, left, bottom, right, top) { //perhaps write 404? is error also raised? } }); - + query.on('row', function(row) { - + if(!success) { success = true; res.writeHead(200, {'Content-Type': 'text/plain'}); res.write(""); } - + console.log(row); - + var node = builder.begin('node') .att('id', row.id) .att('timetamp', toISO8601(row.tstamp)) @@ -116,7 +116,7 @@ function nodeBboxHandler(req, res, key, value, left, bottom, right, top) { node.ele('tag') .att('k',escape(temp[x])) .att('v',escape(temp[x+1])); - } + } res.write(builder.toString({ pretty: true })); }); @@ -150,13 +150,13 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) { var success = false; //console.log(createWayBboxQuery(key, value, left, bottom, right, top)); var query = client.query(createWayBboxQuery(key, value, left, bottom, right, top)); - + query.on('error', function(err) { console.log(err); res.writeHead(404,{}); res.end(); }); - + query.on('end', function() { if(success) { if(count == 0) { @@ -172,7 +172,7 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) { //perhaps write 404? } }); - + query.on('row', function(row) { if(!success) { success = true; @@ -208,10 +208,10 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) { } res.write(builder.toString({pretty:'true'})); }); - + //console.log(createNodesForWayQuery(row.nodes)); } - + var way = builder.begin('way') .att('id', row.id) .att('timetamp', toISO8601(row.tstamp)) @@ -224,19 +224,19 @@ function wayBboxHandler(req, res, key, value, left, bottom, right, top) { .att('k',escape(temp[x])) .att('v',escape(temp[x+1])); } - + var temp = row.nodes.replace("{","").replace("}","").split(","); for(var x=0;x