UNPKG

catchment-area

Version:

A utility for computing the catchment area of given source and destination points. A source may correspond to a health facility while the destinations (catchment areas) are the settlements served by the facility

10 lines 3.92 kB
parcelRequire=function(e,r,n,t){var i="function"==typeof parcelRequire&&parcelRequire,o="function"==typeof require&&require;function u(n,t){if(!r[n]){if(!e[n]){var f="function"==typeof parcelRequire&&parcelRequire;if(!t&&f)return f(n,!0);if(i)return i(n,!0);if(o&&"string"==typeof n)return o(n);var c=new Error("Cannot find module '"+n+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[n][1][r]||r};var l=r[n]=new u.Module(n);e[n][0].call(l.exports,p,l,l.exports,this)}return r[n].exports;function p(e){return u(p.resolve(e))}}u.isParcelRequire=!0,u.Module=function(e){this.id=e,this.bundle=u,this.exports={}},u.modules=e,u.cache=r,u.parent=i,u.register=function(r,n){e[r]=[function(e,r){r.exports=n},{}]};for(var f=0;f<n.length;f++)u(n[f]);if(n.length){var c=u(n[n.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=c:"function"==typeof define&&define.amd?define(function(){return c}):t&&(this[t]=c)}return u}({7:[function(require,module,exports) { "use strict";function e(e,t){return t*(e/60)}function t(e,t,n,r){return{source:n,destinations:r,drivetime:e,distance:t}}exports.__esModule=!0,exports.computeMaxDistance=e,exports.makeCatchmentArea=t; },{}],8:[function(require,module,exports) { "use strict";var e=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}},t=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var r in e)Object.hasOwnProperty.call(e,r)&&(t[r]=e[r]);return t.default=e,t};exports.__esModule=!0;var r=e(require("kdbush")),n=t(require("geokdbush")),i=t(require("ramda")),o=t(require("./util")),u=function(){function e(e,t){void 0===t&&(t=80),this.config=e,this.travelSpeed=t}return Object.defineProperty(e.prototype,"sources",{get:function(){var e=this;return this.config.sources.map(function(t){return e.config.coordinates[t]})},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"destinations",{get:function(){var e=this;return this.config.destinations.map(function(t){return e.config.coordinates[t]})},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"drivetimes",{get:function(){return this.config.drivetimes},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"speed",{get:function(){return this.travelSpeed},enumerable:!0,configurable:!0}),e.prototype.getCatchedPoints=function(e){return e.reduce(function(e,t){return e.concat(t.destinations)},[])},e.prototype.getUncatchedPoints=function(e,t){return i.differenceWith(function(e,t){var r=e[0],n=e[1],i=t[0],o=t[1];return r==i&&n==o},e,t)},e.prototype.generate=function(e,t,i,o){if(i.length<=o)return i;var u=t[0],a=t[1],s=r.default(i);return n.around(s,u,a,o,e)},e.prototype.run=function(){var e=this.sources,t=this.destinations,r=this.drivetimes;if(!e.length)throw new Error("The catchment area generator config object must contain at least one source!");for(var n=[],i=Math.floor(t.length/e.length),u=0,a=r;u<a.length;u++)for(var s=a[u],c=o.computeMaxDistance(s,this.speed),f=0,h=e;f<h.length;f++){var d=h[f],p=this.getCatchedPoints(n),l=this.getUncatchedPoints(t,p),g=this.generate(c,d,l,i);n.push(o.makeCatchmentArea(s,c,d,g))}return n},e}();exports.CatchmentAreaGenerator=u; },{"./util":7}],4:[function(require,module,exports) { "use strict";var r=this&&this.__importStar||function(r){if(r&&r.__esModule)return r;var e={};if(null!=r)for(var t in r)Object.hasOwnProperty.call(r,t)&&(e[t]=r[t]);return e.default=r,e};exports.__esModule=!0;var e=r(require("./util")),t=require("./gen");exports.CatchmentAreaGenerator=t.CatchmentAreaGenerator,exports.Util=e; },{"./util":7,"./gen":8}],1:[function(require,module,exports) { "use strict";exports.__esModule=!0;var e=require("./lib"),r=require("./lib");exports.Util=r.Util,exports.CatchmentAreaGenerator=e.CatchmentAreaGenerator,exports.default=exports.CatchmentAreaGenerator; },{"./lib":4}]},{},[1], null) //# sourceMappingURL=/index.map