Skip to content

Commit

Permalink
US-SEC zone: merge before converting all zones to TopoJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
snarfed committed Aug 29, 2019
1 parent 4f57616 commit f133086
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
18 changes: 10 additions & 8 deletions web/generate-geometries.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ const zoneDefinitions = [
];

const getDataForZone = (zone, mergeStates) => {
/* for a specifi zone, defined by an Object having at least `zoneName` and
/* for a specific zone, defined by an Object having at least `zoneName` and
* `type` as properties, call the corresponding function to get the data */
if (zone.type === 'country'){
return getCountry(zone.id)
Expand Down Expand Up @@ -735,6 +735,15 @@ zoneDefinitions.forEach(zone => {
}
});

// merge contiguous Florida counties in US-SEC so that we only see the outer
// region boundary line(s), not the interior county boundary lines.
// Example: https://bl.ocks.org/mbostock/5416405
// Background: https://github.com/tmrowco/electricitymap-contrib/issues/1713#issuecomment-517704023
const topojson = require('topojson');
const sec = topojson.topology({'US-SEC': zones['US-SEC']})
const secMerged = topojson.mergeArcs(sec, [sec.objects['US-SEC']]);
zones['US-SEC'] = topojson.feature(sec, secMerged)

// create zonesMoreDetails by getting zone having moreDetails===true
let zonesMoreDetails = {};
zoneDefinitions.forEach(zone => {
Expand Down Expand Up @@ -768,15 +777,8 @@ zoneFeatures = toListOfFeatures(zoneFeaturesInline);
fs.writeFileSync('public/dist/zonegeometries.json', zoneFeatures.map(JSON.stringify).join('\n'));

// Convert to TopoJSON
const topojson = require('topojson');
let topo = topojson.topology(zones);

// merge contiguous Florida counties in US-SEC so that we only see the outer
// region boundary line(s), not the interior county boundary lines.
// Example: https://bl.ocks.org/mbostock/5416405
// Background: https://github.com/tmrowco/electricitymap-contrib/issues/1713#issuecomment-517704023
topo.objects['US-SEC'] = topojson.mergeArcs(topo, [topo.objects['US-SEC']]);

// Simplify all countries
topo = topojson.presimplify(topo);
topo = topojson.simplify(topo, 0.01);
Expand Down
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
"extract-text-webpack-plugin": "^4.0.0-beta.0",
"ndjson-cli": "^0.3.1",
"nodemon": "^1.17.1",
"polygon-clipping": "^0.14.2",
"readline-sync": "^1.4.9",
"shapefile": "^0.6.2",
"style-loader": "^0.20.2",
Expand Down
2 changes: 1 addition & 1 deletion web/src/world.json

Large diffs are not rendered by default.

0 comments on commit f133086

Please sign in to comment.