Skip to content

Commit 3d1a23f

Browse files
committed
Imported Upstream version 1.2.4
1 parent 25b6849 commit 3d1a23f

File tree

14 files changed

+125
-46
lines changed

14 files changed

+125
-46
lines changed

CHANGES.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
All tickets are children of http://trac.gispython.org/lab/ticket.
22

3+
1.2.4 (2010-09-09)
4+
------------------
5+
- Raise AttributeError when there's no backend support for a method.
6+
- Raise OSError if libgeos_c.so (or variants) can't be found and loaded.
7+
- Add geos_c DLL loading support for linux platforms where find_library
8+
doesn't work.
9+
310
1.2.3 (2010-08-17)
411
------------------
512
- Add mapping function.

PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.0
22
Name: Shapely
3-
Version: 1.2.3
3+
Version: 1.2.4
44
Summary: Geometric objects, predicates, and operations
55
Home-page: http://trac.gispython.org/lab/wiki/Shapely
66
Author: Sean Gillies

Shapely.egg-info/PKG-INFO

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Metadata-Version: 1.0
22
Name: Shapely
3-
Version: 1.2.3
3+
Version: 1.2.4
44
Summary: Geometric objects, predicates, and operations
55
Home-page: http://trac.gispython.org/lab/wiki/Shapely
66
Author: Sean Gillies

Shapely.egg-info/SOURCES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ shapely/tests/linear-referencing.txt
6060
shapely/tests/linemerge.txt
6161
shapely/tests/polygonize.txt
6262
shapely/tests/test_collection.py
63+
shapely/tests/test_delegated.py
64+
shapely/tests/test_dlls.py
6365
shapely/tests/test_doctests.py
6466
shapely/tests/test_emptiness.py
6567
shapely/tests/test_equality.py

docs/_build/html/_sources/manual.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ The Shapely 1.2 User Manual (Preview)
33
=====================================
44

55
:Author: Sean Gillies, <[email protected]>
6-
:Revision: 1.2.2
7-
:Date: 10 August 2010
6+
:Revision: 1.2.3
7+
:Date: 19 August 2010
88
:Copyright:
99
This work is licensed under a `Creative Commons Attribution 3.0
1010
United States License`__.
@@ -1717,6 +1717,8 @@ The GeoJSON-like mapping of a geometric object can be obtained using
17171717
Return a new, independent geometry with coordinates `copied` from the
17181718
context.
17191719

1720+
`New in version 1.2.3`.
1721+
17201722
For example, using the same `GeoThing` class:
17211723

17221724
.. sourcecode:: pycon

docs/manual.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ The Shapely 1.2 User Manual (Preview)
33
=====================================
44

55
:Author: Sean Gillies, <[email protected]>
6-
:Revision: 1.2.2
7-
:Date: 10 August 2010
6+
:Revision: 1.2.3
7+
:Date: 19 August 2010
88
:Copyright:
99
This work is licensed under a `Creative Commons Attribution 3.0
1010
United States License`__.
@@ -1717,6 +1717,8 @@ The GeoJSON-like mapping of a geometric object can be obtained using
17171717
Return a new, independent geometry with coordinates `copied` from the
17181718
context.
17191719

1720+
`New in version 1.2.3`.
1721+
17201722
For example, using the same `GeoThing` class:
17211723

