Opened 9 years ago

Closed 7 years ago

#6057 closed defect (fixed)

gdal2tiles.py patch for managing empty tiles

Reported by: Kurt Schwehr Owned by: warmerdam
Priority: normal Milestone:
Component: default Version: svn-trunk
Severity: normal Keywords:
Cc:

Description

Another Google engineer, Hideto Kazawa, found that gdal2tiles.py crashes for empty tiles.

swig/python/scripts/gdal2tiles.py -z 7-21 debug.tif tmp
Generating Base Tiles:
ERROR 5: Illegal values for buffer size
ERROR 5: Illegal values for buffer size
Traceback (most recent call last):
  File "./swig/python/scripts/gdal2tiles.py", line 2272, in <module>
    gdal2tiles.process()
  File "./swig/python/scripts/gdal2tiles.py", line 481, in process
    self.generate_base_tiles()
  File "./swig/python/scripts/gdal2tiles.py", line 1282, in generate_base_tiles
    dsquery.WriteRaster(wx, wy, wxsize, wysize, data, band_list=list(range(1,self.dataBandsCount+1)))
  File "/home/schwehr/src/gdal/inst/lib/python2.7/site-packages/GDAL-2.1.0-py2.7-linux-x86_64.egg/osgeo/gdal.py", line 856, in WriteRaster
    buf_pixel_space, buf_line_space, buf_band_space )
TypeError: not a string

He proposes this patch. It looks okay to me, but I could use a double check. Does this look reasonable? If there aren't any concerns, I'll go ahead and apply it to trunk.

  • swig/python/scripts/gdal2tiles.py

    svn diff swig/python/scripts/gdal2tiles.py 
     
    12571257                if self.options.verbose:
    12581258                    print("\tReadRaster Extent: ", (rx, ry, rxsize, rysize), (wx, wy, wxsize, wysize))
    12591259
     1260                if wxsize == 0 or wysize == 0:
     1261                    continue
     1262
    12601263                # Query is in 'nearest neighbour' but can be bigger in then the tilesize
    12611264                # We scale down the query to the tilesize by supplied algorithm.
    12621265
     
    13641367                        for x in range(2*tx,2*tx+2):
    13651368                            minx, miny, maxx, maxy = self.tminmax[tz+1]
    13661369                            if x >= minx and x <= maxx and y >= miny and y <= maxy:
    1367                                 dsquerytile = gdal.Open( os.path.join( self.output, str(tz+1), str(x), "%s.%s" % (y, self.tileext)), gdal.GA_ReadOnly)
     1370                                tilefile = os.path.join(self.output, str(tz+1), str(x), "%s.%s" % (y, self.tileext))
     1371                                if not os.path.exists(tilefile):
     1372                                    continue
     1373                                dsquerytile = gdal.Open(tilefile , gdal.GA_ReadOnly)
     1374                                if dsquerytile is None:
     1375                                   continue
    13681376                                if (ty==0 and y==1) or (ty!=0 and (y % (2*ty)) != 0):
    13691377                                    tileposy = 0
    13701378                                else:

Attachments (1)

debug.tif (396.2 KB ) - added by Kurt Schwehr 9 years ago.
File that crashes gdal2tiles.py -z 7-21 debug.tif tmp

Download all attachments as: .zip

Change History (6)

by Kurt Schwehr, 9 years ago

Attachment: debug.tif added

File that crashes gdal2tiles.py -z 7-21 debug.tif tmp

comment:1 by Jukka Rahkonen, 9 years ago

Is this about the same thing as tickets #3596 and #5005?

in reply to:  1 comment:2 by Even Rouault, 9 years ago

Replying to jratike80:

Is this about the same thing as tickets #3596 and #5005?

Yes, same patch as https://trac.osgeo.org/gdal/attachment/ticket/5005/gdal2tiles.patch #3596 is about empty/transparent content in tiles, whereas this one is about 0xX ou Xx0 tiles.

Looks good to me.

What would be most appreciated is a autotest/pyscripts/test_gdal2tiles.py script since we have none currently.

comment:3 by Kurt Schwehr, 9 years ago

I will try to create a test and get the test and patch in soon.

comment:4 by Even Rouault, 9 years ago

Also reported as #6106

comment:5 by Even Rouault, 7 years ago

Resolution: fixed
Status: newclosed

In 37210:

gdal2tiles: do not crash on empty tiles generation (patch by Gregory Bataille, fixes #6057, github #188)

Due to raster border approximation where the border coords is in a tile A while the border pixel is
in a tile B, neighbour of A

Note: See TracTickets for help on using tickets.