@dra2020/baseclient 1.0.28 → 1.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4663,6 +4663,7 @@ __exportStar(__webpack_require__(/*! ./topo */ "./lib/poly/topo.ts"), exports);
4663
4663
  __exportStar(__webpack_require__(/*! ./selfintersect */ "./lib/poly/selfintersect.ts"), exports);
4664
4664
  __exportStar(__webpack_require__(/*! ./shamos */ "./lib/poly/shamos.ts"), exports);
4665
4665
  __exportStar(__webpack_require__(/*! ./pointinpoly */ "./lib/poly/pointinpoly.ts"), exports);
4666
+ __exportStar(__webpack_require__(/*! ./mapto */ "./lib/poly/mapto.ts"), exports);
4666
4667
 
4667
4668
 
4668
4669
  /***/ }),
@@ -5341,6 +5342,88 @@ if (typeof module !== 'undefined') {
5341
5342
  */
5342
5343
 
5343
5344
 
5345
+ /***/ }),
5346
+
5347
+ /***/ "./lib/poly/mapto.ts":
5348
+ /*!***************************!*\
5349
+ !*** ./lib/poly/mapto.ts ***!
5350
+ \***************************/
5351
+ /***/ (function(__unused_webpack_module, exports, __webpack_require__) {
5352
+
5353
+
5354
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
5355
+ if (k2 === undefined) k2 = k;
5356
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5357
+ }) : (function(o, m, k, k2) {
5358
+ if (k2 === undefined) k2 = k;
5359
+ o[k2] = m[k];
5360
+ }));
5361
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
5362
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
5363
+ }) : function(o, v) {
5364
+ o["default"] = v;
5365
+ });
5366
+ var __importStar = (this && this.__importStar) || function (mod) {
5367
+ if (mod && mod.__esModule) return mod;
5368
+ var result = {};
5369
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
5370
+ __setModuleDefault(result, mod);
5371
+ return result;
5372
+ };
5373
+ Object.defineProperty(exports, "__esModule", ({ value: true }));
5374
+ exports.polyMapTo = void 0;
5375
+ const PL = __importStar(__webpack_require__(/*! ./polylabel */ "./lib/poly/polylabel.ts"));
5376
+ const BB = __importStar(__webpack_require__(/*! ./boundbox */ "./lib/poly/boundbox.ts"));
5377
+ const pointinpoly_1 = __webpack_require__(/*! ./pointinpoly */ "./lib/poly/pointinpoly.ts");
5378
+ function setLabels(c) {
5379
+ c.features.forEach(f => {
5380
+ if (f.properties.labelx === undefined) {
5381
+ let { x, y } = PL.polyLabel(f);
5382
+ f.properties.labelx = x;
5383
+ f.properties.labely = y;
5384
+ }
5385
+ });
5386
+ }
5387
+ // polyMapTo:
5388
+ //
5389
+ // Given a set of underlying blocks (or precincts), map them to the district (or any other feature)
5390
+ // they are contained in.
5391
+ //
5392
+ // If a block maps to multiple districts or no district, it is left out of the result.
5393
+ //
5394
+ // Note that the algorithm is to see where the centroid of the block overlaps. So a block
5395
+ // could potentially overlap multiple districts and this would return only the one containing
5396
+ // the centroid.
5397
+ //
5398
+ // The thinking is that if you want fine granularity, use real blocks as the base collection.
5399
+ // If you provide precincts, you will get a result on precinct granularity.
5400
+ //
5401
+ // The return value is an object that maps the block feature ids to the district feature id.
5402
+ //
5403
+ function polyMapTo(districts, blocks) {
5404
+ let map = {};
5405
+ // Cache labelx, labely if necessary
5406
+ setLabels(blocks);
5407
+ // Cache district boundboxes for quick containment exclusion
5408
+ let bbDistricts = districts.features.map(f => BB.boundbox(f));
5409
+ // Walk over blocks, mapping centroid to district
5410
+ blocks.features.forEach(fBlock => {
5411
+ let x = fBlock.properties.labelx;
5412
+ let y = fBlock.properties.labely;
5413
+ let fIn = [];
5414
+ districts.features.forEach((fDistrict, i) => {
5415
+ if (BB.boundboxContains(bbDistricts[i], x, y))
5416
+ if (pointinpoly_1.polyContainsPoint(fDistrict, x, y))
5417
+ fIn.push(fDistrict);
5418
+ });
5419
+ if (fIn.length == 1)
5420
+ map[fBlock.properties.id] = fIn[0].properties.id;
5421
+ });
5422
+ return map;
5423
+ }
5424
+ exports.polyMapTo = polyMapTo;
5425
+
5426
+
5344
5427
  /***/ }),
5345
5428
 
5346
5429
  /***/ "./lib/poly/matrix.ts":