@dra2020/baseclient 1.0.27 → 1.0.30

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,96 @@ 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 = exports.polyMapToByCentroid = 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 polyMapToByCentroid(districts, centroids) {
5404
+ let map = {};
5405
+ // Cache district boundboxes for quick containment exclusion
5406
+ let bbDistricts = districts.features.map(f => BB.boundbox(f));
5407
+ // Walk over blocks, mapping centroid to district
5408
+ Object.keys(centroids).forEach(blockid => {
5409
+ let x = centroids[blockid].x;
5410
+ let y = centroids[blockid].y;
5411
+ let fIn = [];
5412
+ districts.features.forEach((fDistrict, i) => {
5413
+ if (BB.boundboxContains(bbDistricts[i], x, y))
5414
+ if (pointinpoly_1.polyContainsPoint(fDistrict, x, y))
5415
+ fIn.push(fDistrict);
5416
+ });
5417
+ if (fIn.length == 1)
5418
+ map[blockid] = fIn[0].properties.id;
5419
+ });
5420
+ return map;
5421
+ }
5422
+ exports.polyMapToByCentroid = polyMapToByCentroid;
5423
+ function polyMapTo(districts, blocks) {
5424
+ // Cache labelx, labely if necessary
5425
+ setLabels(blocks);
5426
+ let centroids = {};
5427
+ blocks.features.forEach(f => {
5428
+ centroids[f.properties.id] = { x: f.properties.labelx, y: f.properties.labely };
5429
+ });
5430
+ return polyMapToByCentroid(districts, centroids);
5431
+ }
5432
+ exports.polyMapTo = polyMapTo;
5433
+
5434
+
5344
5435
  /***/ }),
5345
5436
 
5346
5437
  /***/ "./lib/poly/matrix.ts":
@@ -5794,7 +5885,7 @@ function polyContainsPoint(poly, x, y) {
5794
5885
  return;
5795
5886
  let inside = false;
5796
5887
  let iEnd = iOffset + (nPoints - 1) * 2;
5797
- for (let i = iOffset, j = iEnd; i < iEnd; j = i, i += 2) {
5888
+ for (let i = iOffset, j = iEnd; i <= iEnd; j = i, i += 2) {
5798
5889
  let xi = b[i], yi = b[i + 1];
5799
5890
  let xj = b[j], yj = b[j + 1];
5800
5891
  let intersect = ((yi > y) !== (yj > y))