17221724
.. sourcecode:: pycon

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
setup_args = dict(
1717
metadata_version = '1.2',
1818
name = 'Shapely',
19-
version = '1.2.3',
19+
version = '1.2.4',
2020
requires_python = '>=2.5,<3',
2121
requires_external = 'libgeos_c (>=3.1)',
2222
description = 'Geometric objects, predicates, and operations',

shapely/geometry/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from shapely.coords import CoordinateSequence
99
from shapely.geos import lgeos
10-
from shapely.impl import DefaultImplementation
10+
from shapely.impl import DefaultImplementation, delegated
1111
from shapely import wkb, wkt
1212

1313
GEOMETRY_TYPES = [
@@ -250,6 +250,7 @@ def centroid(self):
250250
"""Returns the geometric center of the object"""
251251
return geom_factory(self.impl['centroid'](self))
252252

253+
@delegated
253254
def representative_point(self):
254255
"""Returns a point guaranteed to be within the object, cheaply."""
255256
return geom_factory(self.impl['representative_point'](self))
@@ -299,6 +300,7 @@ def buffer(self, distance, resolution=16, quadsegs=None):
299300
res = resolution
300301
return geom_factory(self.impl['buffer'](self, distance, res))
301302

303+
@delegated
302304
def simplify(self, tolerance, preserve_topology=True):
303305
"""Returns a simplified geometry produced by the Douglas-Puecker
304306
algorithm
@@ -419,6 +421,7 @@ def almost_equals(self, other, decimal=6):
419421
# Linear referencing
420422
# ------------------
421423

424+
@delegated
422425
def project(self, other, normalized=False):
423426
"""Returns the distance along this geometry to a point nearest the
424427
specified point
@@ -431,7 +434,8 @@ def project(self, other, normalized=False):
431434
else:
432435
op = self.impl['project']
433436
return op(self, other)
434-
437+
438+
@delegated
435439
def interpolate(self, distance, normalized=False):
436440
"""Return a point at the specified distance along a linear geometry
437441

shapely/geos.py

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,38 @@ def emit(self, record):
2525
# Find and load the GEOS and C libraries
2626
# If this ever gets any longer, we'll break it into separate modules
2727

28+
def load_dll(libname, fallbacks=None):
29+
lib = find_library(libname)
30+
if lib is not None:
31+
return CDLL(lib)
32+
else:
33+
if fallbacks is not None:
34+
for name in fallbacks:
35+
try:
36+
return CDLL(name)
37+
except OSError:
38+
# move on to the next fallback
39+
pass
40+
# the end
41+
raise OSError(
42+
"Could not find library %s or load any of its variants %s" % (
43+
libname, fallbacks or []))
44+
2845
if sys.platform == 'linux2':
29-
_lgeos = CDLL(find_library('geos_c'))
30-
free = CDLL(find_library('c')).free
46+
_lgeos = load_dll('geos_c', fallbacks=['libgeos_c.so.1', 'libgeos_c.so'])
47+
free = load_dll('c').free
3148
free.argtypes = [c_void_p]
3249
free.restype = None
3350

3451
elif sys.platform == 'darwin':
35-
lib = find_library('geos_c')
36-
if lib is None:
37-
## try a few more locations
38-
lib_paths = [
52+
alt_paths = [
3953
# The Framework build from Kyng Chaos:
4054
"/Library/Frameworks/GEOS.framework/Versions/Current/GEOS",
4155
# macports
4256
'/opt/local/lib/libgeos_c.dylib',
43-
]
44-
for path in lib_paths:
45-
if os.path.exists(path):
46-
lib = path
47-
break
48-
if lib is None:
49-
raise ImportError("Could not find geos_c library")
50-
_lgeos = CDLL(lib)
51-
free = CDLL(find_library('c')).free
57+
]
58+
_lgeos = load_dll('geos_c', fallbacks=alt_paths)
59+
free = load_dll('c').free
5260
free.argtypes = [c_void_p]
5361
free.restype = None
5462

@@ -58,7 +66,7 @@ def emit(self, record):
5866
original_path = os.environ['PATH']
5967
os.environ['PATH'] = "%s;%s" % (local_dlls, original_path)
6068
_lgeos = CDLL("geos.dll")
61-
except (ImportError, WindowsError):
69+
except (ImportError, WindowsError, OSError):
6270
raise
6371
def free(m):
6472
try:
@@ -68,28 +76,14 @@ def free(m):
6876
pass
6977

7078
elif sys.platform == 'sunos5':
71-
# Try the major versioned name first, falling back on the unversioned
72-
# name.
73-
try:
74-
_lgeos = CDLL('libgeos_c.so.1')
75-
except (OSError, ImportError):
76-
_lgeos = CDLL('libgeos_c.so')
77-
except:
78-
raise
79+
_lgeos = load_dll('geos_c', fallbacks=['libgeos_c.so.1', 'libgeos_c.so'])
7980
free = CDLL('libc.so.1').free
8081
free.argtypes = [c_void_p]
8182
free.restype = None
8283

8384
else: # other *nix systems
84-
# Try the major versioned name first, falling back on the unversioned
85-
# name.
86-
try:
87-
_lgeos = CDLL('libgeos_c.so.1')
88-
except (OSError, ImportError):
89-
_lgeos = CDLL('libgeos_c.so')
90-
except:
91-
raise
92-
free = CDLL('libc.so.6').free
85+
_lgeos = load_dll('geos_c', fallbacks=['libgeos_c.so.1', 'libgeos_c.so'])
86+
free = load_dll('c', fallbacks=['libc.so.6']).free
9387
free.argtypes = [c_void_p]
9488
free.restype = None
9589

shapely/impl.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,42 @@
1111
Shapely 1.2 includes a GEOS backend and it is the default.
1212
"""
1313

14+
from functools import wraps
15+
1416
from shapely.coords import BoundsOp
1517
from shapely.geos import lgeos
1618
from shapely.linref import ProjectOp, InterpolateOp
1719
from shapely.predicates import BinaryPredicate, UnaryPredicate
1820
from shapely.topology import BinaryRealProperty, BinaryTopologicalOp
1921
from shapely.topology import UnaryRealProperty, UnaryTopologicalOp
2022

23+
def delegated(func):
24+
"""A delegated method raises AttributeError in the absence of backend
25+
support."""
26+
@wraps(func)
27+
def wrapper(*args, **kwargs):
28+
try:
29+
return func(*args, **kwargs)
30+
except KeyError:
31+
raise AttributeError, "Method '%s' is not supported by %s" % (
32+
func.__name__, repr(args[0].impl))
33+
return wrapper
2134

2235
# Map geometry methods to their GEOS delegates
2336

37+
class BaseImpl(object):
38+
def __init__(self, values):
39+
self.map = dict(values)
40+
def update(self, values):
41+
self.map.update(values)
42+
def __getitem__(self, key):
43+
return self.map[key]
44+
45+
class GEOSImpl(BaseImpl):
46+
def __repr__(self):
47+
return '<GEOSImpl object: GEOS C API version %s>' % (
48+
lgeos.geos_capi_version,)
49+
2450
IMPL14 = {
2551
'area': (UnaryRealProperty, 'area'),
2652
'distance': (BinaryRealProperty, 'distance'),
@@ -81,7 +107,7 @@
81107
def impl_items(defs):
82108
return [(k, v[0](v[1])) for k, v in defs.items()]
83109

84-
imp = dict(impl_items(IMPL14))
110+
imp = GEOSImpl(dict(impl_items(IMPL14)))
85111
if lgeos.geos_capi_version >= (1, 5, 0):
86112
imp.update(impl_items(IMPL15))
87113
if lgeos.geos_capi_version >= (1, 6, 0):

0 commit comments

Comments
 (0)