Skip to content

Commit f9749a8

Browse files
authored
Merge pull request #47 from WorldBank-Transport/develop
Release ram-analysis v0.3.0
2 parents e1f8077 + adcbb14 commit f9749a8

File tree

6 files changed

+298
-268
lines changed

6 files changed

+298
-268
lines changed

ram-analysis/app/calculate-eta/index.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,13 @@ process.on('message', function (e) {
3131
try {
3232
init(e);
3333
} catch (err) {
34-
process.send({type: 'error', data: err.message, stack: err.stack});
35-
throw err;
34+
process.send({
35+
type: 'error',
36+
data: err.message,
37+
stack: err.stack,
38+
details: err.details
39+
});
40+
process.exit(1);
3641
}
3742
});
3843

ram-analysis/app/calculate-eta/tasks.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,18 @@ export function createProcessAreaTask (workArea, poiByType, origins, osrm, maxTi
7171
let minPoi = Math.min(totalPoi, 4);
7272
process.send({type: 'debug', data: `Total poi of type ${key}: ${totalPoi}`, id: id});
7373
do {
74-
poiSet = poisInBuffer(workArea, poiByType[key], time, speed);
74+
// There may be situation where no points are found in the buffer even
75+
// though it encompasses the whole world. In this case it throw an error
76+
// Add some details to the error.
77+
try {
78+
poiSet = poisInBuffer(workArea, poiByType[key], time, speed);
79+
} catch (err) {
80+
if (err.message === 'World buffer overflow') {
81+
err.details = `There are a total of ${totalPoi} pois of type "${key}" but none were found in the full world buffer.
82+
This may mean that the poi coordinates system is not in the EPSG:4326 (WGS84) projection.`;
83+
}
84+
throw err;
85+
}
7586
time += 900;
7687
} while (poiSet.features.length < minPoi);
7788
process.send({type: 'debug', data: `Using ${poiSet.features.length} pois. Time: ${time - 900}`, id: id});

ram-analysis/app/calculate-eta/utils.js

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import { featureCollection } from '@turf/helpers';
33
import within from '@turf/within';
44
import buffer from '@turf/buffer';
5+
import bbox from '@turf/bbox';
56

67
/**
78
* Create an array filled with a range of numbers starting at {start} and ending
@@ -13,7 +14,7 @@ import buffer from '@turf/buffer';
1314
*/
1415
export function range (start, end) {
1516
let res = [];
16-
for (var i = start; i < end; i++) { res.push(i); }
17+
for (let i = start; i < end; i++) { res.push(i); }
1718
return res;
1819
}
1920

@@ -25,7 +26,7 @@ export function range (start, end) {
2526
* Origins in the given area
2627
*/
2728
export function originsInRegion (area, origins) {
28-
let result = within(origins, featureCollection([area]));
29+
const result = within(origins, featureCollection([area]));
2930
return result;
3031
}
3132

@@ -37,12 +38,21 @@ export function originsInRegion (area, origins) {
3738
* @param {number} time Value in seconds
3839
* @param {number} speed Value in km/h
3940
* @param {FeatureCollection} poi Points of Interest
41+
*
42+
* @throws RangeError
43+
*
4044
* @return {FeatureCollection}
4145
* The Points of Interest in the buffered area.
4246
*/
4347
export function poisInBuffer (area, poi, time, speed) {
44-
let distance = (time / 3600) * speed;
45-
let bufferedArea = buffer(area, distance, 'kilometers');
46-
var result = within(poi, featureCollection([bufferedArea]));
48+
const distance = (time / 3600) * speed;
49+
const bufferedArea = buffer(area, distance, 'kilometers');
50+
const [e, s, w, n] = bbox(bufferedArea);
51+
52+
if (e < -180 && w > 180 && s < -85 && n > 85) {
53+
throw new RangeError('World buffer overflow');
54+
}
55+
56+
const result = within(poi, featureCollection([bufferedArea]));
4757
return result;
4858
}

0 commit comments

Comments
 (0)