Skip to content

Commit

Permalink
Merge pull request #106 from nzzdev/release-2.6.0
Browse files Browse the repository at this point in the history
Release 2.6.0
  • Loading branch information
fromdusttilldawn authored Dec 2, 2022
2 parents 7ce8bd3 + cf0b70a commit 406db03
Show file tree
Hide file tree
Showing 11 changed files with 222 additions and 66 deletions.
29 changes: 29 additions & 0 deletions basemaps/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions basemaps/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
"author": "",
"license": "MIT",
"dependencies": {
"d3-geo": "^1.12.1",
"d3-geo-projection": "^2.9.0",
"form-data": "^4.0.0",
"nano": "^8.2.1",
"node-fetch": "^2.6.1",
Expand Down
20 changes: 10 additions & 10 deletions basemaps/prepare-basemaps/01-generate-basemaps/helpers.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
const shell = require("shelljs");
const fs = require("fs");

function convertToGeojson(inputPath, outputPath, commandExtension) {
function convertToGeojson(inputFilePath, outputFilePath, commandExtension) {
shell.exec(
`npx mapshaper -i ${inputPath} encoding=utf8 -proj wgs84 ${commandExtension} -o ${outputPath} force format=geojson`
`npx mapshaper -i ${inputFilePath} encoding=utf8 -proj wgs84 ${commandExtension} -o ${outputFilePath} force format=geojson`
);
}

Expand All @@ -26,8 +26,8 @@ function rewritePropertyValue(propertyValue, propertyValuesToRewrite) {
return propertyValue;
}

function setProperties(fileName, propertyMapping, propertyValuesToRewrite) {
const geojson = require(fileName);
function setProperties(inputFilePath, propertyMapping, propertyValuesToRewrite) {
const geojson = require(inputFilePath);
for (let feature of geojson.features) {
const properties = {};

Expand All @@ -50,7 +50,7 @@ function setProperties(fileName, propertyMapping, propertyValuesToRewrite) {

feature.properties = properties;
}
fs.writeFileSync(fileName, JSON.stringify(geojson));
fs.writeFileSync(inputFilePath, JSON.stringify(geojson));
}

/**
Expand Down Expand Up @@ -86,22 +86,22 @@ function addProperties(outputFilePath, groupedProperties) {
}
}

function convertToTopojson(path, name) {
function convertToTopojson(inputFilePath, name, commandExtension = "") {
shell.exec(
`npx mapshaper -i ${path} encoding=utf8 -proj wgs84 -rename-layers ${name} -o ${path} force format=topojson `
`npx mapshaper -i ${inputFilePath} encoding=utf8 -proj init=wgs84 -rename-layers ${name} ${commandExtension} -o ${inputFilePath} force format=topojson `
);
}

function mergeTopojsons(firstPath, secondPath, outputPath) {
function mergeTopojsons(firstPath, secondPath, outputFilePath) {
shell.exec(
`npx mapshaper -i combine-files ${firstPath} ${secondPath} -o ${outputPath} force format=topojson`
`npx mapshaper -i combine-files ${firstPath} ${secondPath} -o ${outputFilePath} force format=topojson`
);
}

module.exports = {
setProperties,
addProperties,
convertToGeojson,
convertToTopojson,
mergeTopojsons,
setProperties,
};
24 changes: 24 additions & 0 deletions basemaps/prepare-basemaps/config/basemaps.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,4 +651,28 @@ module.exports = [
},
],
},
{
id: "europe-countries-geographic",
title: "Europa » Länder",
versions: [
{
validFrom: "2022-01-01T00:00:00.000Z",
data: {
source: {
url: "https://www.naturalearthdata.com/",
label: "© Natural Earth",
},
config: {
defaultEntityType: "name",
entityTypes: {
name: "Name",
iso3: "ISO-Code",
},
projection: "d3.geoIdentity",
},
entities: require("./basemaps/europe-countries-geographic.js"),
},
},
],
},
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
const fs = require("fs");
const d3Geo = require("d3-geo");
const d3GeoProj = require("d3-geo-projection");

const config = {
featuresFile: "FINAL_laender_fuer_choropleth_europa.json",
featuresPropertyMapping: {
name: "NAME_EN",
iso3: "ADM0_A3_UA",
showAsBubble: "showAsBubble",
},
rewriteProperties: {},
};

module.exports = {
download: async function (basemap, version) {
console.log("Nothing to download. Please copy the GeoJSON file(s) to here:", `${__dirname}/../../00-download-basemaps/data/${basemap.id}/${version.validFrom}/`);
},
transform: async function (helpers, basemap, version) {
const inputFeaturesPath = `${__dirname}/../../00-download-basemaps/data/${basemap.id}/${version.validFrom}/${config.featuresFile}`;
const outputFeaturesPath = `${__dirname}/../../01-generate-basemaps/data/${basemap.id}/${version.validFrom}/${config.featuresFile}`;

// read geojson and project the data using the azimuthalEqualArea projection
// example: https://observablehq.com/@recifs/project-and-clip
const projectedBaseMap = d3GeoProj.geoProject(
JSON.parse(
fs.readFileSync(
inputFeaturesPath,
"utf-8"
)
),
d3Geo.geoAzimuthalEqualArea()
// rotate whole map, so europe is centered correctly
.rotate(
[-10, -52]
)
// add a "bounding box" around europe, because we have to cut some countries (e.g. Russia is way too big)
.fitSize(
[100, 100],
{
type: "MultiPoint",
coordinates: [ [-10, 27], [60, 65] ]
}
)
// clip everything outside the bounding box
.clipExtent(
[ [0, 0], [100, 100] ]
)
);

// export the projected data as a geojson
fs.writeFileSync(
outputFeaturesPath,
JSON.stringify(projectedBaseMap)
);

// map properties using featuresPropertyMapping from config above
helpers.setProperties(
outputFeaturesPath,
config.featuresPropertyMapping,
config.rewriteProperties
);

// convert to TopoJSON, simplify geometries and clip to bounding box
helpers.convertToTopojson(
outputFeaturesPath,
"features",
`-simplify 15% keep-shapes`
);
},
};
Loading

0 comments on commit 406db03

Please sign in to comment.