LinuxCommandLibrary

gdal2tiles.py

Create map tiles from geospatial raster data

TLDR

Generate TMS tiles for the zoom levels 2 to 5 of a raster dataset

$ gdal2tiles.py --zoom 2-5 [path/to/input.tif] [path/to/output_directory]
copy

Generate XYZ tiles for the zoom levels 2 to 5 of a raster dataset
$ gdal2tiles.py --zoom 2-5 --xyz [path/to/input.tif] [path/to/output_directory]
copy

SYNOPSIS

gdal2tiles.py [options] input_file output_dir

PARAMETERS

-p
    Tiling profile: raster (default), mercator, geodetic. mercator is equivalent to EPSG:3857 and geodetic to EPSG:4326. Raster tiles in original georeference.

-r
    Resampling method: average (default), near, bilinear, cubic, cubicspline, lanczos, antialias.
Used for generating overview tiles (smaller sized).

-s
    Override target SRS (coordinate system) of the output tiles. Overrides the auto-detection based on the selected tiling profile. Should be given as an EPSG code (eg EPSG:4326) or WKT definition.

-z
    Zoom level range to generate (e.g. 2-5 or 10). Default is to automatically determine the full zoom range.

-e
    Generate Google Earth KML file for viewing the generated tiles. Uses Regionate to support large datasets.

-a
    NODATA transparency value to assign to the input data.

-q
    Disable progress messages. Quieter execution.

-v
    Generate verbose output messages.

--processes=
    Number of workers to use for processing tiles.

--version
    Show program's version number and exit

--help
    Show help message and exit

input_file
    The input raster file to be processed.

output_dir
    The directory where the generated tiles will be stored.

--tmscompatible
    When using with the raster profile, causes the output tile directory structure to be compatible with the Tile Map Service (TMS) specification, i.e. a bottom-left origin instead of top-left. (GDAL >= 2.1)

DESCRIPTION

gdal2tiles.py is a Python script that creates web-ready tile pyramids from geospatial raster data. It takes a raster image as input and generates a directory structure of tiles suitable for use with tile servers like Leaflet, OpenLayers, or Google Maps API. It efficiently processes large datasets, creating multiple zoom levels of tiles. These tiles are organized based on standard tiling schemes such as Google Maps compatible tile pyramid, allowing for progressive loading of map data in web applications, thereby providing an interactive and responsive user experience. The tool provides options to select tile format (PNG, JPEG, WebP), tiling profile (geodetic, raster), and resampling methods, which gives users precise control over the tiles generated. It can handle various geospatial raster formats supported by GDAL. It's commonly used for publishing large geospatial datasets on the web.

CAVEATS

Requires GDAL (Geospatial Data Abstraction Library) and its Python bindings to be installed. Performance can be affected by I/O speed and available memory.

TILE FORMATS

gdal2tiles.py supports various tile formats, including PNG, JPEG and WebP. PNG is suitable for rasters with transparency, while JPEG is more efficient for photographic imagery, and WebP offers better compression and quality than JPEG. The choice of format depends on the specific requirements of the application.

RESAMPLING METHODS

The resampling method controls how the pixel values are calculated when creating overview tiles. Different methods offer different trade-offs between speed and quality. The default 'average' method provides a good balance, while other methods like 'near', 'bilinear', 'cubic', 'cubicspline', 'lanczos', and 'antialias' may be more appropriate depending on the specific data and desired outcome.

GDAL VERSION

Specific features and options available in gdal2tiles.py might depend on the version of GDAL installed. Always refer to the documentation corresponding to your GDAL version for accurate information.

HISTORY

gdal2tiles.py was originally developed as part of the GDAL project to simplify the process of creating tile pyramids for web mapping applications. It has evolved over time with various improvements and features, including support for different tiling profiles, resampling methods, and output formats. It is now a widely used tool in the geospatial community for preparing raster data for web-based visualization.

SEE ALSO

Copied to clipboard