gdal2tiles package¶
Submodules¶
gdal2tiles.gdal2tiles module¶
-
class
gdal2tiles.gdal2tiles.
GDAL2Tiles
(input_file, output_folder, options)[source]¶ Bases:
object
-
generate_base_tiles
()[source]¶ Generation of the base tiles (the lowest in the pyramid) directly from the input raster
-
generate_googlemaps
()[source]¶ Template for googlemaps.html implementing Overlay of tiles for ‘mercator’ profile. It returns filled string. Expected variables: title, googlemapskey, north, south, east, west, minzoom, maxzoom, tilesize, tileformat, publishurl
-
generate_leaflet
()[source]¶ Template for leaflet.html implementing overlay of tiles for ‘mercator’ profile. It returns filled string. Expected variables: title, north, south, east, west, minzoom, maxzoom, tilesize, tileformat, publishurl
-
generate_metadata
()[source]¶ Generation of main metadata files and HTML viewers (metadata related to particular tiles are generated during the tile processing).
-
generate_openlayers
()[source]¶ Template for openlayers.html implementing overlay of available Spherical Mercator layers.
It returns filled string. Expected variables: title, bingkey, north, south, east, west, minzoom, maxzoom, tilesize, tileformat, publishurl
-
generate_tilemapresource
()[source]¶ - Template for tilemapresource.xml. Returns filled string. Expected variables:
- title, north, south, east, west, isepsg4326, projection, publishurl, zoompixels, tilesize, tileformat, profile
-
geo_query
(ds, ulx, uly, lrx, lry, querysize=0)[source]¶ For given dataset and query in cartographic coordinates returns parameters for ReadRaster() in raster coordinates and x/y shifts (for border tiles). If the querysize is not given, the extent is returned in the native resolution of dataset ds.
raises Gdal2TilesError if the dataset does not contain anything inside this geo_query
-
-
class
gdal2tiles.gdal2tiles.
GlobalGeodetic
(tmscompatible, tileSize=256)[source]¶ Bases:
object
Functions necessary for generation of global tiles in Plate Carre projection, EPSG:4326, “unprojected profile”.
Such tiles are compatible with Google Earth (as any other EPSG:4326 rasters) and you can overlay the tiles on top of OpenLayers base map.
Pixel and tile coordinates are in TMS notation (origin [0,0] in bottom-left).
What coordinate conversions do we need for TMS Global Geodetic tiles?
Global Geodetic tiles are using geodetic coordinates (latitude,longitude) directly as planar coordinates XY (it is also called Unprojected or Plate Carre). We need only scaling to pixel pyramid and cutting to tiles. Pyramid has on top level two tiles, so it is not square but rectangle. Area [-180,-90,180,90] is scaled to 512x256 pixels. TMS has coordinate origin (for pixels and tiles) in bottom-left corner. Rasters are in EPSG:4326 and therefore are compatible with Google Earth.
LatLon <-> Pixels <-> Tiles- WGS84 coordinates Pixels in pyramid Tiles in pyramid
- lat/lon XY pixels Z zoom XYZ from TMS
- EPSG:4326
- .—-. —-
/ <-> /——–/ <-> TMS / /————–/
—– /——————–/WMS, KML Web Clients, Google Earth TileMapService
-
LonLatToPixels
(lon, lat, zoom)[source]¶ Converts lon/lat to pixel coordinates in given zoom of the EPSG:4326 pyramid
-
class
gdal2tiles.gdal2tiles.
GlobalMercator
(tileSize=256)[source]¶ Bases:
object
Functions necessary for generation of tiles in Spherical Mercator projection, EPSG:3857.
Such tiles are compatible with Google Maps, Bing Maps, Yahoo Maps, UK Ordnance Survey OpenSpace API, … and you can overlay them on top of base maps of those web mapping applications.
Pixel and tile coordinates are in TMS notation (origin [0,0] in bottom-left).
What coordinate conversions do we need for TMS Global Mercator tiles:
LatLon <-> Meters <-> Pixels <-> Tile WGS84 coordinates Spherical Mercator Pixels in pyramid Tiles in pyramid lat/lon XY in meters XY pixels Z zoom XYZ from TMS EPSG:4326 EPSG:3857 .----. --------- -- TMS / \ <-> | | <-> /----/ <-> Google \ / | | /--------/ QuadTree ----- --------- /------------/ KML, public WebMapService Web Clients TileMapService
What is the coordinate extent of Earth in EPSG:3857?
[-20037508.342789244, -20037508.342789244, 20037508.342789244, 20037508.342789244] Constant 20037508.342789244 comes from the circumference of the Earth in meters, which is 40 thousand kilometers, the coordinate origin is in the middle of extent. In fact you can calculate the constant as: 2 * math.pi * 6378137 / 2.0 $ echo 180 85 | gdaltransform -s_srs EPSG:4326 -t_srs EPSG:3857 Polar areas with abs(latitude) bigger then 85.05112878 are clipped off.What are zoom level constants (pixels/meter) for pyramid with EPSG:3857?
whole region is on top of pyramid (zoom=0) covered by 256x256 pixels tile, every lower zoom level resolution is always divided by two initialResolution = 20037508.342789244 * 2 / 256 = 156543.03392804062What is the difference between TMS and Google Maps/QuadTree tile name convention?
The tile raster itself is the same (equal extent, projection, pixel size), there is just different identification of the same raster tile. Tiles in TMS are counted from [0,0] in the bottom-left corner, id is XYZ. Google placed the origin [0,0] to the top-left corner, reference is XYZ. Microsoft is referencing tiles by a QuadTree name, defined on the website: http://msdn2.microsoft.com/en-us/library/bb259689.aspxThe lat/lon coordinates are using WGS84 datum, yes?
Yes, all lat/lon we are mentioning should use WGS84 Geodetic Datum. Well, the web clients like Google Maps are projecting those coordinates by Spherical Mercator, so in fact lat/lon coordinates on sphere are treated as if the were on the WGS84 ellipsoid.
From MSDN documentation: To simplify the calculations, we use the spherical form of projection, not the ellipsoidal form. Since the projection is used only for map display, and not for displaying numeric coordinates, we don’t need the extra precision of an ellipsoidal projection. The spherical projection causes approximately 0.33 percent scale distortion in the Y direction, which is not visually noticeable.
How do I create a raster in EPSG:3857 and convert coordinates with PROJ.4?
You can use standard GIS tools like gdalwarp, cs2cs or gdaltransform. All of the tools supports -t_srs ‘epsg:3857’.
For other GIS programs check the exact definition of the projection: More info at http://spatialreference.org/ref/user/google-projection/ The same projection is designated as EPSG:3857. WKT definition is in the official EPSG database.
- Proj4 Text:
- +proj=merc +a=6378137 +b=6378137 +lat_ts=0.0 +lon_0=0.0 +x_0=0.0 +y_0=0 +k=1.0 +units=m +nadgrids=@null +no_defs
- Human readable WKT format of EPSG:3857:
- PROJCS[“Google Maps Global Mercator”,
- GEOGCS[“WGS 84”,
- DATUM[“WGS_1984”,
- SPHEROID[“WGS 84”,6378137,298.257223563,
- AUTHORITY[“EPSG”,”7030”]],
AUTHORITY[“EPSG”,”6326”]],
PRIMEM[“Greenwich”,0], UNIT[“degree”,0.0174532925199433], AUTHORITY[“EPSG”,”4326”]],
PROJECTION[“Mercator_1SP”], PARAMETER[“central_meridian”,0], PARAMETER[“scale_factor”,1], PARAMETER[“false_easting”,0], PARAMETER[“false_northing”,0], UNIT[“metre”,1,
AUTHORITY[“EPSG”,”9001”]]]
-
LatLonToMeters
(lat, lon)[source]¶ Converts given lat/lon in WGS84 Datum to XY in Spherical Mercator EPSG:3857
-
MetersToLatLon
(mx, my)[source]¶ Converts XY point from Spherical Mercator EPSG:3857 to lat/lon in WGS84 Datum
-
MetersToPixels
(mx, my, zoom)[source]¶ Converts EPSG:3857 to pyramid pixel coordinates in given zoom level
-
PixelsToMeters
(px, py, zoom)[source]¶ Converts pixel coordinates in given zoom level of pyramid to EPSG:3857
-
class
gdal2tiles.gdal2tiles.
TileDetail
(**kwargs)[source]¶ Bases:
object
-
querysize
= 0¶
-
rx
= 0¶
-
rxsize
= 0¶
-
ry
= 0¶
-
rysize
= 0¶
-
tx
= 0¶
-
ty
= 0¶
-
tz
= 0¶
-
wx
= 0¶
-
wxsize
= 0¶
-
wy
= 0¶
-
wysize
= 0¶
-
-
class
gdal2tiles.gdal2tiles.
TileJobInfo
(**kwargs)[source]¶ Bases:
object
Plain object to hold tile job configuration for a dataset
-
in_srs_wkt
= 0¶
-
is_epsg_4326
= False¶
-
kml
= False¶
-
nb_data_bands
= 0¶
-
ominy
= 0¶
-
options
= None¶
-
out_geo_trans
= []¶
-
output_file_path
= ''¶
-
src_file
= ''¶
-
tile_driver
= None¶
-
tile_extension
= ''¶
-
tile_size
= 0¶
-
tmaxz
= 0¶
-
tminmax
= []¶
-
tminz
= 0¶
-
-
class
gdal2tiles.gdal2tiles.
Zoomify
(width, height, tilesize=256, tileformat='jpg')[source]¶ Bases:
object
-
gdal2tiles.gdal2tiles.
create_overview_tiles
(tile_job_info, output_folder, options)[source]¶ Generation of the overview tiles (higher in the pyramid) based on existing tiles
-
gdal2tiles.gdal2tiles.
generate_kml
(tx, ty, tz, tileext, tilesize, tileswne, options, children=None, **args)[source]¶ Template for the KML. Returns filled string.
-
gdal2tiles.gdal2tiles.
generate_tiles
(input_file, output_folder, **options)[source]¶ Generate tiles from input file.
- Arguments:
input_file
(str): Path to input file.output_folder
(str): Path to output folder.options
: Tile generation options.- Options:
profile
(str): Tile cutting profile (mercator,geodetic,raster) - default- ‘mercator’ (Google Maps compatible)
resampling
(str): Resampling method (average,near,bilinear,cubic,cubicsp- line,lanczos,antialias) - default ‘average’
s_srs
: The spatial reference system used for the source input datazoom
: Zoom levels to render; format: [int min, int max],- ‘min-max’ or int/str zoomlevel.
tile_size
(int): Size of tiles to render - default 256resume
(bool): Resume mode. Generate only missing files.srcnodata
: NODATA transparency value to assign to the input datatmscompatible
(bool): When using the geodetic profile, specifies the base- resolution as 0.703125 or 2 tiles at zoom level 0.
verbose
(bool): Print status messages to stdoutkml
(bool): Generate KML for Google Earth - default for ‘geodetic’- profile and ‘raster’ in EPSG:4326. For a dataset with different projection use with caution!
url
(str): URL address where the generated tiles are going to be publishedwebviewer
(str): Web viewer to generate (all,google,openlayers,none) -- default ‘all’
title
(str): Title of the mapcopyright
(str): Copyright for the mapgooglekey
(str): Google Maps API key from- http://code.google.com/apis/maps/signup.html
bingkey
(str): Bing Maps API key from https://www.bingmapsportal.com/nb_processes
: Number of processes to use for tiling.
-
gdal2tiles.gdal2tiles.
multi_threaded_tiling
(input_file, output_folder, **options)[source]¶ Generate tiles with multi processing.
-
gdal2tiles.gdal2tiles.
nb_data_bands
(dataset)[source]¶ Return the number of data (non-alpha) bands of a gdal dataset
-
gdal2tiles.gdal2tiles.
reproject_dataset
(from_dataset, from_srs, to_srs, options=None)[source]¶ Returns the input dataset in the expected “destination” SRS. If the dataset is already in the correct SRS, returns it unmodified
-
gdal2tiles.gdal2tiles.
scale_query_to_tile
(dsquery, dstile, tiledriver, options, tilefilename='')[source]¶ Scales down query dataset to the tile dataset
-
gdal2tiles.gdal2tiles.
setup_input_srs
(input_dataset, options)[source]¶ Determines and returns the Input Spatial Reference System (SRS) as an osr object and as a WKT representation
Uses in priority the one passed in the command line arguments. If None, tries to extract them from the input dataset
-
gdal2tiles.gdal2tiles.
setup_no_data_values
(input_dataset, options)[source]¶ Extract the NODATA values from the dataset or use the passed arguments as override if any
-
gdal2tiles.gdal2tiles.
setup_output_srs
(input_srs, options)[source]¶ Setup the desired SRS (based on options)
-
gdal2tiles.gdal2tiles.
single_threaded_tiling
(input_file, output_folder, **options)[source]¶ Generate tiles using single process.
Keep a single threaded version that stays clear of multiprocessing, for platforms that would not support it
-
gdal2tiles.gdal2tiles.
update_alpha_value_for_non_alpha_inputs
(warped_vrt_dataset, options=None)[source]¶ Handles dataset with 1 or 3 bands, i.e. without alpha channel, in the case the nodata value has not been forced by options
gdal2tiles.utils module¶
Module contents¶
Top-level package for gdal2tiles library.