@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.
@@ -1199,13 +1199,12 @@ function extractDistrictProperties(s, bLog = false) {
1199
1199
  for (let i = 1; i <= s.state.nDistricts; i++) {
1200
1200
  const poly = s.districts.getDistrictShapeByID(i);
1201
1201
  // Guard against no shape for empty districts AND null shapes
1202
- const bNull = Poly.polyNull(poly);
1203
- if (!bNull) {
1202
+ if (isAShape(poly)) {
1204
1203
  // TODO - OPTIMIZE: Bundle these calls?
1205
1204
  const area = Poly.polyAreaFlat(poly);
1206
1205
  const perimeter = Poly.polyPerimeterFlat(poly);
1207
1206
  const diameter = Poly.polyDiameterFlat(poly);
1208
- const props = [0, 0, 0]; // TODO - TERRY?!?
1207
+ let props = [0, 0, 0];
1209
1208
  props[0 /* Area */] = area;
1210
1209
  props[1 /* Diameter */] = diameter;
1211
1210
  props[2 /* Perimeter */] = perimeter;
@@ -1216,10 +1215,35 @@ function extractDistrictProperties(s, bLog = false) {
1216
1215
  }
1217
1216
  }
1218
1217
  exports.extractDistrictProperties = extractDistrictProperties;
1218
+ function isAShape(poly) {
1219
+ const bPolyUndefined = (poly === undefined) ? true : false;
1220
+ const bNull = (bPolyUndefined) ? true : Poly.polyNull(poly); // TODO
1221
+ const bNoCoordinates = U.isArrayEmpty((poly.geometry.coordinates)) ? true : false;
1222
+ return (!bPolyUndefined && !bNull && !bNoCoordinates);
1223
+ }
1219
1224
  // SCORE KIWYSI COMPACTNESS
1220
1225
  function scoreKIWYSICompactness(s, bLog = false) {
1221
- const shapes = s.districts.getDistrictShapes();
1222
- const scores = Compactness.scoreShapes(shapes);
1226
+ const rawShapes = s.districts.getDistrictShapes();
1227
+ // Filter the real shapes & throw everything else away
1228
+ let goodShapes = {};
1229
+ goodShapes['type'] = "FeatureCollection";
1230
+ goodShapes['features'] = [];
1231
+ for (let i = 0; i < rawShapes.features.length; i++) {
1232
+ const shape = rawShapes.features[i];
1233
+ if (isAShape(shape)) {
1234
+ const d = Poly.polyDescribe(shape);
1235
+ let f = {
1236
+ type: 'Feature',
1237
+ properties: { districtID: `${i + 1}` },
1238
+ geometry: {
1239
+ type: (d.npoly > 1) ? 'MultiPolygon' : 'Polygon',
1240
+ coordinates: shape.geometry.coordinates
1241
+ }
1242
+ };
1243
+ goodShapes.features.push(f);
1244
+ }
1245
+ }
1246
+ const scores = Compactness.scoreShapes(goodShapes);
1223
1247
  const avgKIWYSIScore = U.avgArray(scores);
1224
1248
  return avgKIWYSIScore;
1225
1249
  }