[gdal-dev] Re: python memory driver
Juliannerc
juliannerc at gmail.com
Thu May 5 10:29:14 EDT 2011
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.
More information about the gdal-dev
mailing list