[gdal-dev] Python Bindings - ReadArray direct to ctypes array?

Jay L. jzl5325 at psu.edu
Mon Jul 30 08:19:43 PDT 2012


Chris,

Thanks for the link / info.  My issue is not working with the ctypes array,
but the fact that, I believe, GDAL returns a numpy array using
gdal.ReadAsArray().  Perhaps it is possible to use the GDAL python bindings
ReadAsArray() to go directly into a ctypes array (as opposed to the
wonderful code post earlier in this thread), but I have missed it.

Is it possible, not using the previously posted code, to do something like:

empty_ctypes_array = multiprocessing.RawArray(data_type, size)
empty_ctypes_array.ReadAsArray()

I realize that the above will not work, but offer it only as a pseudo code
example.  Using the above we could go direct to the ctypes array without
using either any C code, or an intermediate numpy array.

I will definitely check out the SciPy mailing list to see what the current
trends in multiprocessing are on large arrays.

Thanks and please do correct all inaccuracies as I am trying to improve my
fluency in GDAL!
Jay

On Sun, Jul 29, 2012 at 2:20 PM, Chris Barker <chris.barker at noaa.gov> wrote:

> On Fri, Jul 27, 2012 at 8:40 PM, Jay L. <jzl5325 at psu.edu> wrote:
>
> > Currently the workflow is to open the dataset and grab the first band, as
> > usual. I then read in the array, create an empty ctype array, and use
> > memmove to move the numpy array to my ctypes array.
>
> numpy comes with some utilities for working with ctypes and numpy
> arrays -- you certainly should be able to do that without a copy. Poke
> around in the numyp source, docs, and mailing list.
>
> If I understand the docs right, this makes it really simple:
>
>
> http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndarray.ctypes.html
>
> note that there is a lot of great stuff going on with numpy and
> Cython doing this sort of stuff -- numpy arrays may be a good bet anyway.
>
>
> You might also want to check out geo-Dango -- I think they've got a
> pretty complete wrapper for GDAL with ctypes
>
> -Chris
>
>
>
> --
>
> Christopher Barker, Ph.D.
> Oceanographer
>
> Emergency Response Division
> NOAA/NOS/OR&R            (206) 526-6959   voice
> 7600 Sand Point Way NE   (206) 526-6329   fax
> Seattle, WA  98115       (206) 526-6317   main reception
>
> Chris.Barker at noaa.gov
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/gdal-dev/attachments/20120730/270db728/attachment.html>


More information about the gdal-dev mailing list