@dra2020/baseclient 1.0.35 → 1.0.38

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/lib/poly/mapto.ts CHANGED
@@ -38,22 +38,35 @@ export function polyMapToByCentroid(districts: G.GeoFeatureCollection, centroids
38
38
  let map: any = {};
39
39
 
40
40
  // Cache district boundboxes for quick containment exclusion
41
- let bbDistricts: BB.BoundBox[] = districts.features.map(f => BB.boundbox(f));
41
+ let fs: G.GeoFeature[] = districts.features;
42
+ let bbDistricts: BB.BoundBox[] = fs.map(f => BB.boundbox(f));
43
+ let aDistricts: number[] = fs.map(f => P.polyArea(f));
42
44
 
43
45
  // Walk over blocks, mapping centroid to district
44
46
  Object.keys(centroids).forEach(blockid => {
45
47
  let x = centroids[blockid].x;
46
48
  let y = centroids[blockid].y;
47
49
 
48
- let fIn: G.GeoFeature[] = [];
49
- districts.features.forEach((fDistrict: G.GeoFeature, i: number) => {
50
+ let fIn: number[] = [];
51
+ fs.forEach((fDistrict: G.GeoFeature, i: number) => {
50
52
  if (BB.boundboxContains(bbDistricts[i], x, y))
51
53
  if (polyContainsPoint(fDistrict, x, y))
52
- fIn.push(fDistrict);
54
+ fIn.push(i);
53
55
  });
54
56
 
55
57
  if (fIn.length == 1)
56
- map[blockid] = fIn[0].properties.id;
58
+ map[blockid] = fs[fIn[0]].properties.id;
59
+ else if (fIn.length > 1)
60
+ {
61
+ // Pick district with smallest area since some times we get malformed content that doesn't
62
+ // reflect holes in districts when one is nested in another. So theory is smaller district
63
+ // is a hole in containing larger one(s).
64
+ let iLow = fIn[0];
65
+ for (let i = 1; i < fIn.length; i++)
66
+ if (aDistricts[fIn[i]] < aDistricts[iLow])
67
+ iLow = fIn[i];
68
+ map[blockid] = fs[iLow].properties.id;
69
+ }
57
70
  });
58
71
 
59
72
  return map;
package/lib/poly/poly.ts CHANGED
@@ -683,6 +683,7 @@ export function featureRewind(poly: any): any
683
683
  let d = Util.depthof(poly.geometry.coordinates);
684
684
  if (d === 4) closePoly(poly.geometry.coordinates);
685
685
  else if (d === 5) poly.geometry.coordinates.forEach(closePoly);
686
+ poly.geometry.type = d === 4 ? 'Polygon' : 'MultiPolygon';
686
687
  }
687
688
  return poly;
688
689
  }
package/lib/poly/topo.ts CHANGED
@@ -19,11 +19,16 @@ export type Topo = any;
19
19
 
20
20
  function getGEOID(f: any): string
21
21
  {
22
- if (f.features && f.features.length) f = f.features[0];
23
- else if (Array.isArray(f)) f = f[0];
22
+ if (f.features && f.features.length)
23
+ f = f.features[0];
24
+ else if (Array.isArray(f))
25
+ f = f[0];
26
+ else
27
+ return '';
24
28
  if (f.properties.id !== undefined) return 'id';
25
29
  if (f.properties.GEOID !== undefined) return 'GEOID';
26
30
  if (f.properties.GEOID10 !== undefined) return 'GEOID10';
31
+ return '';
27
32
  }
28
33
 
29
34
  export function topoFromCollection(col: any): Topo
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dra2020/baseclient",
3
- "version": "1.0.35",
3
+ "version": "1.0.38",
4
4
  "description": "Utility functions for Javascript projects.",
5
5
  "main": "dist/baseclient.js",
6
6
  "types": "./dist/all/all.d.ts",
@@ -40,6 +40,9 @@
40
40
  "webpack-cli": "^4.4.0"
41
41
  },
42
42
  "dependencies": {
43
+ "@dra2020/baseclient": "^1.0.36",
44
+ "@dra2020/baseserver": "^1.0.21",
45
+ "@dra2020/dra-types": "^1.8.26",
43
46
  "@dra2020/topojson-client": "^3.2.7",
44
47
  "@dra2020/topojson-server": "^3.0.103",
45
48
  "@dra2020/topojson-simplify": "^3.0.102",