Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
test("match lines 1", async (t:any) => {
// test polygon (dc area)
const content = fs.readFileSync('test/geojson/sf_centerlines.sample.geojson');
var linesIn:turfHelpers.FeatureCollection = JSON.parse(content.toLocaleString());
var cleanedLines = new CleanedLines(linesIn);
var lines:turfHelpers.FeatureCollection = turfHelpers.featureCollection(cleanedLines.clean);
var params = new TilePathParams();
params.source = 'osm/planet-180430';
params.tileHierarchy = 6;
//test matcher point candidates
var matcher = new Graph(envelope(lines), params);
await matcher.buildGraph();
var matchedLines = turfHelpers.featureCollection([]);
for(var line of lines.features) {
var pathCandidate = await matcher.matchGeom(line);
matchedLines.features.push(pathCandidate.matchedPath);
}
const expected_1a_file = 'test/geojson/sf_centerlines.sample.out.geojson';
if(BUILD_TEST_OUPUT) {
var expected_1a_out:string = JSON.stringify(matchedLines);
fs.writeFileSync(expected_1a_file, expected_1a_out);
}
const expected_1a_in = fs.readFileSync(expected_1a_file);
const expected_1a:{} = JSON.parse(expected_1a_in.toLocaleString());
test("sharedstreets -- graph test", async (t:any) => {
var params = new TilePathParams();
params.source = 'osm/planet-181224';
params.tileHierarchy = 7;
// test polygon (dc area)
const content = fs.readFileSync('test/geojson/test_route.geojson');
var lineIn:turfHelpers.FeatureCollection = JSON.parse(content.toLocaleString());
var graph = new Graph(envelope(lineIn), params);
await graph.buildGraph();
t.equal(graph.id, 'd626d5b0-0dec-3e6f-97ff-d9712228a282');
var results = await graph.matchGeom(lineIn.features[0]);
lineIn.features[0].geometry.coordinates.reverse();
var results2 = await graph.matchGeom(lineIn.features[0]);
t.end();
});
async function getMatcher() {
// TODO - move TilePathParams into here
// const params = new TilePathParams();
const params: any = {};
// params.source = flags['tile-source'];
params.source = "osm/planet-181224";
// params.tileHierarchy = flags['tile-hierarchy']
params.tileHierarchy = 6;
const extent = envelope(bboxPolygon(extentFromEnv));
const graphs = new sharedstreets.Graph(extent, params, 'car_all');
await graphs.buildGraph();
// console.log("graph built");
graphs.searchRadius = 25;
graphs.snapIntersections = true;
return graphs;
}
const {
id,
poi: poiByType,
villages,
osrmFile,
adminArea,
gridSize,
maxTime,
maxSpeed
} = e;
const osrm = new OSRM(osrmFile);
process.send({type: 'status', data: 'srv_loaded_files', id: id});
// Split the input region in squares for parallelisation.
let box = envelope(adminArea);
let extent = [box.geometry.coordinates[0][0][0], box.geometry.coordinates[0][0][1], box.geometry.coordinates[0][2][0], box.geometry.coordinates[0][2][1]];
let squares = squareGrid(extent, gridSize || 30, 'kilometers').features;
process.send({type: 'squarecount', data: squares.length, id: id});
// Create a task for each square to be run below.
var squareTasks = squares.map(square => {
// Clip the square with the input geometry. In this way we work with a
// smaller area..
let workArea = intersect(adminArea, square);
return createProcessAreaTask(workArea, poiByType, villages, osrm, maxTime, maxSpeed, id);
});
async.parallelLimit(squareTasks, config.cpus, (err, allSquaresRes) => {
if (err) {
throw err;
}
async function getMatcher() {
var params = new TilePathParams();
// params.source = flags['tile-source'];
params.source = "osm/planet-181224";
// params.tileHierarchy = flags['tile-hierarchy']
params.tileHierarchy = 6;
const extent = envelope(extentFile);
const matcher = new Graph(extent, params, GraphMode.CAR_ALL);
await matcher.buildGraph();
// console.log("graph built");
matcher.searchRadius = 25;
matcher.snapIntersections = true;
return matcher;
}
async function matchLines(outFile, params, lines, flags) {
var cleanedlines = new CleanedLines(lines);
console.log(chalk.bold.keyword('green')(' ✨ Matching ' + cleanedlines.clean.length + ' lines...'));
var extent = envelope(lines);
var matcher = new Graph(extent, params);
var matchedLines:turfHelpers.Feature[] = [];
var unmatchedLines:turfHelpers.Feature[] = [];
for(var line of cleanedlines.clean) {
var bearing:number =null;
var matches1 = await matcher.match(line);
line.geometry.coordinates.reverse()
var matches2 = await matcher.match(line);
var bestMatch = null;
if(matches1 && matches2 ) {
export function envelopeBufferFromPoint(point, radius):turfHelpers.Feature {
var nwPoint = destination(point, radius, 315, {'units':'meters'});
var sePoint = destination(point, radius, 135, {'units':'meters'});
return envelope(turfHelpers.featureCollection([nwPoint, sePoint]));
}
getEnvelope() {
if (this.envelope)
return this.envelope;
return (this.envelope = envelope(this.toPolygon()));
}