@dra2020/baseclient 1.0.28 → 1.0.31
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.
- package/dist/baseclient.js +95 -0
- package/dist/baseclient.js.map +1 -1
- package/dist/geo/geo.d.ts +6 -0
- package/dist/poly/all.d.ts +1 -0
- package/dist/poly/mapto.d.ts +3 -0
- package/lib/geo/geo.ts +6 -0
- package/lib/poly/all.ts +1 -0
- package/lib/poly/mapto.ts +73 -0
- package/package.json +1 -1
package/dist/baseclient.js
CHANGED
|
@@ -1359,6 +1359,10 @@ function geoEnsureID(col) {
|
|
|
1359
1359
|
prop = p; });
|
|
1360
1360
|
if (prop)
|
|
1361
1361
|
col.features.forEach(f => { f.properties.id = f.properties[prop]; });
|
|
1362
|
+
else {
|
|
1363
|
+
let n = 1;
|
|
1364
|
+
col.features.forEach(f => { f.properties.id = String(n++); });
|
|
1365
|
+
}
|
|
1362
1366
|
}
|
|
1363
1367
|
}
|
|
1364
1368
|
exports.geoEnsureID = geoEnsureID;
|
|
@@ -4663,6 +4667,7 @@ __exportStar(__webpack_require__(/*! ./topo */ "./lib/poly/topo.ts"), exports);
|
|
|
4663
4667
|
__exportStar(__webpack_require__(/*! ./selfintersect */ "./lib/poly/selfintersect.ts"), exports);
|
|
4664
4668
|
__exportStar(__webpack_require__(/*! ./shamos */ "./lib/poly/shamos.ts"), exports);
|
|
4665
4669
|
__exportStar(__webpack_require__(/*! ./pointinpoly */ "./lib/poly/pointinpoly.ts"), exports);
|
|
4670
|
+
__exportStar(__webpack_require__(/*! ./mapto */ "./lib/poly/mapto.ts"), exports);
|
|
4666
4671
|
|
|
4667
4672
|
|
|
4668
4673
|
/***/ }),
|
|
@@ -5341,6 +5346,96 @@ if (typeof module !== 'undefined') {
|
|
|
5341
5346
|
*/
|
|
5342
5347
|
|
|
5343
5348
|
|
|
5349
|
+
/***/ }),
|
|
5350
|
+
|
|
5351
|
+
/***/ "./lib/poly/mapto.ts":
|
|
5352
|
+
/*!***************************!*\
|
|
5353
|
+
!*** ./lib/poly/mapto.ts ***!
|
|
5354
|
+
\***************************/
|
|
5355
|
+
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
|
5356
|
+
|
|
5357
|
+
|
|
5358
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5359
|
+
if (k2 === undefined) k2 = k;
|
|
5360
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5361
|
+
}) : (function(o, m, k, k2) {
|
|
5362
|
+
if (k2 === undefined) k2 = k;
|
|
5363
|
+
o[k2] = m[k];
|
|
5364
|
+
}));
|
|
5365
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
5366
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
5367
|
+
}) : function(o, v) {
|
|
5368
|
+
o["default"] = v;
|
|
5369
|
+
});
|
|
5370
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
5371
|
+
if (mod && mod.__esModule) return mod;
|
|
5372
|
+
var result = {};
|
|
5373
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
5374
|
+
__setModuleDefault(result, mod);
|
|
5375
|
+
return result;
|
|
5376
|
+
};
|
|
5377
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
5378
|
+
exports.polyMapTo = exports.polyMapToByCentroid = void 0;
|
|
5379
|
+
const PL = __importStar(__webpack_require__(/*! ./polylabel */ "./lib/poly/polylabel.ts"));
|
|
5380
|
+
const BB = __importStar(__webpack_require__(/*! ./boundbox */ "./lib/poly/boundbox.ts"));
|
|
5381
|
+
const pointinpoly_1 = __webpack_require__(/*! ./pointinpoly */ "./lib/poly/pointinpoly.ts");
|
|
5382
|
+
function setLabels(c) {
|
|
5383
|
+
c.features.forEach(f => {
|
|
5384
|
+
if (f.properties.labelx === undefined) {
|
|
5385
|
+
let { x, y } = PL.polyLabel(f);
|
|
5386
|
+
f.properties.labelx = x;
|
|
5387
|
+
f.properties.labely = y;
|
|
5388
|
+
}
|
|
5389
|
+
});
|
|
5390
|
+
}
|
|
5391
|
+
// polyMapTo:
|
|
5392
|
+
//
|
|
5393
|
+
// Given a set of underlying blocks (or precincts), map them to the district (or any other feature)
|
|
5394
|
+
// they are contained in.
|
|
5395
|
+
//
|
|
5396
|
+
// If a block maps to multiple districts or no district, it is left out of the result.
|
|
5397
|
+
//
|
|
5398
|
+
// Note that the algorithm is to see where the centroid of the block overlaps. So a block
|
|
5399
|
+
// could potentially overlap multiple districts and this would return only the one containing
|
|
5400
|
+
// the centroid.
|
|
5401
|
+
//
|
|
5402
|
+
// The thinking is that if you want fine granularity, use real blocks as the base collection.
|
|
5403
|
+
// If you provide precincts, you will get a result on precinct granularity.
|
|
5404
|
+
//
|
|
5405
|
+
// The return value is an object that maps the block feature ids to the district feature id.
|
|
5406
|
+
//
|
|
5407
|
+
function polyMapToByCentroid(districts, centroids) {
|
|
5408
|
+
let map = {};
|
|
5409
|
+
// Cache district boundboxes for quick containment exclusion
|
|
5410
|
+
let bbDistricts = districts.features.map(f => BB.boundbox(f));
|
|
5411
|
+
// Walk over blocks, mapping centroid to district
|
|
5412
|
+
Object.keys(centroids).forEach(blockid => {
|
|
5413
|
+
let x = centroids[blockid].x;
|
|
5414
|
+
let y = centroids[blockid].y;
|
|
5415
|
+
let fIn = [];
|
|
5416
|
+
districts.features.forEach((fDistrict, i) => {
|
|
5417
|
+
if (BB.boundboxContains(bbDistricts[i], x, y))
|
|
5418
|
+
if (pointinpoly_1.polyContainsPoint(fDistrict, x, y))
|
|
5419
|
+
fIn.push(fDistrict);
|
|
5420
|
+
});
|
|
5421
|
+
if (fIn.length == 1)
|
|
5422
|
+
map[blockid] = fIn[0].properties.id;
|
|
5423
|
+
});
|
|
5424
|
+
return map;
|
|
5425
|
+
}
|
|
5426
|
+
exports.polyMapToByCentroid = polyMapToByCentroid;
|
|
5427
|
+
function polyMapTo(districts, blocks) {
|
|
5428
|
+
// Cache labelx, labely if necessary
|
|
5429
|
+
setLabels(blocks);
|
|
5430
|
+
let centroids = {};
|
|
5431
|
+
blocks.features.forEach(f => {
|
|
5432
|
+
centroids[f.properties.id] = { x: f.properties.labelx, y: f.properties.labely };
|
|
5433
|
+
});
|
|
5434
|
+
return polyMapToByCentroid(districts, centroids);
|
|
5435
|
+
}
|
|
5436
|
+
exports.polyMapTo = polyMapTo;
|
|
5437
|
+
|
|
5438
|
+
|
|
5344
5439
|
/***/ }),
|
|
5345
5440
|
|
|
5346
5441
|
/***/ "./lib/poly/matrix.ts":
|