@dra2020/baseclient 1.0.3 → 1.0.6
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 +21 -38
- package/dist/baseclient.js.map +1 -1
- package/dist/geo/geo.d.ts +1 -0
- package/lib/geo/geo.ts +12 -0
- package/lib/poly/topo.ts +14 -40
- package/package.json +1 -1
package/dist/baseclient.js
CHANGED
|
@@ -1515,6 +1515,16 @@ class GeoMultiCollection {
|
|
|
1515
1515
|
}
|
|
1516
1516
|
return undefined;
|
|
1517
1517
|
}
|
|
1518
|
+
filter(test) {
|
|
1519
|
+
let m = new GeoMultiCollection();
|
|
1520
|
+
this.forEachEntry(e => {
|
|
1521
|
+
let col = this._col(e);
|
|
1522
|
+
let features = col ? col.features.filter(test) : null;
|
|
1523
|
+
if (features && features.length)
|
|
1524
|
+
m.add(e.tag, null, { type: 'FeatureCollection', features: features }, null);
|
|
1525
|
+
});
|
|
1526
|
+
return m;
|
|
1527
|
+
}
|
|
1518
1528
|
}
|
|
1519
1529
|
exports.GeoMultiCollection = GeoMultiCollection;
|
|
1520
1530
|
var geoIntersectOptions;
|
|
@@ -7939,24 +7949,14 @@ function ringsCancel(outerPoly, innerRing) {
|
|
|
7939
7949
|
function correctGeometry(f) {
|
|
7940
7950
|
if (f && f.geometry && f.geometry.type === 'MultiPolygon' && f.geometry.coordinates) {
|
|
7941
7951
|
let multiPoly = f.geometry.coordinates;
|
|
7942
|
-
/* Comment this out right now - might have been do to not rewinding merge output
|
|
7943
|
-
// topojson will under certain circumstances return a MultiPolygon with the first Polygon containing holes
|
|
7944
|
-
// that are precisely filled by a subsequent polygon. We make a secondary union pass to try to correct for this.
|
|
7945
|
-
// If we have a really degenerate multipolygon (test above some number of polygons) omit this expensive pass
|
|
7946
|
-
// since cleanup is unlikely.
|
|
7947
|
-
if (multiPoly.length > 1 && multiPoly.length < 50)
|
|
7948
|
-
{
|
|
7949
|
-
let result = Q.unionPolys(multiPoly);
|
|
7950
|
-
if (Util.depthof(result) == 4) result = [ result ];
|
|
7951
|
-
multiPoly = result;
|
|
7952
|
-
}
|
|
7953
|
-
*/
|
|
7954
7952
|
// Convert degenerate MultiPolygon to Polygon
|
|
7955
7953
|
if (multiPoly.length == 1) {
|
|
7956
7954
|
f.geometry.type = 'Polygon';
|
|
7957
7955
|
f.geometry.coordinates = multiPoly[0];
|
|
7958
7956
|
}
|
|
7959
7957
|
}
|
|
7958
|
+
// TopoJSON does not guarantee proper winding order which messes up later processing. Fix it.
|
|
7959
|
+
P.featureRewind(f);
|
|
7960
7960
|
return f;
|
|
7961
7961
|
}
|
|
7962
7962
|
function topoContiguity(topo) {
|
|
@@ -8050,6 +8050,9 @@ function bigTimeString(ms) {
|
|
|
8050
8050
|
return `${minutes}:${seconds < 10 ? '0' : ''}${seconds}`;
|
|
8051
8051
|
}
|
|
8052
8052
|
const DefaultSimplifyOptions = { minArea: 500 };
|
|
8053
|
+
function log(s) {
|
|
8054
|
+
//console.log(s);
|
|
8055
|
+
}
|
|
8053
8056
|
//
|
|
8054
8057
|
// topoSimplifyCollection:
|
|
8055
8058
|
// This implements our simplification strategy for block/precinct level shapes. The basic idea is to
|
|
@@ -8072,10 +8075,10 @@ function topoSimplifyCollection(col, options) {
|
|
|
8072
8075
|
let elapsedTotal = new Util.Elapsed();
|
|
8073
8076
|
let elapsed = new Util.Elapsed();
|
|
8074
8077
|
let topo = topoFromCollection(col);
|
|
8075
|
-
|
|
8078
|
+
log(`topoSimplifyCollection: fromCollection: ${Math.round(elapsed.ms())}ms`);
|
|
8076
8079
|
elapsed.start();
|
|
8077
8080
|
topo = TopoSimplify.presimplify(topo, TopoSimplify['sphericalTriangleArea']);
|
|
8078
|
-
|
|
8081
|
+
log(`topoSimplifyCollection: presimplify: ${Math.round(elapsed.ms())}ms`);
|
|
8079
8082
|
elapsed.start();
|
|
8080
8083
|
// Keep iterating on removing simplification from degenerate shapes
|
|
8081
8084
|
let nTries = 1;
|
|
@@ -8131,11 +8134,11 @@ function topoSimplifyCollection(col, options) {
|
|
|
8131
8134
|
}
|
|
8132
8135
|
}
|
|
8133
8136
|
});
|
|
8134
|
-
|
|
8137
|
+
log(`topoSimplifyCollection: pass ${nTries}: ${nBad} (${nTiny} tiny) of ${col.features.length} features are degenerate`);
|
|
8135
8138
|
// If not making progress, keep more points
|
|
8136
8139
|
if (nBad >= nBadLast) {
|
|
8137
8140
|
keepweight /= 10;
|
|
8138
|
-
|
|
8141
|
+
log(`topoSimplifyCollection: pass ${nTries}: reducing weight limit to ${keepweight}`);
|
|
8139
8142
|
}
|
|
8140
8143
|
nBadLast = nBad;
|
|
8141
8144
|
if (nBad && nTries > MAX_TRIES)
|
|
@@ -8147,7 +8150,7 @@ function topoSimplifyCollection(col, options) {
|
|
|
8147
8150
|
}
|
|
8148
8151
|
nTries++;
|
|
8149
8152
|
}
|
|
8150
|
-
|
|
8153
|
+
log(`topoSimplifyCollection: total elapsed time: ${bigTimeString(elapsedTotal.ms())}`);
|
|
8151
8154
|
return col;
|
|
8152
8155
|
}
|
|
8153
8156
|
exports.topoSimplifyCollection = topoSimplifyCollection;
|
|
@@ -8156,27 +8159,7 @@ function topoMerge(topo, geoids) {
|
|
|
8156
8159
|
return null;
|
|
8157
8160
|
let objects = [];
|
|
8158
8161
|
geoids.forEach((geoid) => objects.push(topo.objects[geoid]));
|
|
8159
|
-
|
|
8160
|
-
P.featureRewind(f);
|
|
8161
|
-
/* Comment out for now - may be due to merge output needing to be rewound
|
|
8162
|
-
// If I get a bad output from topoMerge, just do more expensive poly union. This can happen if input polygons
|
|
8163
|
-
// are a little funky (in particular, if they double back along the same edge.
|
|
8164
|
-
if (selfIntersectFast(f))
|
|
8165
|
-
{
|
|
8166
|
-
//console.log('topoMerge: patching selfIntersect');
|
|
8167
|
-
let polys: any[] = [];
|
|
8168
|
-
geoids.forEach((geoid) => polys.push(topoToFeature(topo, geoid).geometry.coordinates));
|
|
8169
|
-
let result = Q.unionPolys(polys);
|
|
8170
|
-
let depth = Util.depthof(result);
|
|
8171
|
-
if (depth === 5 && result.length === 1)
|
|
8172
|
-
{
|
|
8173
|
-
depth = 4;
|
|
8174
|
-
result = result[0];
|
|
8175
|
-
}
|
|
8176
|
-
f = { type: 'feature', properties: {}, geometry: { type: depth == 4 ? 'Polygon' : 'MultiPolygon', coordinates: result } };
|
|
8177
|
-
}
|
|
8178
|
-
*/
|
|
8179
|
-
return f;
|
|
8162
|
+
return correctGeometry({ type: 'Feature', properties: {}, geometry: TopoClient.merge(topo, objects) });
|
|
8180
8163
|
}
|
|
8181
8164
|
exports.topoMerge = topoMerge;
|
|
8182
8165
|
function topoMergeFeatures(topo, features) {
|