Skip to content

Commit

Permalink
Added additional flag for TMS compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
Steven D. Lander committed Jul 25, 2013
1 parent e611fb8 commit 1207814
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions gdal/swig/python/scripts/gdal2tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,14 @@ class GlobalGeodetic(object):

def __init__(self, tileSize = 256):
self.tileSize = tileSize
self.resFact = 360.0 / self.tileSize
if self.options.tmscompatible:
# Defaults the resolution factor to 0.703125 (2 tiles @ level 0)
# Adhers to OSGeo TMS spec http://wiki.osgeo.org/wiki/Tile_Map_Service_Specification#global-geodetic
self.resFact = 360.0 / self.tileSize
else:
# Defaults the resolution factor to 1.40625 (1 tile @ level 0)
# Adheres OpenLayers, MapProxy, etc default resolution for TMS
self.resFact = 180.0 / self.tileSize

def LatLonToPixels(self, lat, lon, zoom):
"Converts lat/lon to pixel coordinates in given zoom of the EPSG:4326 pyramid"
Expand Down Expand Up @@ -656,6 +663,8 @@ def optparse_init(self):
help="Resume mode. Generate only missing files.")
p.add_option('-a', '--srcnodata', dest="srcnodata", metavar="NODATA",
help="NODATA transparency value to assign to the input data")
p.add_option('-g', '--tmscompatible', dest="tmscompatible", action="store_true",
help="When using the geodetic profile, specifies the base resolution as 0.703125 or 2 tiles at zoom level 0.")
p.add_option("-v", "--verbose",
action="store_true", dest="verbose",
help="Print status messages to stdout")
Expand Down Expand Up @@ -1953,6 +1962,10 @@ def generate_openlayers( self ):
args['tileformat'] = self.tileext
args['publishurl'] = self.options.url
args['copyright'] = self.options.copyright
if self.options.tmscompatible:
args['tmsoffset'] = "-1"
else:
args['tmsoffset'] = ""
if self.options.profile == 'raster':
args['rasterzoomlevels'] = self.tmaxz+1
args['rastermaxresolution'] = 2**(self.nativezoom) * self.out_gt[1]
Expand Down Expand Up @@ -2173,7 +2186,7 @@ def generate_openlayers( self ):
var res = this.getServerResolution();
var x = Math.round((bounds.left - this.tileOrigin.lon) / (res * this.tileSize.w));
var y = Math.round((bounds.bottom - this.tileOrigin.lat) / (res * this.tileSize.h));
var z = this.getServerZoom();
var z = this.getServerZoom()%(tmsoffset)s;
var path = this.serviceVersion + "/" + this.layername + "/" + z + "/" + x + "/" + y + "." + this.type;
var url = this.url;
if (OpenLayers.Util.isArray(url)) {
Expand Down

0 comments on commit 1207814

Please sign in to comment.