@dra2020/baseclient 1.0.4 → 1.0.7

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.
@@ -1375,10 +1375,9 @@ class GeoMultiCollection {
1375
1375
  let n = this.nEntries;
1376
1376
  if (n == 1)
1377
1377
  this.all.col = this._col(this.nthEntry(0));
1378
- else {
1379
- this.all.col = { type: 'FeatureCollection', features: [] };
1380
- this.forEach(f => { this.all.col.features.push(f); });
1381
- }
1378
+ else
1379
+ // Going from map to collection guarantees that any duplicates are removed
1380
+ this.all.col = geoMapToCollection(this.allMap());
1382
1381
  }
1383
1382
  return this.all.col;
1384
1383
  }
@@ -1390,8 +1389,11 @@ class GeoMultiCollection {
1390
1389
  let n = this.nEntries;
1391
1390
  if (n == 1)
1392
1391
  this.all.map = this._map(this.nthEntry(0));
1393
- else
1394
- this.all.map = geoCollectionToMap(this.allCol());
1392
+ else {
1393
+ let map = {};
1394
+ this.all.map = map;
1395
+ this.forEach(f => { map[String(f.properties.id)] = f; });
1396
+ }
1395
1397
  }
1396
1398
  return this.all.map;
1397
1399
  }
@@ -7949,24 +7951,14 @@ function ringsCancel(outerPoly, innerRing) {
7949
7951
  function correctGeometry(f) {
7950
7952
  if (f && f.geometry && f.geometry.type === 'MultiPolygon' && f.geometry.coordinates) {
7951
7953
  let multiPoly = f.geometry.coordinates;
7952
- /* Comment this out right now - might have been do to not rewinding merge output
7953
- // topojson will under certain circumstances return a MultiPolygon with the first Polygon containing holes
7954
- // that are precisely filled by a subsequent polygon. We make a secondary union pass to try to correct for this.
7955
- // If we have a really degenerate multipolygon (test above some number of polygons) omit this expensive pass
7956
- // since cleanup is unlikely.
7957
- if (multiPoly.length > 1 && multiPoly.length < 50)
7958
- {
7959
- let result = Q.unionPolys(multiPoly);
7960
- if (Util.depthof(result) == 4) result = [ result ];
7961
- multiPoly = result;
7962
- }
7963
- */
7964
7954
  // Convert degenerate MultiPolygon to Polygon
7965
7955
  if (multiPoly.length == 1) {
7966
7956
  f.geometry.type = 'Polygon';
7967
7957
  f.geometry.coordinates = multiPoly[0];
7968
7958
  }
7969
7959
  }
7960
+ // TopoJSON does not guarantee proper winding order which messes up later processing. Fix it.
7961
+ P.featureRewind(f);
7970
7962
  return f;
7971
7963
  }
7972
7964
  function topoContiguity(topo) {
@@ -8060,6 +8052,9 @@ function bigTimeString(ms) {
8060
8052
  return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
8061
8053
  }
8062
8054
  const DefaultSimplifyOptions = { minArea: 500 };
8055
+ function log(s) {
8056
+ //console.log(s);
8057
+ }
8063
8058
  //
8064
8059
  // topoSimplifyCollection:
8065
8060
  // This implements our simplification strategy for block/precinct level shapes. The basic idea is to
@@ -8082,10 +8077,10 @@ function topoSimplifyCollection(col, options) {
8082
8077
  let elapsedTotal = new Util.Elapsed();
8083
8078
  let elapsed = new Util.Elapsed();
8084
8079
  let topo = topoFromCollection(col);
8085
- console.log(`topoSimplifyCollection: fromCollection: ${Math.round(elapsed.ms())}ms`);
8080
+ log(`topoSimplifyCollection: fromCollection: ${Math.round(elapsed.ms())}ms`);
8086
8081
  elapsed.start();
8087
8082
  topo = TopoSimplify.presimplify(topo, TopoSimplify['sphericalTriangleArea']);
8088
- console.log(`topoSimplifyCollection: presimplify: ${Math.round(elapsed.ms())}ms`);
8083
+ log(`topoSimplifyCollection: presimplify: ${Math.round(elapsed.ms())}ms`);
8089
8084
  elapsed.start();
8090
8085
  // Keep iterating on removing simplification from degenerate shapes
8091
8086
  let nTries = 1;
@@ -8141,11 +8136,11 @@ function topoSimplifyCollection(col, options) {
8141
8136
  }
8142
8137
  }
8143
8138
  });
8144
- console.log(`topoSimplifyCollection: pass ${nTries}: ${nBad} (${nTiny} tiny) of ${col.features.length} features are degenerate`);
8139
+ log(`topoSimplifyCollection: pass ${nTries}: ${nBad} (${nTiny} tiny) of ${col.features.length} features are degenerate`);
8145
8140
  // If not making progress, keep more points
8146
8141
  if (nBad >= nBadLast) {
8147
8142
  keepweight /= 10;
8148
- console.log(`topoSimplifyCollection: pass ${nTries}: reducing weight limit to ${keepweight}`);
8143
+ log(`topoSimplifyCollection: pass ${nTries}: reducing weight limit to ${keepweight}`);
8149
8144
  }
8150
8145
  nBadLast = nBad;
8151
8146
  if (nBad && nTries > MAX_TRIES)
@@ -8157,7 +8152,7 @@ function topoSimplifyCollection(col, options) {
8157
8152
  }
8158
8153
  nTries++;
8159
8154
  }
8160
- console.log(`topoSimplifyCollection: total elapsed time: ${bigTimeString(elapsedTotal.ms())}`);
8155
+ log(`topoSimplifyCollection: total elapsed time: ${bigTimeString(elapsedTotal.ms())}`);
8161
8156
  return col;
8162
8157
  }
8163
8158
  exports.topoSimplifyCollection = topoSimplifyCollection;
@@ -8166,27 +8161,7 @@ function topoMerge(topo, geoids) {
8166
8161
  return null;
8167
8162
  let objects = [];
8168
8163
  geoids.forEach((geoid) => objects.push(topo.objects[geoid]));
8169
- let f = correctGeometry({ type: 'Feature', properties: {}, geometry: TopoClient.merge(topo, objects) });
8170
- P.featureRewind(f);
8171
- /* Comment out for now - may be due to merge output needing to be rewound
8172
- // If I get a bad output from topoMerge, just do more expensive poly union. This can happen if input polygons
8173
- // are a little funky (in particular, if they double back along the same edge.
8174
- if (selfIntersectFast(f))
8175
- {
8176
- //console.log('topoMerge: patching selfIntersect');
8177
- let polys: any[] = [];
8178
- geoids.forEach((geoid) => polys.push(topoToFeature(topo, geoid).geometry.coordinates));
8179
- let result = Q.unionPolys(polys);
8180
- let depth = Util.depthof(result);
8181
- if (depth === 5 && result.length === 1)
8182
- {
8183
- depth = 4;
8184
- result = result[0];
8185
- }
8186
- f = { type: 'feature', properties: {}, geometry: { type: depth == 4 ? 'Polygon' : 'MultiPolygon', coordinates: result } };
8187
- }
8188
- */
8189
- return f;
8164
+ return correctGeometry({ type: 'Feature', properties: {}, geometry: TopoClient.merge(topo, objects) });
8190
8165
  }
8191
8166
  exports.topoMerge = topoMerge;
8192
8167
  function topoMergeFeatures(topo, features) {