Skip to content

Instantly share code, notes, and snippets.

@wipfli
Last active January 7, 2024 18:29
Show Gist options
  • Save wipfli/6386f21fa19af978dc9e1f136a754024 to your computer and use it in GitHub Desktop.
Save wipfli/6386f21fa19af978dc9e1f136a754024 to your computer and use it in GitHub Desktop.

Vector Landcover Notes

I would like to be able to make myself one day a vector landcover tileset that looks as good as the ones of the large consumer maps. I tried doing this a bit but so far I have not found a good solution.

The landcover should give you an idea how the nature looks like in a place, whatever that means...

In this gist I would like to write down some notes around the challenges of making a vector landcover tileset.

Related to onthegomap/planetiler#550

Landcover vs Climate Zone

As data source one would use a satellite observation with global coverage. There are some open data landcover datasets. For example, this sentinel-2 data set. The classes in this data set are related to what plants grow and if you look at the Alps, then there will be a progression from low to high altitudes from "rangeland", "bare ground", to "snow/ice". But "bare ground" is also used for deserts. So if you only use a landcover dataset, you have to show deserts in the same color as mid-heights in the Alps. And that does not look so great. Example

To solve that problem, one can use information from a climate zone dataset. This one here is with 1 km per pixel the highest resolution I could find. However, the landcover dataset above has 10 m per pixel, so there is a 2 orders of magnitude mismatch between the resolutions of the landcover and the climate zone dataset.

Projection

The landcover data comes in a projection which is different from web mercator which we use for vector tiles. This means that pixels size depends on where you are in the world. And filtering and polygon simplification has different effects afterwards.

Downsampling

The landcover raster dataset comes as geotif where each pixel is 10 m or so. This is roughly z14 for raster tiles I think. So for z14, we can use that data directly. But if we want to use it for lower zooms and global overviews, we have to downsample it. One can do this with GDAL and it has some algorithm like majority vote or whatever, but the problem is that you end up with very small islands of pixels with the same landcover. The image looks noisy and if you vectorize it, you just get a lot of small polygons. The many small polygons increase the size of your vector tiles and they make the map visually nervous. So it is bad.

People apply polygon simplification after vectorization to decrease the tile size but if you do it too much, the polygons will just look like triangles and you get a triangle chaos map.

I found that before vectorization it helps to reduce spatial noise by applying an image filter like for example a median filter. https://github.com/wipfli/median-filter-landcover

Upsampling

Another question is what do you do for high zoom levels. If you just vectorize your landcover for z14, then you will see all the pixel outlines. A 45 degree boundary between forest and grass for example will look like a stair instead of a straight line.

I never tried it at global scale, but for small extracts I found that there are spline upsampling algorithms that turn a 1 pixel forest into a nice round blob. Maybe something like that could be use to show forests at z14 from the landcover dataset...

@wipfli
Copy link
Author

wipfli commented Sep 20, 2023

ESA world cover is CC-BY https://worldcover2020.esa.int/download

@dBitech
Copy link

dBitech commented Sep 21, 2023

it looks like Mapbox-gl V3 has new styling abilities for on-the-fly client-side styling for these kinds of raster datasets. https://medium.com/earthrisemedia/growing-food-in-pixels-eba2e2a288f1

@wipfli
Copy link
Author

wipfli commented Jan 7, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment