@dra2020/baseclient 1.0.50 → 1.0.53

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.
@@ -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
- function geoEnsureID(col) {
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 => { if (prop === undefined && f.properties[p] !== undefined)
1359
- prop = p; });
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;
@@ -9167,6 +9251,7 @@ __exportStar(__webpack_require__(/*! ./countedhash */ "./lib/util/countedhash.ts
9167
9251
  __exportStar(__webpack_require__(/*! ./indexedarray */ "./lib/util/indexedarray.ts"), exports);
9168
9252
  __exportStar(__webpack_require__(/*! ./gradient */ "./lib/util/gradient.ts"), exports);
9169
9253
  __exportStar(__webpack_require__(/*! ./bintrie */ "./lib/util/bintrie.ts"), exports);
9254
+ __exportStar(__webpack_require__(/*! ./bitset */ "./lib/util/bitset.ts"), exports);
9170
9255
 
9171
9256
 
9172
9257
  /***/ }),
@@ -9628,6 +9713,67 @@ class BinTrieBuilder {
9628
9713
  exports.BinTrieBuilder = BinTrieBuilder;
9629
9714
 
9630
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
+ }
9732
+ toBits(l) {
9733
+ if (!this.index) {
9734
+ this.size = Math.floor((this.list.length + 7) / 8);
9735
+ this.index = {};
9736
+ this.list.forEach((s, i) => { this.index[s] = i; });
9737
+ }
9738
+ let ab = new ArrayBuffer(this.size);
9739
+ let u8 = new Uint8Array(ab);
9740
+ if (l)
9741
+ l.forEach(s => {
9742
+ let n = this.index[s];
9743
+ let i = Math.floor(n / 8);
9744
+ u8[i] |= BitLookup[n % 8];
9745
+ });
9746
+ return u8;
9747
+ }
9748
+ toList(u8) {
9749
+ let list = [];
9750
+ for (let i = 0; i < u8.length; i++) {
9751
+ let u = u8[i];
9752
+ if (u) {
9753
+ if (u & 1)
9754
+ list.push(this.list[i * 8 + 0]);
9755
+ if (u & 2)
9756
+ list.push(this.list[i * 8 + 1]);
9757
+ if (u & 4)
9758
+ list.push(this.list[i * 8 + 2]);
9759
+ if (u & 8)
9760
+ list.push(this.list[i * 8 + 3]);
9761
+ if (u & 16)
9762
+ list.push(this.list[i * 8 + 4]);
9763
+ if (u & 32)
9764
+ list.push(this.list[i * 8 + 5]);
9765
+ if (u & 64)
9766
+ list.push(this.list[i * 8 + 6]);
9767
+ if (u & 128)
9768
+ list.push(this.list[i * 8 + 7]);
9769
+ }
9770
+ }
9771
+ return list;
9772
+ }
9773
+ }
9774
+ exports.ListToBitset = ListToBitset;
9775
+
9776
+
9631
9777
  /***/ }),
9632
9778
 
9633
9779
  /***/ "./lib/util/countedhash.ts":