DEV Community

Cover image for Building a Dynamic Tile Server Using Cloud Optimized GeoTIFF(COG) with TiTiler
Yasunori Kirimoto for MIERUNE

Posted on

Building a Dynamic Tile Server Using Cloud Optimized GeoTIFF(COG) with TiTiler

img

I built a dynamic tile server using Cloud Optimized GeoTIFF (COG) with TiTiler!

TiTiler is a dynamic tile server built on FastAPI and Rasterio/GDAL. Its main features include support for Cloud Optimized GeoTIFF(COG), multiple projection methods, various output formats (JPEG, JP2, PNG, WEBP, GTIFF, NumpyTile), WMTS, and virtual mosaic. It also provides Lambda and ECS deployment environments using AWS CDK.

Advance Preparation

The sample data used this time is in Cloud Optimized GeoTIFF (COG) format, which can be obtained from the Registry of Open Data on AWS provided by AWS.

img

I selected the COG of "Sentinel-2".
https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/54/T/WN/2023/8/S2A_54TWN_20230815_0_L2A/TCI.tif

img

Install & launch TiTiler

Install TiTiler. This time, we will use Docker to start it locally.

Clone the TiTiler repository.



git clone https://github.com/developmentseed/titiler.git
cd titiler


Enter fullscreen mode Exit fullscreen mode

Start TiTiler.



docker-compose up --build titiler


Enter fullscreen mode Exit fullscreen mode

img

After launching, go to "http://localhost:8000". The TiTiler top page will appear.
img

You can check the actual usage by looking at the API documentation.
img

Obtaining basic data information

First, basic data information is acquired.

Select "/cog/info" → enter COG URL in Dataset URL → click "Execute."
img

Basic information on the target data can be obtained in JSON.



{
  "bounds": [
    140.99975320947394,
    42.356322389620374,
    142.3544473299751,
    43.35285539188815
  ],
  "minzoom": 7,
  "maxzoom": 13,
  "band_metadata": [
    [
      "b1",
      {}
    ],
    [
      "b2",
      {}
    ],
    [
      "b3",
      {}
    ]
  ],
  "band_descriptions": [
    [
      "b1",
      ""
    ],
    [
      "b2",
      ""
    ],
    [
      "b3",
      ""
    ]
  ],
  "dtype": "uint8",
  "nodata_type": "Nodata",
  "colorinterp": [
    "red",
    "green",
    "blue"
  ],
  "driver": "GTiff",
  "count": 3,
  "width": 10980,
  "height": 10980,
  "overviews": [
    2,
    4,
    8,
    16
  ],
  "nodata_value": 0
}


Enter fullscreen mode Exit fullscreen mode

Displaying data in a viewer

Next, display the target data in the default viewer provided by TiTiler!

Select the "/cog/viewer" entry. Then, by accessing "http://localhost:8000/cog/viewer" directly, the viewer screen will appear.
img

Access the viewer → Input COG URL → Click "Apply."
img

The target data is displayed on the viewer. You can also try zooming in/out and setting parameters.
img

Obtaining basic information in GeoJSON format

Next, get basic information in GeoJSON format and display it in QGIS.

Use the API of "/cog/info.geojson" to read GeoJSON format data in QGIS.



http://localhost:8000/cog/info.geojson?url=https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/54/T/WN/2023/8/S2A_54TWN_20230815_0_L2A/TCI.tif


Enter fullscreen mode Exit fullscreen mode

img

You can see the range polygons of the target data and the basic information in the attributes.
img

Obtaining XYZ Tiles

Next, get the raster tiles in XYZ Tiles format and display them in QGIS.

Use the API "/cog/tiles" and read XYZ Tiles raster tiles in QGIS.



http://localhost:8000/cog/tiles/WebMercatorQuad/{z}/{x}/{y}.png?url=https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/54/T/WN/2023/8/S2A_54TWN_20230815_0_L2A/TCI.tif


Enter fullscreen mode Exit fullscreen mode

img

You can see that the target data is dynamically delivered in XYZ Tiles.
img

Obtaining WMTS

Finally, get the raster tiles in WMTS format and display them in QGIS.

Use the API in "/cog/WMTSCapabilities.xml" to load WMTS raster tiles in QGIS.



http://localhost:8000/cog/WMTSCapabilities.xml?url=https://sentinel-cogs.s3.us-west-2.amazonaws.com/sentinel-s2-l2a-cogs/54/T/WN/2023/8/S2A_54TWN_20230815_0_L2A/TCI.tif


Enter fullscreen mode Exit fullscreen mode

img

You can see that the target data is dynamically delivered in WMTS.
img

The TiTiler can easily deliver dynamic tile in various formats by specifying the data URL! Static tile delivery is suitable for simple raster tile delivery, but dynamic tile delivery is also a choice when various formats or special processing is required.

TiTiler comes standard with a built-in viewer for immediate data visualization. In addition, a deployment environment to Lambda and ECS is available using AWS CDK, and detailed documentation is provided.

There are many other features that were unable to introduce in this article, so please try them out for yourself!

Related Articles

References
TiTiler
QGIS

Top comments (0)