[OSM-dev] NOT-saving empty Mapnik tiles

marqqs at gmx.eu marqqs at gmx.eu
Fri Aug 12 20:41:41 BST 2011


To Igor:

> If your current method works for you and it's just about reducing disk 
> IO, you just could use StringIO [1] or the like and save the PNG image 
> to a buffer first, then check its length and conditionally save it to
> disk:

Sounds very good, I will try this, thanks!
Meanwhile I realized that I will have to access the disc in either case, if the image is "empty" or not. If it's empty, I will have to ensure that a possibly existing image is deleted. Nevertheless your idea will save some disk access as in most cases no write access will be necessary (a delete request for a non-existing file does not result in any disk writing).

To Frederik:

> In a normal mod_tile setup, this would mean that the next time someone 
> requests that area, the tile will be rendered again, and again, and 
> again, each time producing (after a series of database queries) an empty 
> tile. Compared to that, the cost of having a 116 byte file lying around 
> is rather small!

Thanks for the warning!
But in this project I will not use mod_tile. Everything will be rendered in advance and kept up-to-date by using osm2pgsql's dirty-tiles list.

Markus


-------- Original-Nachricht --------
> Datum: Fri, 12 Aug 2011 20:02:27 +0200
> Von: Igor Podolskiy <igor.podolskiy at vwi-stuttgart.de>
> An: dev at openstreetmap.org, marqqs at gmx.eu
> Betreff: Re: [OSM-dev] NOT-saving empty Mapnik tiles

> Hi Markus,
> 
> sorry, I misread your first mail, it's not a PIL.Image but a 
> mapnik.Image - it doesn't have all those fancy methods of a PIL Image. I 
> don't know how to convert from mapnik to PIL now, either :( My fault.
> 
> But I just had another idea.
> 
> If your current method works for you and it's just about reducing disk 
> IO, you just could use StringIO [1] or the like and save the PNG image 
> to a buffer first, then check its length and conditionally save it to
> disk:
> 
> import StringIO
> buf = StringIO.StringIO()
> # ... render the image somehow here ...
> im.save(buf, 'png256')
> if buf.len > 116:
>     f = open(tile_name, 'wb')
>     f.write(buf.getvalue())
>     f.close()
> buf.close()
> 
> Bye
> Igor
> 
> [1] http://docs.python.org/library/stringio.html



More information about the dev mailing list