Reputation: 103
I am experiencing > 2s processing time for converting a 120 MB geojson
file to protobuf
through Mapnik
Vector Tile node bindings.
On the other end serving the raw geosjon
file takes under 200 ms.
Is it normal ? If yes, what is the point of serving vector tiles over geojson
(I am viewing it with mapbox-gl-js
)?
Here is an extract of my code :
// Load GeoJson into memory
var fs = require("fs");
var content = JSON.parse(fs.readFileSync("us_counties.json"));
// Initialise Mapnik and mercator object
mapnik.register_default_fonts();
mapnik.register_default_input_plugins();
var mercator = new SphericalMercator({
size: 256
});
// Vector Tile Router
router.get('/:z/:x/:y.pbf', function(req, res) {
var bbox = mercator.bbox(
+req.params.x,
+req.params.y,
+req.params.z,
false,
'4326'
);
// Convert GEOJSON to protobuf VectorTile and Serve
var vtile = new mapnik.VectorTile(+req.params.z, +req.params.x, +req.params.y)
vtile.addGeoJSON(JSON.stringify(content), 'fixture_layer')
res.setHeader('Content-Encoding', 'deflate')
res.setHeader('Content-Type', 'application/x-protobuf')
zlib.deflate(vtile.getData(), function(err, pbf) {
res.send(pbf);
})
});
Upvotes: 2
Views: 3139
Reputation: 5525
Vector tile is NOT lossless, vector tile simplify the geometry also round the corner to tile grid intersection. So here comes problem, some of my polygon in vector tile are not correctly drawing. You must be aware of this problem, because it makes my parcels not usable since always I can easily found some parcels lines are not correctly drawing.
second vector tile only support by mapbox GL js, geojson supported by google map, openlayer, leaflet, bing map, mapquest, etc....mapbox js.
If you worry about performance of geojson, here is the solution:
on server side, use geobuf, to serialize(encode) geojson to protocol buffer binary format, it compress to 20% of original geojson size. 120MB-geojson- 20MB geobuf.
transfer 20MB geobuf from server via internet to client browser, use geobuf(javascript lib) again to decode to geojson.
In brower, render geojson directly with google map, bing map, openlayer, leaflet, etc....
This give you a lossless and quick response solution.
Upvotes: 1
Reputation: 3782
GeoJSON and vector tiles each have strengths and weaknesses as data formats for Mapbox GL.
If GeoJSON is working for you, I encourage you to use it! Just be aware of cases where your users may be unable to quickly download 120 MB.
Upvotes: 5