mapbox / tippecanoe

Build vector tilesets from large collections of GeoJSON features.
BSD 2-Clause "Simplified" License
2.72k stars 432 forks source link

Tippecanoe will be perfect to have a nodejs bindings #203

Open jingsam opened 8 years ago

e-n-f commented 8 years ago

This might be possible, although Tippecanoe is structured to operate as a program, not as a library. How are you thinking you would like to be able to use it? Give it JSON text and get back an mbtiles file, or are you wanting it to work on JSON objects and give access to individual tiles?

jingsam commented 8 years ago

I am currently working on a web mapping platform built with Express. A nodejs bindings would be great so that I could integrate Tippecanoe in our platform.

e-n-f commented 8 years ago

If you are serving tiles dynamically, you may be better off using https://github.com/mapbox/geojson-vt. Hard to say without knowing more about what you are doing.

anandthakker commented 8 years ago

This might be possible, although Tippecanoe is structured to operate as a program, not as a library. How are you thinking you would like to be able to use it?

@ericfischer One thought I've had before is that if Tippecanoe exposed a limited library interface for data input, maybe that would afford a way to skip the geojson parsing step, which I remember you saying is one of the main bottlenecks?

e-n-f commented 8 years ago

@anandthakker That would make sense. As it is the generation of the internal representation of geometries is highly tangled up with GeoJSON parsing and with the notion that there are a fixed number of parser threads, but it would be great to get that all straightened out and cleaned up.

clouddie commented 8 years ago

@ericfischer Hi, saw your comment about using https://github.com/mapbox/geojson-vt, but it can't export vector tiles to MBTiles. From what I gather, only tippecanoe can do this (outside of using a desktop like software such as MapBox Studio), am I mistaken ?

e-n-f commented 8 years ago

@clouddie I think https://github.com/mapbox/vt-pbf should let you create vector tiles from JavaScript.

clouddie commented 8 years ago

@ericfischer I agree, but it does not create mbtiles, isn't it ?

e-n-f commented 8 years ago

@clouddie It doesn't, but you could use https://github.com/mapbox/node-sqlite3 to create an mbtiles file and write the tiles to it.

Most of what tippecanoe does with mbtiles is mostly just sqlite inserts of tiles into the database. The only messy part is making the vector_layers row in the metadata table, but that should be easier from JavaScript than it is from C++ since you can make it as a JavaScript object and stringify it instead of having to build the structure by hand. I think you should just be able to copy most of the SQL from https://github.com/mapbox/tippecanoe/blob/master/mbtiles.cpp to do exactly the same thing Tippecanoe does, but from JavaScript instead of C++.

clouddie commented 8 years ago

@ericfischer Thanks for the tip, I am usually so terrified by C++ that I don't dare look at source code (hence my comment on node bindings). I will give it a go !

SeanChristopherConway commented 8 years ago

@ericfischer @jingsam You could just spawn a child process and manipulate the stdout for feedback etc. Assuming you have tippecanoe installed you can simply call it in a node script as such:

`var exec = require('child_process') .exec, output = "test.mbtiles", input = "test.geojson", layername ='test';

execute('tippecanoe -o '+output+' -l '+layername+' '+input+'');

function execute(command) {

var child = exec(command); child.stdout.on('data', function (data) { console.log('stdout: ' + data); //cb(data); }); child.stderr.on('data', function (data) { //console.log('stdout: ' + data); }); child.on('close', function (code) { console.log('closing code: ' + code); });

}`

andrewharvey commented 7 years ago

This would help with wrapping tippecanoe behind a node powered web app. Like http://ogre.adc4gis.com but for tippecanoe. Sure we can spawn a child process but proper bindings would make this nicer.

e-n-f commented 7 years ago

Currently tippecanoe's error handling is far too reliant on exiting when an error is encountered to make it viable to use as a library instead of in its own process. Maybe someday I can get that straightened out but probably not any time soon.