Created
April 5, 2012 15:50
-
-
Save springmeyer/2312067 to your computer and use it in GitHub Desktop.
convert point coordinate pair into wkb in javascript/node.js and insert into sqlite db for rendering in TileMill
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var sqlite3 = require('sqlite3') | |
var db = new sqlite3.Database('test.db'); | |
var make_wkb_point = function(x,y) { | |
var byteorder = 1; | |
var len = 1 + 4 + 8*2 ; | |
var wkb = new Buffer(len); | |
wkb.fill(0); | |
wkb[0] = byteorder; | |
wkb.writeUInt8(1,1) | |
wkb.writeDoubleLE(x,1+4) | |
wkb.writeDoubleLE(y,1+4+8) | |
return wkb; | |
} | |
var add_point = function(x,y,name) { | |
var stmt = db.prepare("INSERT into \"point_table\" (id,geometry,name) values (?,?,?)"); | |
stmt.run(null,make_wkb_point(x,y),name); | |
stmt.finalize(); | |
} | |
db.serialize(function() { | |
db.run("CREATE TABLE IF NOT EXISTS \"point_table\" (id INTEGER PRIMARY KEY AUTOINCREMENT, geometry BLOB, \"name\" varchar)"); | |
add_point(-122,48,'Seattle'); | |
add_point(-77,39,'DC'); | |
add_point(0,51,'London'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
/cc @Vertice