@dra2020/baseclient 1.0.49 → 1.0.52
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 +159 -14
- package/dist/baseclient.js.map +1 -1
- package/dist/geo/geo.d.ts +8 -1
- package/dist/poly/topo.d.ts +1 -0
- package/dist/util/all.d.ts +1 -0
- package/dist/util/bitset.d.ts +10 -0
- package/lib/geo/geo.ts +116 -4
- package/lib/poly/topo.ts +9 -8
- package/lib/util/all.ts +1 -0
- package/lib/util/bitset.ts +49 -0
- package/package.json +1 -1
package/dist/baseclient.js
CHANGED
|
@@ -1345,18 +1345,31 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
1345
1345
|
return result;
|
|
1346
1346
|
};
|
|
1347
1347
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
1348
|
-
exports.geoIntersect = exports.geoIntersectOptions = exports.GeoMultiCollection = exports.geoMapEqual = exports.geoEqual = exports.geoTopoToCollectionNonNull = exports.geoTopoToCollection = exports.geoCollectionToTopoNonNull = exports.geoCollectionToTopo = exports.geoMapToCollectionNonNull = exports.geoMapToCollection = exports.geoCollectionToMap = exports.geoEnsureID = void 0;
|
|
1348
|
+
exports.geoIntersect = exports.geoIntersectOptions = exports.GeoMultiCollection = exports.geoMapEqual = exports.geoEqual = exports.geoTopoToCollectionNonNull = exports.geoTopoToCollection = exports.geoCollectionToTopoNonNull = exports.geoCollectionToTopo = exports.geoMapToCollectionNonNull = exports.geoMapToCollection = exports.geoCollectionToMap = exports.geoNormalizeCollection = exports.geoNormalizeFeature = exports.geoEnsureID = void 0;
|
|
1349
1349
|
const Util = __importStar(__webpack_require__(/*! ../util/all */ "./lib/util/all.ts"));
|
|
1350
1350
|
const Poly = __importStar(__webpack_require__(/*! ../poly/all */ "./lib/poly/all.ts"));
|
|
1351
|
-
|
|
1351
|
+
const NormalizeAll = { joinPolygons: true, checkRewind: true, ensureID: true };
|
|
1352
|
+
// set the canonical 'id' property from the best property value.
|
|
1353
|
+
// if joinPolygons is true, we do not enforce uniqueness.
|
|
1354
|
+
//
|
|
1355
|
+
function geoEnsureID(col, options) {
|
|
1356
|
+
options = Util.shallowAssignImmutable({}, options);
|
|
1352
1357
|
let prop;
|
|
1353
|
-
const props = ['id', 'GEOID', 'GEOID10', 'GEOID20', 'GEOID30'];
|
|
1358
|
+
const props = ['id', 'GEOID', 'GEOID10', 'GEOID20', 'GEOID30', 'DISTRICT', 'DISTRICTNO', 'DISTRICTNAME'];
|
|
1354
1359
|
if (col && col.features && col.features.length > 0) {
|
|
1355
1360
|
let f = col.features[0];
|
|
1356
1361
|
if (f.properties.id !== undefined)
|
|
1357
|
-
return;
|
|
1358
|
-
props.forEach(p => {
|
|
1359
|
-
prop
|
|
1362
|
+
return; // short-cut - assume if 'id' is set, we're all good.
|
|
1363
|
+
props.forEach(p => {
|
|
1364
|
+
if (prop === undefined)
|
|
1365
|
+
if (f.properties[p] !== undefined)
|
|
1366
|
+
prop = p;
|
|
1367
|
+
else {
|
|
1368
|
+
p = p.toLowerCase();
|
|
1369
|
+
if (f.properties[p] !== undefined)
|
|
1370
|
+
prop = p;
|
|
1371
|
+
}
|
|
1372
|
+
});
|
|
1360
1373
|
if (prop)
|
|
1361
1374
|
col.features.forEach(f => { f.properties.id = f.properties[prop]; });
|
|
1362
1375
|
else {
|
|
@@ -1366,6 +1379,77 @@ function geoEnsureID(col) {
|
|
|
1366
1379
|
}
|
|
1367
1380
|
}
|
|
1368
1381
|
exports.geoEnsureID = geoEnsureID;
|
|
1382
|
+
function geoNormalizeFeature(f, options) {
|
|
1383
|
+
options = Util.shallowAssignImmutable({}, options);
|
|
1384
|
+
if (f && f.geometry && f.geometry.type === 'MultiPolygon' && f.geometry.coordinates) {
|
|
1385
|
+
let multiPoly = f.geometry.coordinates;
|
|
1386
|
+
// Convert degenerate MultiPolygon to Polygon
|
|
1387
|
+
if (multiPoly.length == 1) {
|
|
1388
|
+
f.geometry.type = 'Polygon';
|
|
1389
|
+
f.geometry.coordinates = multiPoly[0];
|
|
1390
|
+
}
|
|
1391
|
+
}
|
|
1392
|
+
else if (f && f.geometry && f.geometry.type === 'Point' && f.geometry.coordinates) {
|
|
1393
|
+
while (Array.isArray(f.geometry.coordinates[0]))
|
|
1394
|
+
f.geometry.coordinates = f.geometry.coordinates[0];
|
|
1395
|
+
}
|
|
1396
|
+
else if (options.checkRewind)
|
|
1397
|
+
// Various tools do not guarantee valid GeoJSON winding rules. Verify it since internal processing
|
|
1398
|
+
// assumes it is correct.
|
|
1399
|
+
Poly.featureRewind(f);
|
|
1400
|
+
return f;
|
|
1401
|
+
}
|
|
1402
|
+
exports.geoNormalizeFeature = geoNormalizeFeature;
|
|
1403
|
+
function onlyPolygons(col) {
|
|
1404
|
+
if (col && Array.isArray(col.features))
|
|
1405
|
+
for (let i = 0; i < col.features.length; i++) {
|
|
1406
|
+
let f = col.features[i];
|
|
1407
|
+
if (f.geometry && f.geometry.type === 'MultiPolygon')
|
|
1408
|
+
return false;
|
|
1409
|
+
}
|
|
1410
|
+
return true;
|
|
1411
|
+
}
|
|
1412
|
+
function mergePolygon(f1, f2) {
|
|
1413
|
+
if (!f1)
|
|
1414
|
+
return f2;
|
|
1415
|
+
if (!f2)
|
|
1416
|
+
return f1;
|
|
1417
|
+
if (f1.geometry.type !== 'Polygon' && f1.geometry.type !== 'MultiPolygon')
|
|
1418
|
+
return f1;
|
|
1419
|
+
if (f2.geometry.type !== 'Polygon' && f2.geometry.type !== 'MultiPolygon')
|
|
1420
|
+
return f2;
|
|
1421
|
+
if (f1.geometry.type === 'Polygon') {
|
|
1422
|
+
f1.geometry.type = 'MultiPolygon';
|
|
1423
|
+
if (f2.geometry.type === 'Polygon')
|
|
1424
|
+
f1.geometry.coordinates = [f1.geometry.coordinates, f2.geometry.coordinates];
|
|
1425
|
+
else
|
|
1426
|
+
f1.geometry.coordinates = [f1.geometry.coordinates, ...f2.geometry.coordinates];
|
|
1427
|
+
}
|
|
1428
|
+
else {
|
|
1429
|
+
if (f2.geometry.type === 'Polygon')
|
|
1430
|
+
f1.geometry.coordinates.push(f2.geometry.coordinates);
|
|
1431
|
+
else
|
|
1432
|
+
f1.geometry.coordinates = [...f1.geometry.coordinates, ...f2.geometry.coordinates];
|
|
1433
|
+
}
|
|
1434
|
+
return f1;
|
|
1435
|
+
}
|
|
1436
|
+
function geoNormalizeCollection(col, options) {
|
|
1437
|
+
options = Util.shallowAssignImmutable(NormalizeAll, options);
|
|
1438
|
+
// Normalize individual features
|
|
1439
|
+
if (col && Array.isArray(col.features))
|
|
1440
|
+
col.features.forEach((f) => geoNormalizeFeature(f, options));
|
|
1441
|
+
// Ensure ID
|
|
1442
|
+
if (options.ensureID)
|
|
1443
|
+
geoEnsureID(col, options);
|
|
1444
|
+
// Merge polygons into multi-polygons based on id?
|
|
1445
|
+
if (options.ensureID && options.joinPolygons && onlyPolygons(col)) {
|
|
1446
|
+
let map = {};
|
|
1447
|
+
col.features.forEach(f => { let id = f.properties.id; map[id] = mergePolygon(map[id], f); });
|
|
1448
|
+
col.features = Object.values(map);
|
|
1449
|
+
}
|
|
1450
|
+
return col;
|
|
1451
|
+
}
|
|
1452
|
+
exports.geoNormalizeCollection = geoNormalizeCollection;
|
|
1369
1453
|
function geoCollectionToMap(col) {
|
|
1370
1454
|
if (col == null)
|
|
1371
1455
|
return null;
|
|
@@ -8551,8 +8635,9 @@ function intpt(f) {
|
|
|
8551
8635
|
return { x: x, y: y };
|
|
8552
8636
|
}
|
|
8553
8637
|
const DefaultSimplifyOptions = { minArea: 500 };
|
|
8554
|
-
function log(s) {
|
|
8555
|
-
|
|
8638
|
+
function log(emitlog, s) {
|
|
8639
|
+
if (emitlog)
|
|
8640
|
+
console.log(s);
|
|
8556
8641
|
}
|
|
8557
8642
|
//
|
|
8558
8643
|
// topoSimplifyCollection:
|
|
@@ -8576,10 +8661,10 @@ function topoSimplifyCollection(col, options) {
|
|
|
8576
8661
|
let elapsedTotal = new Util.Elapsed();
|
|
8577
8662
|
let elapsed = new Util.Elapsed();
|
|
8578
8663
|
let topo = topoFromCollection(col);
|
|
8579
|
-
log(`topoSimplifyCollection: fromCollection: ${Math.round(elapsed.ms())}ms`);
|
|
8664
|
+
log(options.log, `topoSimplifyCollection: fromCollection: ${Math.round(elapsed.ms())}ms`);
|
|
8580
8665
|
elapsed.start();
|
|
8581
8666
|
topo = TopoSimplify.presimplify(topo, TopoSimplify['sphericalTriangleArea']);
|
|
8582
|
-
log(`topoSimplifyCollection: presimplify: ${Math.round(elapsed.ms())}ms`);
|
|
8667
|
+
log(options.log, `topoSimplifyCollection: presimplify: ${Math.round(elapsed.ms())}ms`);
|
|
8583
8668
|
elapsed.start();
|
|
8584
8669
|
// Keep iterating on removing simplification from degenerate shapes
|
|
8585
8670
|
let nTries = 1;
|
|
@@ -8644,17 +8729,17 @@ function topoSimplifyCollection(col, options) {
|
|
|
8644
8729
|
keepTiny.set(f, f);
|
|
8645
8730
|
keepArcs(topo, oOld.arcs, 0); // keeps all points to avoid reprocessing these tiny shapes
|
|
8646
8731
|
nBad++, nTiny++;
|
|
8647
|
-
log(`topoSimplifyCollection: ${f.properties.id}: increasing feature fidelity because intpt dist is ${d}`);
|
|
8732
|
+
log(options.log, `topoSimplifyCollection: ${f.properties.id}: increasing feature fidelity because intpt dist is ${d}`);
|
|
8648
8733
|
}
|
|
8649
8734
|
}
|
|
8650
8735
|
}
|
|
8651
8736
|
}
|
|
8652
8737
|
});
|
|
8653
|
-
log(`topoSimplifyCollection: pass ${nTries}: ${nBad} (${nTiny} tiny) of ${col.features.length} features are degenerate`);
|
|
8738
|
+
log(options.log, `topoSimplifyCollection: pass ${nTries}: ${nBad} (${nTiny} tiny) of ${col.features.length} features are degenerate`);
|
|
8654
8739
|
// If not making progress, keep more points
|
|
8655
8740
|
if (nBad >= nBadLast) {
|
|
8656
8741
|
keepweight /= 10;
|
|
8657
|
-
log(`topoSimplifyCollection: pass ${nTries}: reducing weight limit to ${keepweight}`);
|
|
8742
|
+
log(options.log, `topoSimplifyCollection: pass ${nTries}: reducing weight limit to ${keepweight}`);
|
|
8658
8743
|
}
|
|
8659
8744
|
nBadLast = nBad;
|
|
8660
8745
|
if (nBad && nTries > MAX_TRIES)
|
|
@@ -8666,7 +8751,7 @@ function topoSimplifyCollection(col, options) {
|
|
|
8666
8751
|
}
|
|
8667
8752
|
nTries++;
|
|
8668
8753
|
}
|
|
8669
|
-
log(`topoSimplifyCollection: total elapsed time: ${bigTimeString(elapsedTotal.ms())}`);
|
|
8754
|
+
log(options.log, `topoSimplifyCollection: total elapsed time: ${bigTimeString(elapsedTotal.ms())}`);
|
|
8670
8755
|
return col;
|
|
8671
8756
|
}
|
|
8672
8757
|
exports.topoSimplifyCollection = topoSimplifyCollection;
|
|
@@ -9166,6 +9251,7 @@ __exportStar(__webpack_require__(/*! ./countedhash */ "./lib/util/countedhash.ts
|
|
|
9166
9251
|
__exportStar(__webpack_require__(/*! ./indexedarray */ "./lib/util/indexedarray.ts"), exports);
|
|
9167
9252
|
__exportStar(__webpack_require__(/*! ./gradient */ "./lib/util/gradient.ts"), exports);
|
|
9168
9253
|
__exportStar(__webpack_require__(/*! ./bintrie */ "./lib/util/bintrie.ts"), exports);
|
|
9254
|
+
__exportStar(__webpack_require__(/*! ./bitset */ "./lib/util/bitset.ts"), exports);
|
|
9169
9255
|
|
|
9170
9256
|
|
|
9171
9257
|
/***/ }),
|
|
@@ -9627,6 +9713,65 @@ class BinTrieBuilder {
|
|
|
9627
9713
|
exports.BinTrieBuilder = BinTrieBuilder;
|
|
9628
9714
|
|
|
9629
9715
|
|
|
9716
|
+
/***/ }),
|
|
9717
|
+
|
|
9718
|
+
/***/ "./lib/util/bitset.ts":
|
|
9719
|
+
/*!****************************!*\
|
|
9720
|
+
!*** ./lib/util/bitset.ts ***!
|
|
9721
|
+
\****************************/
|
|
9722
|
+
/***/ ((__unused_webpack_module, exports) => {
|
|
9723
|
+
|
|
9724
|
+
|
|
9725
|
+
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
|
9726
|
+
exports.ListToBitset = void 0;
|
|
9727
|
+
const BitLookup = [1, 2, 4, 8, 16, 32, 64, 128];
|
|
9728
|
+
class ListToBitset {
|
|
9729
|
+
constructor(list) {
|
|
9730
|
+
this.list = list;
|
|
9731
|
+
this.index = {};
|
|
9732
|
+
this.size = Math.floor((this.list.length + 7) / 8);
|
|
9733
|
+
this.list.forEach((s, i) => { this.index[s] = i; });
|
|
9734
|
+
}
|
|
9735
|
+
toBits(l) {
|
|
9736
|
+
let ab = new ArrayBuffer(this.size);
|
|
9737
|
+
let u8 = new Uint8Array(ab);
|
|
9738
|
+
if (l)
|
|
9739
|
+
l.forEach(s => {
|
|
9740
|
+
let n = this.index[s];
|
|
9741
|
+
let i = Math.floor(n / 8);
|
|
9742
|
+
u8[i] |= BitLookup[n % 8];
|
|
9743
|
+
});
|
|
9744
|
+
return u8;
|
|
9745
|
+
}
|
|
9746
|
+
toList(u8) {
|
|
9747
|
+
let list = [];
|
|
9748
|
+
for (let i = 0; i < u8.length; i++) {
|
|
9749
|
+
let u = u8[i];
|
|
9750
|
+
if (u) {
|
|
9751
|
+
if (u & 1)
|
|
9752
|
+
list.push(this.list[i * 8 + 0]);
|
|
9753
|
+
if (u & 2)
|
|
9754
|
+
list.push(this.list[i * 8 + 1]);
|
|
9755
|
+
if (u & 4)
|
|
9756
|
+
list.push(this.list[i * 8 + 2]);
|
|
9757
|
+
if (u & 8)
|
|
9758
|
+
list.push(this.list[i * 8 + 3]);
|
|
9759
|
+
if (u & 16)
|
|
9760
|
+
list.push(this.list[i * 8 + 4]);
|
|
9761
|
+
if (u & 32)
|
|
9762
|
+
list.push(this.list[i * 8 + 5]);
|
|
9763
|
+
if (u & 64)
|
|
9764
|
+
list.push(this.list[i * 8 + 6]);
|
|
9765
|
+
if (u & 128)
|
|
9766
|
+
list.push(this.list[i * 8 + 7]);
|
|
9767
|
+
}
|
|
9768
|
+
}
|
|
9769
|
+
return list;
|
|
9770
|
+
}
|
|
9771
|
+
}
|
|
9772
|
+
exports.ListToBitset = ListToBitset;
|
|
9773
|
+
|
|
9774
|
+
|
|
9630
9775
|
/***/ }),
|
|
9631
9776
|
|
|
9632
9777
|
/***/ "./lib/util/countedhash.ts":
|