@dra2020/baseclient 1.0.34 → 1.0.37

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,7 +1345,7 @@ 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.geoTopoToCollection = exports.geoCollectionToTopo = 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.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
  function geoEnsureID(col) {
@@ -1375,25 +1375,39 @@ function geoCollectionToMap(col) {
1375
1375
  }
1376
1376
  exports.geoCollectionToMap = geoCollectionToMap;
1377
1377
  function geoMapToCollection(map) {
1378
- if (map == null || Util.countKeys(map) == 0)
1378
+ if (Util.countKeys(map) == 0)
1379
+ return null;
1380
+ return geoMapToCollectionNonNull(map);
1381
+ }
1382
+ exports.geoMapToCollection = geoMapToCollection;
1383
+ function geoMapToCollectionNonNull(map) {
1384
+ if (map == null)
1379
1385
  return null;
1380
1386
  let col = { type: 'FeatureCollection', features: [] };
1381
1387
  Object.keys(map).forEach((geoid) => { col.features.push(map[geoid]); });
1382
1388
  return col;
1383
1389
  }
1384
- exports.geoMapToCollection = geoMapToCollection;
1390
+ exports.geoMapToCollectionNonNull = geoMapToCollectionNonNull;
1385
1391
  function geoCollectionToTopo(col) {
1386
1392
  let topo = Poly.topoFromCollection(col);
1387
1393
  Poly.topoPack(topo);
1388
1394
  return topo;
1389
1395
  }
1390
1396
  exports.geoCollectionToTopo = geoCollectionToTopo;
1397
+ function geoCollectionToTopoNonNull(col) {
1398
+ return geoCollectionToTopo(col);
1399
+ }
1400
+ exports.geoCollectionToTopoNonNull = geoCollectionToTopoNonNull;
1391
1401
  function geoTopoToCollection(topo) {
1392
1402
  let col = Poly.topoToCollection(topo);
1393
1403
  Poly.featurePack(col);
1394
1404
  return col;
1395
1405
  }
1396
1406
  exports.geoTopoToCollection = geoTopoToCollection;
1407
+ function geoTopoToCollectionNonNull(topo) {
1408
+ return geoTopoToCollection(topo);
1409
+ }
1410
+ exports.geoTopoToCollectionNonNull = geoTopoToCollectionNonNull;
1397
1411
  function geoEqual(m1, m2) {
1398
1412
  let n1 = m1 ? m1.length : 0;
1399
1413
  let n2 = m2 ? m2.length : 0;
@@ -1483,9 +1497,9 @@ class GeoMultiCollection {
1483
1497
  return null;
1484
1498
  if (!e.col) {
1485
1499
  if (e.map)
1486
- e.col = geoMapToCollection(e.map);
1500
+ e.col = geoMapToCollectionNonNull(e.map);
1487
1501
  else if (e.topo)
1488
- e.col = geoTopoToCollection(e.topo);
1502
+ e.col = geoTopoToCollectionNonNull(e.topo);
1489
1503
  }
1490
1504
  return e.col;
1491
1505
  }
@@ -1496,7 +1510,7 @@ class GeoMultiCollection {
1496
1510
  if (e.col)
1497
1511
  e.map = geoCollectionToMap(e.col);
1498
1512
  else if (e.topo) {
1499
- e.col = geoTopoToCollection(e.topo);
1513
+ e.col = geoTopoToCollectionNonNull(e.topo);
1500
1514
  e.map = geoCollectionToMap(e.col);
1501
1515
  }
1502
1516
  }
@@ -1507,10 +1521,10 @@ class GeoMultiCollection {
1507
1521
  return null;
1508
1522
  if (!e.topo) {
1509
1523
  if (e.col)
1510
- e.topo = geoCollectionToTopo(e.col);
1524
+ e.topo = geoCollectionToTopoNonNull(e.col);
1511
1525
  else if (e.map) {
1512
- e.col = geoMapToCollection(e.map);
1513
- e.topo = geoCollectionToTopo(e.col);
1526
+ e.col = geoMapToCollectionNonNull(e.map);
1527
+ e.topo = geoCollectionToTopoNonNull(e.col);
1514
1528
  }
1515
1529
  }
1516
1530
  return e.topo;
@@ -1531,7 +1545,7 @@ class GeoMultiCollection {
1531
1545
  this.all.col = this._col(this.nthEntry(0));
1532
1546
  else
1533
1547
  // Going from map to collection guarantees that any duplicates are removed
1534
- this.all.col = geoMapToCollection(this.allMap());
1548
+ this.all.col = geoMapToCollectionNonNull(this.allMap());
1535
1549
  }
1536
1550
  return this.all.col;
1537
1551
  }
@@ -1560,7 +1574,7 @@ class GeoMultiCollection {
1560
1574
  if (n == 1)
1561
1575
  this.all.topo = this._topo(this.nthEntry(0));
1562
1576
  else
1563
- this.all.topo = geoCollectionToTopo(this.allCol());
1577
+ this.all.topo = geoCollectionToTopoNonNull(this.allCol());
1564
1578
  }
1565
1579
  return this.all.topo;
1566
1580
  }
@@ -5376,6 +5390,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
5376
5390
  };
