@dra2020/district-analytics 8.2.1 → 8.2.4
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 +41 -12
- package/dist/cli.js.map +1 -1
- package/dist/district-analytics.js +29 -5
- package/dist/district-analytics.js.map +1 -1
- package/dist/src/results.d.ts +2 -1
- package/package.json +3 -3
package/dist/cli.js
CHANGED
|
@@ -90407,7 +90407,7 @@ function combineTwoPolys(poly1, poly2) {
|
|
|
90407
90407
|
throw 'Unable to load union function from polygon-clipping';
|
|
90408
90408
|
return _union(poly1, poly2);
|
|
90409
90409
|
}
|
|
90410
|
-
// FEATURE 3: REOCK
|
|
90410
|
+
// FEATURE 3: REOCK - Reock is the primary measure of the dispersion of district
|
|
90411
90411
|
// shapes, calculated as “the area of the distric to the area of the minimum spanning
|
|
90412
90412
|
// circle that can enclose the district.”
|
|
90413
90413
|
//
|
|
@@ -90531,12 +90531,17 @@ exports.featureizePoly = featureizePoly;
|
|
|
90531
90531
|
//
|
|
90532
90532
|
// COMPACTNESS PACKAGE API
|
|
90533
90533
|
//
|
|
90534
|
-
function __export(m) {
|
|
90535
|
-
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
90536
|
-
}
|
|
90537
90534
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
90538
|
-
|
|
90539
|
-
|
|
90535
|
+
var features_1 = __webpack_require__(/*! ./features */ "./src/features.ts");
|
|
90536
|
+
exports.calcXSymmetry = features_1.calcXSymmetry;
|
|
90537
|
+
exports.calcYSymmetry = features_1.calcYSymmetry;
|
|
90538
|
+
exports.calcReock = features_1.calcReock;
|
|
90539
|
+
exports.calcBoundingBox = features_1.calcBoundingBox;
|
|
90540
|
+
exports.calcPolsbyPopper = features_1.calcPolsbyPopper;
|
|
90541
|
+
exports.calcConvexHullFeature = features_1.calcConvexHullFeature;
|
|
90542
|
+
exports.calcSchwartzberg = features_1.calcSchwartzberg;
|
|
90543
|
+
var kiwysi_1 = __webpack_require__(/*! ./kiwysi */ "./src/kiwysi.ts");
|
|
90544
|
+
exports.scoreShapes = kiwysi_1.scoreShapes;
|
|
90540
90545
|
|
|
90541
90546
|
|
|
90542
90547
|
/***/ }),
|
|
@@ -90566,7 +90571,7 @@ exports.scoreShape = scoreShape;
|
|
|
90566
90571
|
function scoreShapes(shapes, options) {
|
|
90567
90572
|
let scores = [];
|
|
90568
90573
|
for (let i = 0; i < shapes.features.length; i++) {
|
|
90569
|
-
scores.push(scoreShape(shapes.features[i]));
|
|
90574
|
+
scores.push(scoreShape(shapes.features[i], options));
|
|
90570
90575
|
}
|
|
90571
90576
|
return scores;
|
|
90572
90577
|
}
|
|
@@ -281969,13 +281974,12 @@ function extractDistrictProperties(s, bLog = false) {
|
|
|
281969
281974
|
for (let i = 1; i <= s.state.nDistricts; i++) {
|
|
281970
281975
|
const poly = s.districts.getDistrictShapeByID(i);
|
|
281971
281976
|
// Guard against no shape for empty districts AND null shapes
|
|
281972
|
-
|
|
281973
|
-
if (!bNull) {
|
|
281977
|
+
if (isAShape(poly)) {
|
|
281974
281978
|
// TODO - OPTIMIZE: Bundle these calls?
|
|
281975
281979
|
const area = Poly.polyAreaFlat(poly);
|
|
281976
281980
|
const perimeter = Poly.polyPerimeterFlat(poly);
|
|
281977
281981
|
const diameter = Poly.polyDiameterFlat(poly);
|
|
281978
|
-
|
|
281982
|
+
let props = [0, 0, 0];
|
|
281979
281983
|
props[0 /* Area */] = area;
|
|
281980
281984
|
props[1 /* Diameter */] = diameter;
|
|
281981
281985
|
props[2 /* Perimeter */] = perimeter;
|
|
@@ -281986,10 +281990,35 @@ function extractDistrictProperties(s, bLog = false) {
|
|
|
281986
281990
|
}
|
|
281987
281991
|
}
|
|
281988
281992
|
exports.extractDistrictProperties = extractDistrictProperties;
|
|
281993
|
+
function isAShape(poly) {
|
|
281994
|
+
const bPolyUndefined = (poly === undefined) ? true : false;
|
|
281995
|
+
const bNull = (bPolyUndefined) ? true : Poly.polyNull(poly); // TODO
|
|
281996
|
+
const bNoCoordinates = U.isArrayEmpty((poly.geometry.coordinates)) ? true : false;
|
|
281997
|
+
return (!bPolyUndefined && !bNull && !bNoCoordinates);
|
|
281998
|
+
}
|
|
281989
281999
|
// SCORE KIWYSI COMPACTNESS
|
|
281990
282000
|
function scoreKIWYSICompactness(s, bLog = false) {
|
|
281991
|
-
const
|
|
281992
|
-
|
|
282001
|
+
const rawShapes = s.districts.getDistrictShapes();
|
|
282002
|
+
// Filter the real shapes & throw everything else away
|
|
282003
|
+
let goodShapes = {};
|
|
282004
|
+
goodShapes['type'] = "FeatureCollection";
|
|
282005
|
+
goodShapes['features'] = [];
|
|
282006
|
+
for (let i = 0; i < rawShapes.features.length; i++) {
|
|
282007
|
+
const shape = rawShapes.features[i];
|
|
282008
|
+
if (isAShape(shape)) {
|
|
282009
|
+
const d = Poly.polyDescribe(shape);
|
|
282010
|
+
let f = {
|
|
282011
|
+
type: 'Feature',
|
|
282012
|
+
properties: { districtID: `${i + 1}` },
|
|
282013
|
+
geometry: {
|
|
282014
|
+
type: (d.npoly > 1) ? 'MultiPolygon' : 'Polygon',
|
|
282015
|
+
coordinates: shape.geometry.coordinates
|
|
282016
|
+
}
|
|
282017
|
+
};
|
|
282018
|
+
goodShapes.features.push(f);
|
|
282019
|
+
}
|
|
282020
|
+
}
|
|
282021
|
+
const scores = Compactness.scoreShapes(goodShapes);
|
|
281993
282022
|
const avgKIWYSIScore = U.avgArray(scores);
|
|
281994
282023
|
return avgKIWYSIScore;
|
|
281995
282024
|
}
|