Skip to content

Instantly share code, notes, and snippets.

@evenevan
Last active June 29, 2024 16:51
Show Gist options
  • Save evenevan/042e465de022b39a26676a48bb9390b9 to your computer and use it in GitHub Desktop.
Save evenevan/042e465de022b39a26676a48bb9390b9 to your computer and use it in GitHub Desktop.
mostly a note for myself - getting sentinel-2 data

creating a .mbtile from a .jp2 from a sentinel-2 dataset for map tiling

download the esa sentinel-2 data zip

https://dataspace.copernicus.eu/explore-data/data-collections/sentinel-data/sentinel-2

  • press the green "explore sentinel-2 data"

https://sentiwiki.copernicus.eu/web/sentinel-2

  • the downloaded files should be as described here

the file of interest is probably the one with TCI (true color image) in the filename. for me it is a .jp2 file.

using gdal to do processing of the tdi .jp2 https://github.com/OSGeo/gdal/tree/master/docker

  • install in docker environment
docker run --rm -v c:\Users\username:/home ghcr.io/osgeo/gdal:ubuntu-small-latest gdal_translate /home/T10UEV_20240509T190921_TCI_10m.jp2 /home/test.mbtiles

the command is not pretty

get more zoom levels with gdladdo. this only increases the amount you can zoom out. zoom in is determined by the pixel density i think. the number of numbers at the end represent how many zoom levels to add

docker run --rm -v c:\Users\username:/home ghcr.io/osgeo/gdal:ubuntu-small-latest gdaladdo /home/test.mbtiles 2 4 8 16 32 64 128 256 512 1024

this is an upgrade to the base translate command. the 8,8 increases the output resolution (smaller = more detail). decently sure the 8,8 means 1 pixel per 8 meters in both the x and y directions. use this to be able to zoom in more. command takes a very long time to run.

docker run --rm -v c:\Users\User:/home ghcr.io/osgeo/gdal:ubuntu-small-latest gdal_translate -tr 8 8 /home/test1.mbtiles /home/test2.mbtiles

mosaic

https://s2maps.eu/?downloadservice# https://open.esa.int/open-copernicus-sentinel-2-data-turned-into-a-global-cloudless-mosaic/ https://www.copernicus.eu/en/sentinel-2-cloudless-mosaic-first-global-almost-cloud-free-view-planet https://land.copernicus.eu/en/products/global-image-mosaic?tab=main https://s2gm.land.copernicus.eu/mosaic-hub

mosaics are available of the sentinel-2 data. the last link has a tool for ordering and downloading custom shape mosaics.

up to date documentation on s2gm is at https://s2gm.land.copernicus.eu/help/documentation

settings

  • the advanced menu gives a choice for output, i find .tif to be easier to work with.
  • use a compositing period of at least a quarter to avoid clouds

these are the exact settings i used

{
      ...
      "configuration": {
        "aoi": {
          "type": "Polygon",
          "coordinates": [
            [
              [
                -116.76427144,
                49.23679239
              ],
              [
                -116.76427144,
                53.73349954
              ],
              [
                -109.51835022,
                53.73349954
              ],
              [
                -109.51835022,
                49.23679239
              ],
              [
                -116.76427144,
                49.23679239
              ]
            ]
          ]
        },
        "srs": "WGS84",
        "do_nir": false,
        "date_to": "2023-09-30",
        "date_from": "2023-07-01",
        "cloud_mask": [
          "ESA",
          "LX"
        ],
        "resolution": "10",
        "output_format": "geotiff",
        "temporal_resolution": "QUARTER"
      },
      ...
    }

processing

combine the output tifs into one mega tif. prepare list of .tif as described https://gdal.org/programs/gdal_merge.html#passing-a-large-list-of-files-to-gdal-merge

docker run --rm -v c:\Users\User:/home ghcr.io/osgeo/gdal:ubuntu-small-latest gdal_merge -o /home/mosaic.tif --optfile /home/tif.txt

translate the "mega" tif into .mbtiles

docker run --rm -v c:\Users\User:/home ghcr.io/osgeo/gdal:ubuntu-small-latest gdal_translate -co "ZOOM_LEVEL_STRATEGY=UPPER" -co "RESAMPLING=NEAREST" -of MBTILES /home/mosaic.tif /home/mosaic.mbtiles

increase zoom in

docker run --rm -v c:\Users\User:/home ghcr.io/osgeo/gdal:ubuntu-small-latest gdal_translate -tr 5.0 5.0 /home/mosaic.mbtiles /home/mosaic-res.mbtiles

increase zoom out

docker run --rm -v c:\Users\User:/home ghcr.io/osgeo/gdal:ubuntu-small-latest gdaladdo /home/mosaic-res.mbtiles 2 4 8 16 32 64 128 256 512 1024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment