[Community] Shapely, ctypes and finding geos_c
Sean Gillies
sgillies at frii.com
Fri Feb 8 00:49:35 EET 2008
Sean Gillies wrote:
> Christopher Barker wrote:
>> Hi all,
>>
>> I started checking out Shapely. Of course, the first step is getting it
>> running!
>>
>> I'm running on OS-X 10.4. I've got the geos libs in a Framework,
>> provided by KyngChaos:
>>
>> http://www.kyngchaos.com/wiki/software:frameworks
>>
>> William has done a great job of bundling up all sort of Open Source GIS
>> software in Frameworks, which is, nominally, the "right way" to do it on
>> OS-X.
>>
>> However, ctype.util.find_library doesn't find it.
>>
>> This is a general issue with ctypes-based stuff. I can imagine this is
>> always a pain, unless you deliver the libs with your own code. In any
>> case, barring digging into the find_library code and trying to patch
>> that, I added a lit bit to shapely.geos:
>>
>> elif sys.platform == 'darwin':
>> lib = find_library('geos_c')
>> if lib is None:
>> ## try a few more locations
>> ## This, or course, could be a lot smarter!
>> lib_paths =
>> ["/Library/Frameworks/GEOS.framework/Versions/Current/unix/lib/libgeos_c.dylib",#
>> The Framework build from Kyng Chaos:
>> ]
>> for path in lib_paths:
>> if os.path.exists(path):
>> lib = path
>> break
>> else:
>> raise Exception("Could not find geos_c library")
>> lgeos = CDLL(lib)
>> free = CDLL(find_library('libc')).free
>>
>> This works for me, and allows future folks to add other likely paths to
>> that list (darwinports, fink, ???)
>>
>> Is this worth a patch?
>>
>>
>> Also, I was poking around a bit, and did this:
>>
>> (poly is a Polygon object)
>>
>> cs = poly.get_coords()
>> >>> cs
>> <shapely.geometry.base.CoordinateSequence object at 0x71e30>
>> >>> import numpy as N
>> >>> N.asarray(cs)
>> Bus error
>>
>> oops!
>>
>> Maybe I shouldn't be able to turn a coords object into a numpy array,
>> but a crash should never happen.
>>
>> -Chris
>
> Well, you were as welcome as anyone to beta test it so the bug gets
> caught before 1.0 ;) Maybe Shapely coordinate sequences *should* provide
> the Numpy array interface after all. I can't think of a reason why not.
>
> The only problem I see with the patch is that the framework name/path
> looks arbitrary to me. But then I don't know much about the Mac lib
> frameworks.
>
> Cheers,
> Sean
New tickets:
http://trac.gispython.org/projects/PCL/ticket/152
http://trac.gispython.org/projects/PCL/ticket/153
Sean
More information about the Community
mailing list