nst-guide / route-vector-tiles Goto Github PK
View Code? Open in Web Editor NEWExperimental routing using vector tiles
License: MIT License
Experimental routing using vector tiles
License: MIT License
It seems very possible.
Geojson path finder seems to work best when the input coordinate is one of the existing vertices. Not sure how to best find the closest network vertex from an arbitrary point.
I guess the simplest way is to select all the points within some precision-difference, like within +- .001 degrees for lat and lon, and then only for those points, run like turf.closest
Note that geojson path finder when you provide the precision option, makes all points in the network have not more than that precision!
Reading the tile to GeoJSON:
The key I was having trouble with, when I kept getting vector tiles with no layers, was that I was forming the request incorrectly. I need to pass gzip:true
, and encoding:null
to get the right format of buffer. Check the reading here:
https://github.com/mapbox/vt2geojson/blob/f5e6f1f5afedb5c7f9b6ef225e25207cf8a4b5fc/index.js#L61-L90
It's probably also easiest to clip the vector tile buffer the the box extents, as shown below.
x = [2759, 2760]
y = [6326, 6327]
z = 14
x = 2759
y = 6326
request_promisify = promisify(request)
var testobject
request_promisify(url, {
gzip: true,
encoding: null
}).then(x => {
testobject = x
})
typeof(testobject.body)
buffer = testobject.body
buffer[0] === 0x78 && buffer[1] === 0x9C
buffer[0] === 0x1F && buffer[1] === 0x8B
var tile = new VectorTile(new Protobuf(buffer));
tile.layers
Object.keys(tile.layers);
layer_name = 'transportation'
layers.forEach(function (layerID) {
var layer = tile.layers[layer_name];
i = 0
if (layer) {
for (var i = 0; i < layer.length; i++) {
var feature = layer.feature(i).toGeoJSON(x, y, z);
console.log(JSON.stringify(feature))
var xyzBox = sphericalMercator.bbox(args.x, args.y, args.z);
var clippedFeature = bboxClip(feature, xyzBox);
if (layers.length > 1) feature.properties.vt_layer = layerID;
collection.features.push(clippedFeature);
// collection.features.push(feature);
}
}
});
Routing:
var helpers = require("@turf/helpers");
var length = require("@turf/length").default;
var PathFinder = require("geojson-path-finder");
var combined = require("./combined.json");
var combined = require('/Users/kyle/github/mapping/vt2geojson/combined.json')
var Point = helpers.point;
// Each degree of latitude is 111km, so precision of .001 snaps vertices within 100m
var pathFinder = new PathFinder(combined, { precision: 0.00001 });
// Same line
var start = Point([-119.377431, 37.873708]);
var end = Point([-119.345603, 37.889177]);
var path = pathFinder.findPath(start, end);
console.log(JSON.stringify(helpers.lineString(path.path)));
var pathFinder = new PathFinder(combined, { precision: 0.00001 });
var start = Point([-119.35996413230896, 37.87304103829722]);
// var end = Point([-119.36515152454376, 37.872219535492945])
// var end = Point([-119.37064468860626,37.8720332139949])
var end = Point([-119.37064468860626,37.8720])
var path = pathFinder.findPath(start, end);
console.log(JSON.stringify(helpers.lineString(path.path)));
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.