[gdal-dev] Python Bindings - ReadArray direct to ctypes array?
Even Rouault
even.rouault at mines-paris.org
Mon Jul 30 09:39:09 PDT 2012
Selon "Jay L." <jzl5325 at psu.edu>:
> One more, likely, foolish question.
>
> Where is libgdal.dylib living on OSX? I have used the Kyngchaos binary
> installer and it looks like it renames libgdal.dylib to simply GDAL.
> Should I be soft linking that libgdal.dylib?
>
> Also, evan's test [1] looks like it is using simply libgdal.dylib. Is that
> test failing on OS X then?
I never had the opportunity to test it on the Mac, so it might fail indeed.
I'd note that in trunk we have disabled the test with ctypes, because there was
a concern that the GDAL library loaded by "from osgeo import gdal" and the one
with ctypes might not be the same (multiple installs of GDAL coexisting on the
same system), leading to weird behaviour.
>
> [1]
>
http://svn.osgeo.org/gdal/sandbox/rouault/gdal-openjpeg-trunk/autotest/gcore/testnonboundtoswig.py
>
>
> Thanks,
> Jay
>
>
> On Mon, Jul 30, 2012 at 8:19 AM, Jay L. <jzl5325 at psu.edu> wrote:
>
> > 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
> >>
> >
> >
>
More information about the gdal-dev
mailing list