@dra2020/district-analytics 8.2.1 → 8.2.2

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/cli.js CHANGED
@@ -281969,13 +281969,12 @@ function extractDistrictProperties(s, bLog = false) {
281969
281969
  for (let i = 1; i <= s.state.nDistricts; i++) {
281970
281970
  const poly = s.districts.getDistrictShapeByID(i);
281971
281971
  // Guard against no shape for empty districts AND null shapes
281972
- const bNull = Poly.polyNull(poly);
281973
- if (!bNull) {
281972
+ if (isAShape(poly)) {
281974
281973
  // TODO - OPTIMIZE: Bundle these calls?
281975
281974
  const area = Poly.polyAreaFlat(poly);
281976
281975
  const perimeter = Poly.polyPerimeterFlat(poly);
281977
281976
  const diameter = Poly.polyDiameterFlat(poly);
281978
- const props = [0, 0, 0]; // TODO - TERRY?!?
281977
+ let props = [0, 0, 0];
281979
281978
  props[0 /* Area */] = area;
281980
281979
  props[1 /* Diameter */] = diameter;
281981
281980
  props[2 /* Perimeter */] = perimeter;
@@ -281986,10 +281985,35 @@ function extractDistrictProperties(s, bLog = false) {
281986
281985
  }
281987
281986
  }
281988
281987
  exports.extractDistrictProperties = extractDistrictProperties;
281988
+ function isAShape(poly) {
281989
+ const bPolyUndefined = (poly === undefined) ? true : false;
281990
+ const bNull = (bPolyUndefined) ? true : Poly.polyNull(poly); // TODO
281991
+ const bNoCoordinates = U.isArrayEmpty((poly.geometry.coordinates)) ? true : false;
281992
+ return (!bPolyUndefined && !bNull && !bNoCoordinates);
281993
+ }
281989
281994
  // SCORE KIWYSI COMPACTNESS
281990
281995
  function scoreKIWYSICompactness(s, bLog = false) {
281991
- const shapes = s.districts.getDistrictShapes();
281992
- const scores = Compactness.scoreShapes(shapes);
281996
+ const rawShapes = s.districts.getDistrictShapes();
281997
+ // Filter the real shapes & throw everything else away
281998
+ let goodShapes = {};
281999
+ goodShapes['type'] = "FeatureCollection";
282000
+ goodShapes['features'] = [];
282001
+ for (let i = 0; i < rawShapes.features.length; i++) {
282002
+ const shape = rawShapes.features[i];
282003
+ if (isAShape(shape)) {
282004
+ const d = Poly.polyDescribe(shape);
282005
+ let f = {
282006
+ type: 'Feature',
282007
+ properties: { districtID: `${i + 1}` },
282008
+ geometry: {
282009
+ type: (d.npoly > 1) ? 'MultiPolygon' : 'Polygon',
282010
+ coordinates: shape.geometry.coordinates
282011
+ }
282012
+ };
282013
+ goodShapes.features.push(f);
282014
+ }
282015
+ }
282016
+ const scores = Compactness.scoreShapes(goodShapes);
281993
282017
  const avgKIWYSIScore = U.avgArray(scores);
281994
282018
  return avgKIWYSIScore;
281995
282019
  }