Hi Frank,<br><br>Thanks for the example. How can I specify alpha in that, for one of the quantized 8-bit PNG's (with alpha) that MapServer produces? <br><br>They look like this:<br><br>Metadata:<br> Software=UMN Mapserver<br>
Corner Coordinates:<br>Upper Left ( 0.0, 0.0)<br>Lower Left ( 0.0, 256.0)<br>Upper Right ( 256.0, 0.0)<br>Lower Right ( 256.0, 256.0)<br>Center ( 128.0, 128.0)<br>
Band 1 Block=256x1 Type=Byte, ColorInterp=Palette<br> NoData Value=0<br> Color Table (RGB with 85 entries)<br> 0: 0,0,0,0<br> 1: 251,0,0,64<br> 2: 250,0,0,54<br> 3: 253,0,0,114<br> 4: 254,0,0,176<br> 5: 254,0,0,224<br>
6: 254,0,0,228<br> 7: 254,0,0,252<br> 8: 253,0,0,168<br> 9: 254,0,0,170<br> 10: 254,0,0,234<br> 11: 254,0,0,246<br> 12: 254,0,0,230<br> 13: 252,0,0,194<br> 14: 253,0,0,232<br> 15: 254,0,0,248<br>
16: 254,0,0,226<br>
17: 253,0,0,252<br> 18: 254,0,0,244<br> 19: 254,0,0,240<br> 20: 253,0,0,248<br> 21: 254,0,0,192<br> 22: 250,0,0,98<br> 23: 252,0,0,98<br> 24: 253,0,0,236<br> 25: 251,0,0,144<br> 26: 253,0,0,208<br> 27: 252,0,0,252<br>
28: 253,0,0,250<br> 29: 253,0,0,226<br> 30: 254,0,0,212<br> 31: 253,0,0,242<br> 32: 250,0,0,112<br> 33: 253,0,0,238<br> 34: 253,0,0,222<br> 35: 254,0,0,208<br> 36: 253,0,0,234<br> 37: 254,0,0,236<br>
38: 254,0,0,232<br>
39: 252,0,0,150<br> 40: 253,0,0,240<br> 41: 251,0,0,114<br> 42: 253,0,0,244<br> 43: 254,0,0,222<br> 44: 231,0,0,255<br> 45: 202,0,0,255<br> 46: 249,0,0,255<br> 47: 96,0,0,255<br> 48: 63,0,0,255<br> 49: 229,0,0,255<br>
50: 89,0,0,255<br> 51: 248,0,0,255<br> 52: 192,0,0,255<br> 53: 230,0,0,255<br> 54: 88,0,0,255<br> 55: 176,0,0,255<br> 56: 225,0,0,255<br> 57: 206,0,0,255<br> 58: 64,0,0,255<br> 59: 53,0,0,255<br> 60: 113,0,0,255<br>
61: 169,0,0,255<br> 62: 183,0,0,255<br> 63: 252,0,0,255<br> 64: 184,0,0,255<br> 65: 251,0,0,255<br> 66: 247,0,0,255<br> 67: 189,0,0,255<br> 68: 224,0,0,255<br> 69: 250,0,0,255<br> 70: 244,0,0,255<br>
71: 243,0,0,255<br>
72: 227,0,0,255<br> 73: 241,0,0,255<br> 74: 253,0,0,255<br> 75: 246,0,0,255<br> 76: 167,0,0,255<br> 77: 168,0,0,255<br> 78: 254,0,0,255<br> 79: 242,0,0,255<br> 80: 245,0,0,255<br> 81: 44,0,0,255<br> 82: 161,0,0,255<br>
83: 0,0,0,255<br> 84: 255,0,0,255<br><br><br>Roger<br>--<br><br><div class="gmail_quote">On Sat, Jan 16, 2010 at 1:26 PM, Frank Warmerdam <span dir="ltr"><<a href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div><div></div><div>Roger André wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Hi All,<br>
<br>
I'd like to know if I can take the results of a MapServer Python mapscript 'mapImage.getBytes()' operation, and feed it into GDAL as a data source for an in-memory raster? The MapServer docs state that the results of 'getBytes' in Python is a "string of binary data". I'm not sure if GDAL can open this sort of object though.<br>
<br>
For background purposes, the reason I would like to do this is so that I can try replacing PIL with GDAL in TileCache for the cutting of metatiles. PIL isn't properly saving the image formats generated by MapServer, whereas GDAL replicates them perfectly.<br>
</blockquote>
<br></div></div>
Roger,<br>
<br>
I am not aware of a way to utilize a raw buffer as a mem dataset from<br>
Python (though this is doable from C++). However, you can just write<br>
the buffer to a mem dataset. This code snippet from the autotest suite<br>
shows something like this:<br>
<br>
#######################################################<br>
# Setup dataset<br>
drv = gdal.GetDriverByName('MEM')<br>
gdaltest.mem_ds = drv.Create( 'mem_1.mem', 50, 3, gdal.GDT_Int32, 1 )<br>
ds = gdaltest.mem_ds<br>
<br>
raw_data = array.array('f',list(range(150))).tostring()<br>
ds.WriteRaster( 0, 0, 50, 3, raw_data,<br>
buf_type = gdal.GDT_Float32,<br>
band_list = [1] )<br>
<br>
It is slightly more tricky with what I assume is a pixel interleaved 3<br>
band image you would have. Without having tested it, something like this<br>
might work:<br>
<br>
mem_ds = gdal.GetDriverByName('MEM').Create('x',200,300,gdal.GDT_Byte,3)<br>
mem_ds.WriteRaster( 0, 0, 200, 300,<br>
mapImage.getBytes(), 200, 300, gdal.GDT_Byte,<br>
band_list=[1,2,3],<br>
buf_pixel_space=3,<br>
buf_line_space=3*200,<br>
buf_band_space=1)<br>
<br>
Good luck,<div><div></div><div><br>
<br>
-- <br>
---------------------------------------+--------------------------------------<br>
I set the clouds in motion - turn up | Frank Warmerdam, <a href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</a><br>
light and sound - activate the windows | <a href="http://pobox.com/%7Ewarmerdam" target="_blank">http://pobox.com/~warmerdam</a><br>
and watch the world go round - Rush | Geospatial Programmer for Rent<br>
<br>
</div></div></blockquote></div><br>