MCPcopy Create free account
hub / github.com/Project-OSRM/osrm-backend / generate_points

Function generate_points

scripts/osrm-runner.js:39–78  ·  view source on GitHub ↗
(polygon, number, coordinates_number, max_distance)

Source from the content-addressed store, hash-verified

37
38// Generate random coordinate points within a polygon boundary for route testing
39function generate_points(polygon, number, coordinates_number, max_distance) {
40 const query_points = [];
41 while (query_points.length < number) {
42 let points = [];
43
44 while(points.length < coordinates_number) {
45 const chunk = turf
46 .randomPoint(coordinates_number, { bbox: turf.bbox(polygon)})
47 .features
48 .map(x => x.geometry.coordinates)
49 .filter(pt => turf.booleanPointInPolygon(turf.point(pt), polygon));
50
51 if (max_distance > 0)
52 {
53 chunk.forEach(pt => {
54 if (points.length == 0)
55 {
56 points.push(pt);
57 }
58 else
59 {
60 const distance = turf.distance(pt, points[points.length-1], 'meters');
61 if (distance < max_distance)
62 {
63 points.push(pt);
64 }
65 }
66 });
67 }
68 else
69 {
70 points = points.concat(chunk);
71 }
72 }
73
74 query_points.push(points);
75 }
76
77 return query_points;
78}
79
80// Convert coordinate points into OSRM API query URLs
81function generate_queries(options, query_points) {

Callers 1

osrm-runner.jsFile · 0.85

Calls 3

pointMethod · 0.80
pushMethod · 0.80
distanceMethod · 0.45

Tested by

no test coverage detected