5377
5391
  Object.defineProperty(exports, "__esModule", ({ value: true }));
5378
5392
  exports.polyMapTo = exports.polyMapToByCentroid = void 0;
5393
+ const P = __importStar(__webpack_require__(/*! ./poly */ "./lib/poly/poly.ts"));
5379
5394
  const PL = __importStar(__webpack_require__(/*! ./polylabel */ "./lib/poly/polylabel.ts"));
5380
5395
  const BB = __importStar(__webpack_require__(/*! ./boundbox */ "./lib/poly/boundbox.ts"));
5381
5396
  const pointinpoly_1 = __webpack_require__(/*! ./pointinpoly */ "./lib/poly/pointinpoly.ts");
@@ -5407,19 +5422,31 @@ function setLabels(c) {
5407
5422
  function polyMapToByCentroid(districts, centroids) {
5408
5423
  let map = {};
5409
5424
  // Cache district boundboxes for quick containment exclusion
5410
- let bbDistricts = districts.features.map(f => BB.boundbox(f));
5425
+ let fs = districts.features;
5426
+ let bbDistricts = fs.map(f => BB.boundbox(f));
5427
+ let aDistricts = fs.map(f => P.polyArea(f));
5411
5428
  // Walk over blocks, mapping centroid to district
5412
5429
  Object.keys(centroids).forEach(blockid => {
5413
5430
  let x = centroids[blockid].x;
5414
5431
  let y = centroids[blockid].y;
5415
5432
  let fIn = [];
5416
- districts.features.forEach((fDistrict, i) => {
5433
+ fs.forEach((fDistrict, i) => {
5417
5434
  if (BB.boundboxContains(bbDistricts[i], x, y))
5418
5435
  if (pointinpoly_1.polyContainsPoint(fDistrict, x, y))
5419
- fIn.push(fDistrict);
5436
+ fIn.push(i);
5420
5437
  });
5421
5438
  if (fIn.length == 1)
5422
- map[blockid] = fIn[0].properties.id;
5439
+ map[blockid] = fs[fIn[0]].properties.id;
5440
+ else if (fIn.length > 1) {
5441
+ // Pick district with smallest area since some times we get malformed content that doesn't
5442
+ // reflect holes in districts when one is nested in another. So theory is smaller district
5443
+ // is a hole in containing larger one(s).
5444
+ let iLow = fIn[0];
5445
+ for (let i = 1; i < fIn.length; i++)
5446
+ if (aDistricts[fIn[i]] < aDistricts[iLow])
5447
+ iLow = fIn[i];
5448
+ map[blockid] = fs[iLow].properties.id;
5449
+ }
5423
5450
  });
5424
5451
  return map;
5425
5452
  }
@@ -8264,12 +8291,15 @@ function getGEOID(f) {
8264
8291
  f = f.features[0];
8265
8292
  else if (Array.isArray(f))
8266
8293
  f = f[0];
8294
+ else
8295
+ return '';
8267
8296
  if (f.properties.id !== undefined)
8268
8297
  return 'id';
8269
8298
  if (f.properties.GEOID !== undefined)
8270
8299
  return 'GEOID';
8271
8300
  if (f.properties.GEOID10 !== undefined)
8272
8301
  return 'GEOID10';
8302
+ return '';
8273
8303
  }
8274
8304
  function topoFromCollection(col) {
8275
8305
  if (col == null)
@@ -8278,7 +8308,11 @@ function topoFromCollection(col) {
8278
8308
  let prop = getGEOID(col);
8279
8309
  let objects = {};
8280
8310
  col.features.forEach((f) => objects[f.properties[prop]] = f);
8281
- let topo = TopoServer.topology(objects);
8311
+ let topo;
8312
+ if (Util.isEmpty(objects))
8313
+ topo = { objects: objects };
8314
+ else
8315
+ topo = TopoServer.topology(objects);
8282
8316
  PP.featureRepack(col, save);
8283
8317
  if (col.datasets)
8284
8318
  topo.datasets = col.datasets;
@@ -8342,10 +8376,11 @@ function topoToFeature(topo, geoid) {
8342
8376
  exports.topoToFeature = topoToFeature;
8343
8377
  function topoToCollection(topo) {
8344
8378
  let col = { type: 'FeatureCollection', features: [] };
8345
- Object.keys(topo.objects).forEach((geoid) => {
8346
- col.features.push(topoToFeature(topo, geoid));
8347
- });
8348
- if (topo.datasets)
8379
+ if (topo)
8380
+ Object.keys(topo.objects).forEach((geoid) => {
8381
+ col.features.push(topoToFeature(topo, geoid));
8382
+ });
8383
+ if (topo && topo.datasets)
8349
8384
  col.datasets = topo.datasets;
8350
8385
  return col;
8351
8386
  }