[gdal-dev] Re: python memory driver

Chaitanya kumar CH chaitanya.ch at gmail.com
Thu May 5 10:53:41 EDT 2011


Julianne,

You can use the Memory raster driver just like you would use any other
format driver. Use the ReadRaster() function.
Refer to http://www.gdal.org/gdal_tutorial.html

On Thu, May 5, 2011 at 7:59 PM, Juliannerc <juliannerc at gmail.com> wrote:

> Thanks for the response.
>
> Are the code snippets below what you mean by the memory drivers?
>
>    #
>    # Create a memory raster to rasterize into.
>    #
>    target_dr = gdal.GetDriverByName ('MEM')
>
>    target_ds = target_dr.Create ('',
>                                  1500,
>                                  1500,
>                                  3,
>                                  gdal.GDT_Byte)
> ...
>
>    #
>    # Create a memory layer to rasterize from.
>    #
>    rast_dr = ogr.GetDriverByName ('Memory')
>
>    rast_ogr_ds = rast_dr.CreateDataSource ('wrk')
>
> That part of the example code works fine.  The lines and polygons created
> in
> the ogr layer are rasterized as expected according to the transform
> settings:
>
>    #
>    # Run the algorithm.
>    #
>    err = gdal.RasterizeLayer (target_ds,
>                               [2, 3, 1],
>                               rast_mem_lyr,
>                               burn_values = [240, 80, 200])
>
>
> At this point, I believe that the raster image(s) (per layer) are in the
> memory because the write to the disk produces the expected image:
>        out_dr = gdal.GetDriverByName ('pnm')
>
>        out_dr.CreateCopy ('./rasterize_1.ppm',
>                           target_ds)
>
> My BIG question is whether or not there is a way to get at the memory
> portion of the raster bands.  The ideal way (in Python) would be to get a
> numpy array as one does in the ReadAsArray option.  However, I'm not sure
> that there is a way, and if so, how to do it.
>
> I believe that the C interface allows one access to the data store using:
>
> OGR_Dr_CreateDataSource
>
> If all else fails, one can create the images, write them to disk (maybe
> memory file?) and then read them back as needed.  It seems unnecessary to
> have to go through the compression/write step when the object is right
> there.
>
> Further clarification would be very welcome.
>
> Julianne
>
> --
> View this message in context:
> http://osgeo-org.1803224.n2.nabble.com/python-memory-driver-tp6332439p6334436.html
> Sent from the GDAL - Dev mailing list archive at Nabble.com.
> _______________________________________________
> gdal-dev mailing list
> gdal-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/gdal-dev
>



-- 
Best regards,
Chaitanya kumar CH.
/tʃaɪθənjə/ /kʊmɑr/
+91-9494447584
17.2416N 80.1426E
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/gdal-dev/attachments/20110505/f6884d9e/attachment.html


More information about the gdal-dev mailing list