Skip to content

Commit

Permalink
Simplify exceptions for aruba (electricitymaps#1179)
Browse files Browse the repository at this point in the history
* Added missing unzip to container needed by topogen.sh

* Added topogen.sh as a volume to the container, to modify it from outside

* Added missing third_party_maps to docker.

* Added "lessSimplify:true" to zones to not hide small zone like Aruba

* Changes to moreDetails after review

* Sorted alphabetically
  • Loading branch information
pascalheraud authored and corradio committed Mar 8, 2018
1 parent a34ed26 commit 2d9a11a
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 8 deletions.
11 changes: 8 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ services:
- NODE_ENV=development
ports: ['8000:8000']
volumes:
- './web/src:/home/web/src'
- './config:/home/config'
- './web/generate-geometries.js:/home/web/generate-geometries.js'
- './web/locales:/home/web/locales'
- './web/package.json:/home/web/package.json'
- './web/public:/home/web/public'
- './web/server.js:/home/web/server.js'
- './web/src:/home/web/src'
- './web/third_party_maps:/home/web/third_party_maps'
- './web/topogen.sh:/home/web/topogen.sh'
- './web/views:/home/web/views'
- './web/webpack.config.js:/home/web/webpack.config.js'
- './web/locales:/home/web/locales'
- './config:/home/config'


1 change: 1 addition & 0 deletions web/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ WORKDIR /home/web

ADD web/package.json /home/web/package.json
ADD web/package-lock.json /home/web/package-lock.json
RUN apt-get update && apt-get install -y unzip
RUN npm install

ADD web /home/web
Expand Down
54 changes: 50 additions & 4 deletions web/generate-geometries.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const zoneDefinitions = [
// Map between "zones" iso_a2 and adm0_a3 in order to support XX, GB etc..
// Note that the definition of "zones" is very vague here..
// Specific case of Kosovo and Serbia: considered as a whole as long as they will be reported together in ENTSO-E.
// Add moreDetails:true to use a smaller threshold for simplifying a zone thus the zone will have more details. More details also means bigger world.json so use with small zones.
{zoneName:'XX', type:'country', id:'CYN'},

// List of all zones
Expand All @@ -110,7 +111,7 @@ const zoneDefinitions = [
{zoneName: 'AUS-TAS', countryId: 'AUS', stateId: 'AU.TS', type: 'state'},
{zoneName: 'AUS-VIC', countryId: 'AUS', stateId: 'AU.VI', type: 'state'},
{zoneName: 'AUS-WA', countryId: 'AUS', stateId: 'AU.WA', type: 'state'},
{zoneName: 'AW', type: 'country', id: 'ABW'},
{zoneName: 'AW', type: 'country', id: 'ABW', moreDetails: true},
{zoneName: 'AX', type: 'country', id: 'ALA'},
{zoneName: 'AZ', type: 'country', id: 'AZE'},
//{zoneName: 'BA', type: 'country', id: 'BIH'},
Expand Down Expand Up @@ -551,13 +552,50 @@ const toListOfFeatures = (zones) => {
});
};

// create zones from definitions
//Adds the zones from topo2 to topo1
function mergeTopoJsonSingleZone(topo1, topo2) {
let srcArcsLength = topo1.arcs.length;
// Copy Zones from topo2 to topo1
Object.keys(topo2.objects).forEach(zoneName=>{
topo1.objects[zoneName]=topo2.objects[zoneName];
// Relocate arc into zone by adding srcArcsLength
topo1.objects[zoneName].arcs.forEach(arcList1=>{
arcList1.forEach(arcList2=>{
for(i=0; i<arcList2.length; i++) {
arcList2[i]+=srcArcsLength;
}
});
});
});

// Add arcs from topo2
topo2.arcs.forEach(arc=> {
topo1.arcs.push(arc);
});
}

// create zones from definitions, avoid zones having moreDetails==true
let zones = {};
zoneDefinitions.forEach(zone => {
if (zone.zoneName in zones)
throw ('Warning: ' + zone.zoneName + ' has duplicated entries. Each zoneName must be present ' +
'only once in zoneDefinitions');
zones[zone.zoneName] = getDataForZone(zone, true);
// Avoid zone with moreDetails
if ( !('moreDetails' in zone) || !zone.moreDetails) {
zones[zone.zoneName] = getDataForZone(zone, true);
}
});

// create zonesMoreDetails by getting zone having moreDetails===true
let zonesMoreDetails = {};
zoneDefinitions.forEach(zone => {
// Take only zones having modeDetails
if (('moreDetails' in zone) && zone.moreDetails) {
if (zone.zoneName in zonesMoreDetails || zone.zoneName in zones)
throw ('Warning: ' + zone.zoneName + ' has duplicated entries. Each zoneName must be present ' +
'only once in zoneDefinitions');
zonesMoreDetails[zone.zoneName] = getDataForZone(zone, true);
}
});

// We do not want to merge states
Expand All @@ -580,11 +618,19 @@ zoneFeatures = toListOfFeatures(zoneFeaturesInline);
// Write unsimplified list of geojson, without state merges
fs.writeFileSync('build/zonegeometries.json', zoneFeatures.map(JSON.stringify).join('\n'));

// Simplify
// Simplify all countries
const topojson = require('topojson');
let topo = topojson.topology(zones);
topo = topojson.presimplify(topo);
topo = topojson.simplify(topo, 0.01);

// Simplify to 0.001 zonesMoreDetails zones
topoMoreDetails = topojson.topology(zonesMoreDetails);
topoMoreDetails = topojson.presimplify(topoMoreDetails);
topoMoreDetails = topojson.simplify(topoMoreDetails, 0.001);
// Merge topoMoreDetails into topo
mergeTopoJsonSingleZone(topo, topoMoreDetails);

topo = topojson.filter(topo, topojson.filterWeight(topo, 0.01));
topo = topojson.quantize(topo, 1e5);
fs.writeFileSync('src/world.json', JSON.stringify(topo));
2 changes: 1 addition & 1 deletion web/src/world.json

Large diffs are not rendered by default.

0 comments on commit 2d9a11a

Please sign in to comment.