Hello
I was in need to generate tiles from a geotiff to publish the image as a
tms-service. So i was happy to find the gdal2tiles.py script which does
the job.

The only issue i stumbled over:
gdal2tiles.py generates the tiles in the google format(0,0=top-left) , i
need the tms format(0,0=bottom-left). I  looked at the script  and found
 something not  so nice:
The generation of the tile-filename is with redundancy of 3 times  in
the script.

So i wrote a little patch to keep the generation of the tile-filename in
a single place.  This is a better base for further development of the
script.

best regards
   martin
diff -r faa5dfbf6110 swig/python/scripts/gdal2tiles.py
--- a/swig/python/scripts/gdal2tiles.py	Wed Apr 13 21:09:47 2011 +0200
+++ b/swig/python/scripts/gdal2tiles.py	Wed Apr 13 21:10:01 2011 +0200
@@ -1139,6 +1139,10 @@
 					f.close()
 		
 	# -------------------------------------------------------------------------
+	
+	def tilefilename(self, x, y, z):
+		return(os.path.join( self.output, str(z), str(x), "%s.%s" % (y, self.tileext)))
+			
 	def generate_base_tiles(self):
 		"""Generation of the base tiles (the lowest in the pyramid) directly from the input raster"""
 		
@@ -1183,7 +1187,7 @@
 				if self.stopped:
 					break
 				ti += 1
-				tilefilename = os.path.join(self.output, str(tz), str(tx), "%s.%s" % (ty, self.tileext))
+				tilefilename = self.tilefilename(tx,ty,tz)
 				if self.options.verbose:
 					print(ti,'/',tcount, tilefilename) #, "( TileMapService: z / x / y )"
 
@@ -1326,7 +1330,7 @@
 						break
 						
 					ti += 1
-					tilefilename = os.path.join( self.output, str(tz), str(tx), "%s.%s" % (ty, self.tileext) )
+					tilefilename = self.tilefilename(tx,ty,tz)
 
 					if self.options.verbose:
 						print(ti,'/',tcount, tilefilename) #, "( TileMapService: z / x / y )"
@@ -1358,7 +1362,7 @@
 						for x in range(2*tx,2*tx+2):
 							minx, miny, maxx, maxy = self.tminmax[tz+1]
 							if x >= minx and x <= maxx and y >= miny and y <= maxy:
-								dsquerytile = gdal.Open( os.path.join( self.output, str(tz+1), str(x), "%s.%s" % (y, self.tileext)), gdal.GA_ReadOnly)
+								dsquerytile = gdal.Open(self.tilefilename(x,y,tz+1), gdal.GA_ReadOnly)
 								if (ty==0 and y==1) or (ty!=0 and (y % (2*ty)) != 0):
 									tileposy = 0
 								else:
_______________________________________________
gdal-dev mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/gdal-dev

Reply via email to