Hi Frank, 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?
They look like this: Metadata: Software=UMN Mapserver Corner Coordinates: Upper Left ( 0.0, 0.0) Lower Left ( 0.0, 256.0) Upper Right ( 256.0, 0.0) Lower Right ( 256.0, 256.0) Center ( 128.0, 128.0) Band 1 Block=256x1 Type=Byte, ColorInterp=Palette NoData Value=0 Color Table (RGB with 85 entries) 0: 0,0,0,0 1: 251,0,0,64 2: 250,0,0,54 3: 253,0,0,114 4: 254,0,0,176 5: 254,0,0,224 6: 254,0,0,228 7: 254,0,0,252 8: 253,0,0,168 9: 254,0,0,170 10: 254,0,0,234 11: 254,0,0,246 12: 254,0,0,230 13: 252,0,0,194 14: 253,0,0,232 15: 254,0,0,248 16: 254,0,0,226 17: 253,0,0,252 18: 254,0,0,244 19: 254,0,0,240 20: 253,0,0,248 21: 254,0,0,192 22: 250,0,0,98 23: 252,0,0,98 24: 253,0,0,236 25: 251,0,0,144 26: 253,0,0,208 27: 252,0,0,252 28: 253,0,0,250 29: 253,0,0,226 30: 254,0,0,212 31: 253,0,0,242 32: 250,0,0,112 33: 253,0,0,238 34: 253,0,0,222 35: 254,0,0,208 36: 253,0,0,234 37: 254,0,0,236 38: 254,0,0,232 39: 252,0,0,150 40: 253,0,0,240 41: 251,0,0,114 42: 253,0,0,244 43: 254,0,0,222 44: 231,0,0,255 45: 202,0,0,255 46: 249,0,0,255 47: 96,0,0,255 48: 63,0,0,255 49: 229,0,0,255 50: 89,0,0,255 51: 248,0,0,255 52: 192,0,0,255 53: 230,0,0,255 54: 88,0,0,255 55: 176,0,0,255 56: 225,0,0,255 57: 206,0,0,255 58: 64,0,0,255 59: 53,0,0,255 60: 113,0,0,255 61: 169,0,0,255 62: 183,0,0,255 63: 252,0,0,255 64: 184,0,0,255 65: 251,0,0,255 66: 247,0,0,255 67: 189,0,0,255 68: 224,0,0,255 69: 250,0,0,255 70: 244,0,0,255 71: 243,0,0,255 72: 227,0,0,255 73: 241,0,0,255 74: 253,0,0,255 75: 246,0,0,255 76: 167,0,0,255 77: 168,0,0,255 78: 254,0,0,255 79: 242,0,0,255 80: 245,0,0,255 81: 44,0,0,255 82: 161,0,0,255 83: 0,0,0,255 84: 255,0,0,255 Roger -- On Sat, Jan 16, 2010 at 1:26 PM, Frank Warmerdam <warmer...@pobox.com>wrote: > Roger André wrote: > >> Hi All, >> >> 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. >> >> 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. >> > > Roger, > > I am not aware of a way to utilize a raw buffer as a mem dataset from > Python (though this is doable from C++). However, you can just write > the buffer to a mem dataset. This code snippet from the autotest suite > shows something like this: > > ####################################################### > # Setup dataset > drv = gdal.GetDriverByName('MEM') > gdaltest.mem_ds = drv.Create( 'mem_1.mem', 50, 3, gdal.GDT_Int32, 1 ) > ds = gdaltest.mem_ds > > raw_data = array.array('f',list(range(150))).tostring() > ds.WriteRaster( 0, 0, 50, 3, raw_data, > buf_type = gdal.GDT_Float32, > band_list = [1] ) > > It is slightly more tricky with what I assume is a pixel interleaved 3 > band image you would have. Without having tested it, something like this > might work: > > mem_ds = gdal.GetDriverByName('MEM').Create('x',200,300,gdal.GDT_Byte,3) > mem_ds.WriteRaster( 0, 0, 200, 300, > mapImage.getBytes(), 200, 300, gdal.GDT_Byte, > band_list=[1,2,3], > buf_pixel_space=3, > buf_line_space=3*200, > buf_band_space=1) > > Good luck, > > > -- > > ---------------------------------------+-------------------------------------- > I set the clouds in motion - turn up | Frank Warmerdam, > warmer...@pobox.com > light and sound - activate the windows | > http://pobox.com/~warmerdam<http://pobox.com/%7Ewarmerdam> > and watch the world go round - Rush | Geospatial Programmer for Rent > >
_______________________________________________ gdal-dev mailing list gdal-dev@lists.osgeo.org http://lists.osgeo.org/mailman/listinfo/gdal-dev