AW: [gdal-dev] Create gdaldataset from in-memory Image/Bitmap/byte[]/MemoryStream

Even Rouault even.rouault at mines-paris.org
Wed May 26 14:07:22 EDT 2010


Felix,

yes you should be able to use FileFromMemBuffer() to create a virtual file and 
open it with the PNG driver (since the PNG driver supports virtual IO --> as 
confirmed by gdalinfo --format PNG)

Here's the C API for it : 
http://gdal.org/cpl__vsi_8h.html#1ecb3a78729ecea4d2ce22065a605244

And here's an extract of a test in the Python autotest suite. 

    content = open('data/byte.tif', mode='rb').read()

    # Create in-memory file and initialize it with the content 
    gdal.FileFromMemBuffer('/vsimem/tiffinmem', content)

    # Open the in-memory file
    ds = gdal.Open('/vsimem/tiffinmem')

    # do something with the dataset

    # Close the dataset
    ds = None

    # Release memory associated to the in-memory file
    gdal.Unlink('/vsimem/tiffinmem')


Disclaimer: You should be able to adapt the above for C#, but I haven't tested 
with the C# bindings, so there's a risk that they aren't ready if there's 
some missing required typemap.

Best regards,

Even

Le Wednesday 26 May 2010 10:21:04 Felix Obermaier, vous avez écrit :
> Tamas,
>
> I just went through the gdal 1.7 release notes, and read that a function
> 'FileFromMemBuffer' was added to the csharp bindings. Since I'm getting
> image blobs from an sqlite database (png), is it a suitable way to use that
> function?
>
> Thanks
> Felix Obermaier
>
> ------------------------------------------
>  Ingenieurgruppe IVV GmbH & Co. KG
>  Dipl.-Ing. Felix Obermaier
>  Oppenhoffallee 171
>  52066 Aachen
>
>  Telefon: +49 (241) 94691-39
>  Telefax: +49 (241) 531622
>  eMail: obe at ivv-aachen.de<mailto:obe at ivv-aachen.de>
>  Internet: http://www.ivv-aachen.de
>
>  Sitz der Gesellschaft: Aachen
>  Amtsgericht Aachen HRA 6212
>  GF: Bauassessor Dr.-Ing. Dieter Hölsken
>  IVV-Management GmbH
>  Amtsgericht Aachen HRB 12543
>
> Von: Tamas Szekeres [mailto:szekerest at gmail.com]
> Gesendet: Donnerstag, 20. Mai 2010 23:03
> An: Felix Obermaier
> Cc: gdal-dev at lists.osgeo.org
> Betreff: Re: [gdal-dev] Create gdaldataset from in-memory
> Image/Bitmap/byte[]/MemoryStream
>
> Felix,
>
> You can find examples in the gdal source tree about creating a dataset and
> write data by using the WriteRaster method:
>
> http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/csharp/apps/GDALWrite.cs
> http://trac.osgeo.org/gdal/browser/trunk/gdal/swig/csharp/apps/GDALDatasetW
>rite.cs
>
> For more information about the raster IO operations in C# see:
> http://trac.osgeo.org/gdal/wiki/GdalOgrCsharpRaster
>
> Best regards,
>
> Tamas
>
>
>
> 2010/5/20 Felix Obermaier <obe at ivv-aachen.de<mailto:obe at ivv-aachen.de>>
> Hello list,
>
> I'm using GDAL via swig C# bindings. Is there a way to create a gdal
> dataset object from an in-memory Image/Bitmap/byte[]/MemoryStream, and if
> so, how  can I achive this.
>
> Thanks in advance
>
> Felix Obermaier
>
> ------------------------------------------
>  Ingenieurgruppe IVV GmbH & Co. KG
>  Dipl.-Ing. Felix Obermaier
>  Oppenhoffallee 171
>  52066 Aachen
>
>  Telefon: +49 (241) 94691-39
>  Telefax: +49 (241) 531622
>  eMail: obe_at_ivv-aachen.de<http://obe_at_ivv-aachen.de>
>  Internet: http://www.ivv-aachen.de
>
>  Sitz der Gesellschaft: Aachen
>  Amtsgericht Aachen HRA 6212
>  GF: Bauassessor Dr.-Ing. Dieter Hölsken
>  IVV-Management GmbH
>  Amtsgericht Aachen HRB 12543
>
>
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org<mailto:gdal-dev at lists.osgeo.org>
> http://lists.osgeo.org/mailman/listinfo/gdal-dev




More information about the gdal-dev mailing list