[gdal-dev] Write dataset to web output

Even Rouault even.rouault at mines-paris.org
Wed Sep 25 16:19:20 PDT 2013


Le mercredi 25 septembre 2013 10:48:00, Guillaume Sueur a écrit :
> Hi list,
> 
> I've build a python gdal script which retrieves WMS images from a remote
> layer. I'd like to send the image back to the browser, but I can't
> figure out how to do that...
> Once I've got a correct gdal dataset, how to read it into the server
> response ?

Guillaume,

Not sure to completely understand your use case, but why not just using 
OpenLayers to display images from a WMS source ?

If you want to stick with your script, a solution could be to create a PNG file 
from the GDAL dataset ( gdal.GetDriverByName('PNG').CreateCopy('the.png', 
src_ds) ) and then dump it to the standard output of your webserver after 
having written a "ContentType: image/png\n\n" header.

Note : you can do that without having to create a file on the regular 
filesystem, but by CreateCopy'ing() instead to /vsimem/the.png and using 
gdal.VSIFOpenL() / gdal.VSIFReadL() / gdal.VSIFCloseL() to get the content 
into a Python buffer object ( see autotest/gcore/vsifile.py in GDAL source tree 
)

Even

-- 
Geospatial professional services
http://even.rouault.free.fr/services.html


More information about the gdal-dev mailing list