Merge branch 'master' into subtrees-protozero-vtzero
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
/*********************************
|
||||
* Takes an XML `.osm` file and converts it into a cucumber scenario definition like
|
||||
* Given the node locations
|
||||
* | node | lon | lat |
|
||||
* .....
|
||||
* Given the ways
|
||||
* | nodes | tag1 | tag2 | tag3 |
|
||||
* .....
|
||||
*
|
||||
* Note that cucumber tests are limited to 26 nodes (labelled a-z), so
|
||||
* you'll need to use pretty small OSM extracts to get this to work.
|
||||
*****************************************/
|
||||
var fs = require('fs');
|
||||
var parseString = require('xml2js').parseString;
|
||||
|
||||
var data = fs.readFileSync('filename.osm', 'utf8');
|
||||
|
||||
const items = parseString(data, (err, result) => {
|
||||
var idmap = {};
|
||||
|
||||
console.log('Given the node locations');
|
||||
console.log(' | node | lon | lat |');
|
||||
result.osm.node.filter(n => !n.$.action || n.$.action !== 'delete').forEach(i => {
|
||||
var code = String.fromCharCode(97 + Object.keys(idmap).length)
|
||||
idmap[i.$.id] = code;
|
||||
console.log(` | ${code} | ${i.$.lon} | ${i.$.lat} |`);
|
||||
});
|
||||
|
||||
var allkeys = {};
|
||||
var waytags = {};
|
||||
|
||||
result.osm.way.filter(n => !n.$.action || n.$.action !== 'delete').forEach(w => {
|
||||
if (!waytags[w.$.id]) waytags[w.$.id] = {};
|
||||
w.tag.forEach(t => { allkeys[t.$.k] = t.$.v; waytags[w.$.id][t.$.k] = t.$.v; });
|
||||
});
|
||||
|
||||
console.log('And the ways');
|
||||
console.log(` | nodes | ${Object.keys(allkeys).join(' | ')} |`);
|
||||
|
||||
result.osm.way.filter(n => !n.$.action || n.$.action !== 'delete').forEach(w => {
|
||||
console.log(` | ${w.nd.map(n => idmap[n.$.ref]).join('')} | ${Object.keys(allkeys).map(k => waytags[w.$.id][k] || '').join(' | ')} |`);
|
||||
});
|
||||
});
|
||||
+43
-18
@@ -36,27 +36,51 @@ const run_query = (query_options, filters, callback) => {
|
||||
}).end();
|
||||
};
|
||||
|
||||
function generate_points(polygon, number) {
|
||||
function generate_points(polygon, number, coordinates_number, max_distance) {
|
||||
let query_points = [];
|
||||
while (query_points.length < number) {
|
||||
var chunk = turf
|
||||
.random('points', number, { bbox: turf.bbox(polygon)})
|
||||
.features
|
||||
.map(x => x.geometry.coordinates)
|
||||
.filter(pt => turf.inside(pt, polygon));
|
||||
query_points = query_points.concat(chunk);
|
||||
let points = [];
|
||||
|
||||
while(points.length < coordinates_number) {
|
||||
let chunk = turf
|
||||
.random('points', coordinates_number, { bbox: turf.bbox(polygon)})
|
||||
.features
|
||||
.map(x => x.geometry.coordinates)
|
||||
.filter(pt => turf.inside(pt, polygon));
|
||||
|
||||
if (max_distance > 0)
|
||||
{
|
||||
chunk.forEach(pt => {
|
||||
if (points.length == 0)
|
||||
{
|
||||
points.push(pt);
|
||||
}
|
||||
else
|
||||
{
|
||||
let distance = turf.distance(pt, points[points.length-1], 'meters');
|
||||
if (distance < max_distance)
|
||||
{
|
||||
points.push(pt);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
points = points.concat(chunk);
|
||||
}
|
||||
}
|
||||
|
||||
query_points.push(points);
|
||||
}
|
||||
return query_points.slice(0, number);
|
||||
|
||||
return query_points;
|
||||
}
|
||||
|
||||
function generate_queries(options, query_points, coordinates_number) {
|
||||
let queries = [];
|
||||
for (let chunk = 0; chunk < query_points.length; chunk += coordinates_number)
|
||||
{
|
||||
let points = query_points.slice(chunk, chunk + coordinates_number);
|
||||
let query = options.path.replace(/{}/g, x => points.pop().join(','));
|
||||
queries.push(query);
|
||||
}
|
||||
function generate_queries(options, query_points) {
|
||||
let queries = query_points.map(points => {
|
||||
return options.path.replace(/{}/g, x => points.pop().join(','));
|
||||
});
|
||||
return queries;
|
||||
}
|
||||
|
||||
@@ -80,6 +104,7 @@ const optionsList = [
|
||||
{name: 'bounding-box', alias: 'b', type: BoundingBox, defaultValue: BoundingBox('5.86442,47.2654,15.0508,55.1478'), multiple: true, description: 'queries bounding box, default "5.86442,47.2654,15.0508,55.1478"', typeLabel: '{underline west,south,east,north}'},
|
||||
{name: 'max-sockets', alias: 'm', type: Number, defaultValue: 1, description: 'how many concurrent sockets the agent can have open per origin, default 1', typeLabel: '{underline number}'},
|
||||
{name: 'number', alias: 'n', type: Number, defaultValue: 10, description: 'number of query points, default 10', typeLabel: '{underline number}'},
|
||||
{name: 'max-distance', alias: 'd', type: Number, defaultValue: -1, description: 'maximal distance between coordinates', typeLabel: '{underline number}'},
|
||||
{name: 'queries-files', alias: 'q', type: String, description: 'CSV file with queries in the first row', typeLabel: '{underline file}'},
|
||||
];
|
||||
const options = cla(optionsList);
|
||||
@@ -109,8 +134,8 @@ if (options.hasOwnProperty('queries-files')) {
|
||||
} else {
|
||||
const polygon = options['bounding-box'].map(x => x.poly).reduce((x,y) => turf.union(x, y));
|
||||
const coordinates_number = (options.path.match(/{}/g) || []).length;
|
||||
const query_points = generate_points(polygon, coordinates_number * options.number);
|
||||
queries = generate_queries(options, query_points, coordinates_number);
|
||||
const query_points = generate_points(polygon, options.number, coordinates_number, options['max-distance']);
|
||||
queries = generate_queries(options, query_points);
|
||||
}
|
||||
queries = queries.map(q => { return {hostname: options.server.hostname, port: options.server.port, path: q}; });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user