@dra2020/district-analytics 8.2.2 → 8.2.5

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.
@@ -503,10 +503,17 @@ class Districts {
503
503
  featurePop = outerThis._session.features.fieldForFeature(f, "CENSUS" /* CENSUS */, "Tot" /* TotalPop */);
504
504
  // Total district population
505
505
  totalPop += featurePop;
506
- // Total population by counties w/in a district,
507
- // except the dummy unassigned district 0
508
- if (i > 0)
509
- countySplits[outerThis.getCountyIndex(geoID)] += featurePop;
506
+ // Ignore features when the county is unrecognized
507
+ const countyFIPS = U.parseGeoID(geoID)['county'];
508
+ if (U.keyExists(countyFIPS, outerThis._session.counties.index)) {
509
+ // Total population by counties w/in a district,
510
+ // except the dummy unassigned district 0
511
+ if (i > 0)
512
+ countySplits[outerThis.getCountyIndex(geoID)] += featurePop;
513
+ }
514
+ else {
515
+ console.log("County not recognized:", geoID);
516
+ }
510
517
  // Democratic and Republican vote totals
511
518
  demVotes += outerThis._session.features.fieldForFeature(f, "ELECTION" /* ELECTION */, "D" /* DemVotes */);
512
519
  repVotes += outerThis._session.features.fieldForFeature(f, "ELECTION" /* ELECTION */, "R" /* RepVotes */);
@@ -1217,7 +1224,7 @@ function extractDistrictProperties(s, bLog = false) {
1217
1224
  exports.extractDistrictProperties = extractDistrictProperties;
1218
1225
  function isAShape(poly) {
1219
1226
  const bPolyUndefined = (poly === undefined) ? true : false;
1220
- const bNull = (bPolyUndefined) ? true : Poly.polyNull(poly); // TODO
1227
+ const bNull = (bPolyUndefined) ? true : Poly.polyNull(poly); // TODO - poly
1221
1228
  const bNoCoordinates = U.isArrayEmpty((poly.geometry.coordinates)) ? true : false;
1222
1229
  return (!bPolyUndefined && !bNull && !bNoCoordinates);
1223
1230
  }
@@ -1457,12 +1464,25 @@ function doPreprocessData(s, bLog = false) {
1457
1464
  exports.doPreprocessData = doPreprocessData;
1458
1465
  // CREATE A FIPS CODE TO COUNTY NAME LOOKUP
1459
1466
  function doPreprocessCountyFeatures(s, bLog = false) {
1467
+ let fipsCodes = [];
1468
+ // CREATE A MAP OF FIPS CODES TO NAMES
1460
1469
  for (let i = 0; i < s.counties.nCounties; i++) {
1461
1470
  let county = s.counties.countyByIndex(i);
1462
1471
  let fips = s.counties.propertyForCounty(county, 'COUNTYFP');
1472
+ fipsCodes.push(fips);
1463
1473
  let name = s.counties.propertyForCounty(county, 'NAME');
1464
1474
  s.counties.mapFIPSToName(fips, name);
1465
1475
  }
1476
+ // CREATE A FIPS CODE-ORDINAL MAP
1477
+ // Sort the FIPS codes in the county shapes
1478
+ fipsCodes = fipsCodes.sort();
1479
+ // Add a dummy county, for county-district splitting analysis.
1480
+ fipsCodes.unshift('000');
1481
+ // NOTE - This was added for the legacy SPLITTING implementation.
1482
+ // Create the ID-ordinal map
1483
+ for (let i in fipsCodes) {
1484
+ s.counties.index[fipsCodes[i]] = Number(i);
1485
+ }
1466
1486
  }
1467
1487
  // ANALYZE THE CENSUS BY COUNTY
1468
1488
  function doPreprocessCensus(s, bLog = false) {
@@ -1482,12 +1502,18 @@ function doPreprocessCensus(s, bLog = false) {
1482
1502
  s.state.totalPop += value;
1483
1503
  // Get the county FIPS code for the feature
1484
1504
  let countyFIPS = U.parseGeoID(geoID)['county'];
1485
- // If a subtotal for the county doesn't exist, initialize one
1486
- if (!(U.keyExists(countyFIPS, totalByCounty))) {
1487
- totalByCounty[countyFIPS] = 0;
1505
+ // Ignore features when the county is unrecognized
1506
+ if (U.keyExists(countyFIPS, s.counties.index)) {
1507
+ // If a subtotal for the county doesn't exist, initialize one
1508
+ if (!(U.keyExists(countyFIPS, totalByCounty))) {
1509
+ totalByCounty[countyFIPS] = 0;
1510
+ }
1511
+ // Sum total population by county
1512
+ totalByCounty[countyFIPS] += value;
1513
+ }
1514
+ else {
1515
+ console.log("County not recognized:", geoID);
1488
1516
  }
1489
- // Sum total population by county
1490
- totalByCounty[countyFIPS] += value;
1491
1517
  }
1492
1518
  else {
1493
1519
  if (bLog)
@@ -1495,18 +1521,24 @@ function doPreprocessCensus(s, bLog = false) {
1495
1521
  }
1496
1522
  }
1497
1523
  // NOTE - The above could be replaced, if I got totals on county.geojson.
1524
+ /* Moved this to doPreprocessCountyFeatures() - 09-14-2020 to fix VA county mismatch bug
1498
1525
  // CREATE A FIPS CODE-ORDINAL MAP
1526
+
1499
1527
  // Get the county FIPS codes
1500
1528
  let fipsCodes = U.getObjectKeys(totalByCounty);
1501
1529
  // Sort the results
1502
1530
  fipsCodes = fipsCodes.sort();
1531
+
1503
1532
  // NOTE - This was added for the legacy SPLITTING implementation.
1504
1533
  // Add a dummy county, for county-district splitting analysis.
1505
1534
  fipsCodes.unshift('000');
1535
+
1506
1536
  // Create the ID-ordinal map
1507
- for (let i in fipsCodes) {
1508
- s.counties.index[fipsCodes[i]] = Number(i);
1537
+ for (let i in fipsCodes)
1538
+ {
1539
+ s.counties.index[fipsCodes[i]] = Number(i);
1509
1540
  }
1541
+ */
1510
1542
  // MAKE AN ARRAY OF TOTAL POPULATIONS BY COUNTY INDEX
1511
1543
  // Add an extra 0th virtual county bucket for county-district splitting analysis
1512
1544
  let nCountyBuckets = s.counties.nCounties + 1;
@@ -1528,6 +1560,8 @@ function doPreprocessCensus(s, bLog = false) {
1528
1560
  let tooBigName = [];
1529
1561
  let expectedSplits = 0;
1530
1562
  let expectedAffected = 0;
1563
+ // Get the county FIPS codes
1564
+ let fipsCodes = U.getObjectKeys(s.counties.index);
1531
1565
  // Loop over the counties
1532
1566
  for (let county in fipsCodes) {
1533
1567
  let fipsCode = fipsCodes[county];