[OSM-dev] NOT-saving empty Mapnik tiles
Igor Podolskiy
igor.podolskiy at vwi-stuttgart.de
Mon Aug 15 21:46:23 BST 2011
Hi,
> sorry for jumping into this discussion so late.
>
> On 15.08.2011, at 20:56, Igor Podolskiy wrote:
>> Actually, mapnik _can_ save a PNG to a buffer. My accusation from the previous mail that it couldn't do it was totally wrong, sorry for that :( Here is how it works:
>>
>> def is_empty_by_size(mapnik_image):
>> return im.tostring('png256') == 116
>
> This depends on the actual implementation of the PNG encoder, since the size might change if the implementation changes.
sure. This is more or less Markus' "original" solution without writing
the images to disk. It isn't pretty, but I figured if the original hack
worked for Markus its in-memory translation might work too.
> PILs getcolors is the "right" method for that. It is the fastest way to do it, if you limit it to one color. See how I did that in MapProxy for the link_single_color_image feature: https://bitbucket.org/olt/mapproxy/src/04dec4a33735/mapproxy/image/__init__.py#cl-387
Yes, definitely, if you have a PIL image in the first place. Here, you
don't. You have a mapnik.Image which gives you tostring() and nothing
more. In the long run, the right way to do this is mapnik providing a
more more friendly interface for conversion to PIL (like exposing more
of its internal mapnik::image_32). Too bad I won't have time in the
foreseeable future to provide that patch :(
And PIL.Image.getcolors(1) might be fast - but it is still an iteration
over all pixels of the image for a single-color image (I just looked it
up in the PIL sources). You might just as well do it in Python without
introducing a dependency on PIL just for that, see the first function
from the last mail. If you want to do more image processing, then it's a
different story. Then you can convert the mapnik.Image into a PIL.Image
and have all the PIL goodness :)
Bye
Igor
More information about the dev
mailing list