@dra2020/baseclient 1.0.50 → 1.0.51

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;