@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.
- package/dist/baseclient.js +19 -44
- package/dist/baseclient.js.map +1 -1
- package/lib/geo/geo.ts +7 -5
- package/lib/poly/topo.ts +14 -40
- package/package.json +1 -1
package/lib/geo/geo.ts
CHANGED
|
@@ -218,10 +218,8 @@ export class GeoMultiCollection
|
|
|
218
218
|
if (n == 1)
|
|
219
219
|
this.all.col = this._col(this.nthEntry(0));
|
|
220
220
|
else
|
|
221
|
-
|
|
222
|
-
this.all.col =
|
|
223
|
-
this.forEach(f => { this.all.col.features.push(f) });
|
|
224
|
-
}
|
|
221
|
+
// Going from map to collection guarantees that any duplicates are removed
|
|
222
|
+
this.all.col = geoMapToCollection(this.allMap());
|
|
225
223
|
}
|
|
226
224
|
return this.all.col;
|
|
227
225
|
}
|
|
@@ -236,7 +234,11 @@ export class GeoMultiCollection
|
|
|
236
234
|
if (n == 1)
|
|
237
235
|
this.all.map = this._map(this.nthEntry(0));
|
|
238
236
|
else
|
|
239
|
-
|
|
237
|
+
{
|
|
238
|
+
let map: GeoFeatureMap = {};
|
|
239
|
+
this.all.map = map;
|
|
240
|
+
this.forEach(f => { map[String(f.properties.id)] = f });
|
|
241
|
+
}
|
|
240
242
|
}
|
|
241
243
|
return this.all.map;
|
|
242
244
|
}
|
package/lib/poly/topo.ts
CHANGED
|
@@ -59,19 +59,6 @@ function correctGeometry(f: any): any
|
|
|
59
59
|
{
|
|
60
60
|
let multiPoly = f.geometry.coordinates;
|
|
61
61
|
|
|
62
|
-
/* Comment this out right now - might have been do to not rewinding merge output
|
|
63
|
-
// topojson will under certain circumstances return a MultiPolygon with the first Polygon containing holes
|
|
64
|
-
// that are precisely filled by a subsequent polygon. We make a secondary union pass to try to correct for this.
|
|
65
|
-
// If we have a really degenerate multipolygon (test above some number of polygons) omit this expensive pass
|
|
66
|
-
// since cleanup is unlikely.
|
|
67
|
-
if (multiPoly.length > 1 && multiPoly.length < 50)
|
|
68
|
-
{
|
|
69
|
-
let result = Q.unionPolys(multiPoly);
|
|
70
|
-
if (Util.depthof(result) == 4) result = [ result ];
|
|
71
|
-
multiPoly = result;
|
|
72
|
-
}
|
|
73
|
-
*/
|
|
74
|
-
|
|
75
62
|
// Convert degenerate MultiPolygon to Polygon
|
|
76
63
|
if (multiPoly.length == 1)
|
|
77
64
|
{
|
|
@@ -80,6 +67,9 @@ function correctGeometry(f: any): any
|
|
|
80
67
|
}
|
|
81
68
|
}
|
|
82
69
|
|
|
70
|
+
// TopoJSON does not guarantee proper winding order which messes up later processing. Fix it.
|
|
71
|
+
P.featureRewind(f);
|
|
72
|
+
|
|
83
73
|
return f;
|
|
84
74
|
}
|
|
85
75
|
|
|
@@ -194,6 +184,11 @@ export interface SimplifyOptions
|
|
|
194
184
|
|
|
195
185
|
const DefaultSimplifyOptions: SimplifyOptions = { minArea: 500 };
|
|
196
186
|
|
|
187
|
+
function log(s: string): void
|
|
188
|
+
{
|
|
189
|
+
//console.log(s);
|
|
190
|
+
}
|
|
191
|
+
|
|
197
192
|
//
|
|
198
193
|
// topoSimplifyCollection:
|
|
199
194
|
// This implements our simplification strategy for block/precinct level shapes. The basic idea is to
|
|
@@ -218,10 +213,10 @@ export function topoSimplifyCollection(col: any, options?: SimplifyOptions): any
|
|
|
218
213
|
let elapsedTotal = new Util.Elapsed();
|
|
219
214
|
let elapsed = new Util.Elapsed();
|
|
220
215
|
let topo = topoFromCollection(col);
|
|
221
|
-
|
|
216
|
+
log(`topoSimplifyCollection: fromCollection: ${Math.round(elapsed.ms())}ms`);
|
|
222
217
|
elapsed.start();
|
|
223
218
|
topo = TopoSimplify.presimplify(topo, TopoSimplify['sphericalTriangleArea']);
|
|
224
|
-
|
|
219
|
+
log(`topoSimplifyCollection: presimplify: ${Math.round(elapsed.ms())}ms`);
|
|
225
220
|
elapsed.start();
|
|
226
221
|
|
|
227
222
|
// Keep iterating on removing simplification from degenerate shapes
|
|
@@ -286,13 +281,13 @@ export function topoSimplifyCollection(col: any, options?: SimplifyOptions): any
|
|
|
286
281
|
}
|
|
287
282
|
}
|
|
288
283
|
});
|
|
289
|
-
|
|
284
|
+
log(`topoSimplifyCollection: pass ${nTries}: ${nBad} (${nTiny} tiny) of ${col.features.length} features are degenerate`);
|
|
290
285
|
|
|
291
286
|
// If not making progress, keep more points
|
|
292
287
|
if (nBad >= nBadLast)
|
|
293
288
|
{
|
|
294
289
|
keepweight /= 10;
|
|
295
|
-
|
|
290
|
+
log(`topoSimplifyCollection: pass ${nTries}: reducing weight limit to ${keepweight}`);
|
|
296
291
|
}
|
|
297
292
|
nBadLast = nBad;
|
|
298
293
|
|
|
@@ -308,7 +303,7 @@ export function topoSimplifyCollection(col: any, options?: SimplifyOptions): any
|
|
|
308
303
|
nTries++;
|
|
309
304
|
}
|
|
310
305
|
|
|
311
|
-
|
|
306
|
+
log(`topoSimplifyCollection: total elapsed time: ${bigTimeString(elapsedTotal.ms())}`);
|
|
312
307
|
|
|
313
308
|
return col;
|
|
314
309
|
}
|
|
@@ -318,28 +313,7 @@ export function topoMerge(topo: Topo, geoids: string[]): any
|
|
|
318
313
|
if (geoids == null || geoids.length == 0) return null;
|
|
319
314
|
let objects: any[] = [];
|
|
320
315
|
geoids.forEach((geoid) => objects.push(topo.objects[geoid]));
|
|
321
|
-
|
|
322
|
-
P.featureRewind(f);
|
|
323
|
-
|
|
324
|
-
/* Comment out for now - may be due to merge output needing to be rewound
|
|
325
|
-
// If I get a bad output from topoMerge, just do more expensive poly union. This can happen if input polygons
|
|
326
|
-
// are a little funky (in particular, if they double back along the same edge.
|
|
327
|
-
if (selfIntersectFast(f))
|
|
328
|
-
{
|
|
329
|
-
//console.log('topoMerge: patching selfIntersect');
|
|
330
|
-
let polys: any[] = [];
|
|
331
|
-
geoids.forEach((geoid) => polys.push(topoToFeature(topo, geoid).geometry.coordinates));
|
|
332
|
-
let result = Q.unionPolys(polys);
|
|
333
|
-
let depth = Util.depthof(result);
|
|
334
|
-
if (depth === 5 && result.length === 1)
|
|
335
|
-
{
|
|
336
|
-
depth = 4;
|
|
337
|
-
result = result[0];
|
|
338
|
-
}
|
|
339
|
-
f = { type: 'feature', properties: {}, geometry: { type: depth == 4 ? 'Polygon' : 'MultiPolygon', coordinates: result } };
|
|
340
|
-
}
|
|
341
|
-
*/
|
|
342
|
-
return f;
|
|
316
|
+
return correctGeometry({ type: 'Feature', properties: {}, geometry: TopoClient.merge(topo, objects) });
|
|
343
317
|
}
|
|
344
318
|
|
|
345
319
|
export function topoMergeFeatures(topo: Topo, features: any[]): any
|