Skip to content

Commit

Permalink
feat(data-layers): improve land-cover tiles and legend (#520)
Browse files Browse the repository at this point in the history
  • Loading branch information
pwambach authored Aug 26, 2020
1 parent adecd99 commit e6cdb96
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 1 addition & 1 deletion data/gdal-reproject.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ for file in $(find $FOLDER -name *.nc -type f | sort -n); do
--tmscompatible \
--no-kml \
--webviewer=none \
--resampling near \
--resampling average \
--s_srs EPSG:4326 \
./colored.tif /data/images/$VARIABLE/$timestamp_counter
else
Expand Down
11 changes: 10 additions & 1 deletion scripts/generate-legend-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,33 @@ variables.forEach(variable => {
const min = colorRamp[colorRamp.length - 1][0];
const range = max - min;

let lastColor = null;

colorRamp.forEach(colorStop => {
const [value, r, g, b, a] = colorStop;
const stop = 1 - (value - min) / range;

const alpha = Number(a) / 255;
const hasAlpha = !isNaN(a);
const color = `rgb${hasAlpha ? 'a' : ''}(${r}, ${g}, ${b}${
hasAlpha ? `, ${alpha}` : ''
})`;

if (variable === 'lccs_class' && lastColor) {
gradient.addColorStop(stop - 0.001, lastColor);
}

gradient.addColorStop(stop, color);

lastColor = color;
});

ctx.fillStyle = gradient;
ctx.fillRect(0, 0, WIDTH, HEIGHT);

writeImage(variable, canvas);
} catch (err) {
console.log(`No colors file found for ${variable}`);
console.log(`No colors file found for ${variable}`, err);
return;
}
});
Expand Down
Binary file modified storage/legend-images/lccs_class.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit e6cdb96

Please sign in to comment.