shapely 1.2.9__py2.6-win32.egg → 1.2.12__py2.6-win32.egg

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. DLLs/geos.dll +0 -0
  2. DLLs/geos_c.dll +0 -0
  3. EGG-INFO/PKG-INFO +23 -1
  4. EGG-INFO/native_libs.txt +1 -0
  5. shapely/algorithms/__init__.py +0 -0
  6. shapely/algorithms/__init__.pyc +0 -0
  7. shapely/algorithms/cga.py +17 -0
  8. shapely/algorithms/cga.pyc +0 -0
  9. shapely/ctypes_declarations.py +5 -0
  10. shapely/ctypes_declarations.pyc +0 -0
  11. shapely/examples/__init__.py +1 -0
  12. shapely/examples/__init__.pyc +0 -0
  13. shapely/examples/dissolve.py +53 -0
  14. shapely/examples/dissolve.pyc +0 -0
  15. shapely/examples/geoms.py +51 -0
  16. shapely/examples/geoms.pyc +0 -0
  17. shapely/examples/intersect.py +81 -0
  18. shapely/examples/intersect.pyc +0 -0
  19. shapely/examples/world.py +21 -0
  20. shapely/examples/world.pyc +0 -0
  21. shapely/geometry/base.py +4 -1
  22. shapely/geometry/base.pyc +0 -0
  23. shapely/geometry/linestring.py +8 -13
  24. shapely/geometry/linestring.pyc +0 -0
  25. shapely/geometry/multilinestring.py +0 -3
  26. shapely/geometry/multilinestring.pyc +0 -0
  27. shapely/geometry/multipoint.py +3 -2
  28. shapely/geometry/multipoint.pyc +0 -0
  29. shapely/geometry/polygon.py +40 -39
  30. shapely/geometry/polygon.pyc +0 -0
  31. shapely/geos.py +8 -7
  32. shapely/geos.pyc +0 -0
  33. shapely/impl.py +4 -0
  34. shapely/impl.pyc +0 -0
  35. shapely/predicates.py +2 -2
  36. shapely/predicates.pyc +0 -0
  37. shapely/prepared.py +4 -1
  38. shapely/prepared.pyc +0 -0
  39. shapely/speedups/__init__.py +42 -0
  40. shapely/speedups/__init__.pyc +0 -0
  41. shapely/speedups/_speedups.py +7 -0
  42. shapely/speedups/_speedups.pyc +0 -0
  43. shapely/speedups/_speedups.pyd +0 -0
  44. shapely/tests/__init__.py +28 -0
  45. shapely/tests/__init__.pyc +0 -0
  46. shapely/tests/test_box.py +19 -0
  47. shapely/tests/test_box.pyc +0 -0
  48. shapely/tests/test_cga.py +33 -0
  49. shapely/tests/test_cga.pyc +0 -0
  50. shapely/tests/test_collection.py +11 -0
  51. shapely/tests/test_collection.pyc +0 -0
  52. shapely/tests/test_delegated.py +26 -0
  53. shapely/tests/test_delegated.pyc +0 -0
  54. shapely/tests/test_dlls.py +16 -0
  55. shapely/tests/test_dlls.pyc +0 -0
  56. shapely/tests/test_doctests.py +35 -0
  57. shapely/tests/test_doctests.pyc +0 -0
  58. shapely/tests/test_emptiness.py +19 -0
  59. shapely/tests/test_emptiness.pyc +0 -0
  60. shapely/tests/test_equality.py +30 -0
  61. shapely/tests/test_equality.pyc +0 -0
  62. shapely/tests/test_geomseq.py +11 -0
  63. shapely/tests/test_geomseq.pyc +0 -0
  64. shapely/tests/test_linear_referencing.py +67 -0
  65. shapely/tests/test_linear_referencing.pyc +0 -0
  66. shapely/tests/test_mapping.py +11 -0
  67. shapely/tests/test_mapping.pyc +0 -0
  68. shapely/tests/test_prepared.py +28 -0
  69. shapely/tests/test_prepared.pyc +0 -0
  70. shapely/tests/test_products_z.py +14 -0
  71. shapely/tests/test_products_z.pyc +0 -0
  72. shapely/tests/test_singularity.py +15 -0
  73. shapely/tests/test_singularity.pyc +0 -0
  74. shapely/tests/test_speedups.py +38 -0
  75. shapely/tests/test_speedups.pyc +0 -0
  76. shapely/tests/test_validation.py +10 -0
  77. shapely/tests/test_validation.pyc +0 -0
  78. shapely/tests/test_xy.py +14 -0
  79. shapely/tests/test_xy.pyc +0 -0
  80. shapely/tests/threading_test.py +37 -0
  81. shapely/tests/threading_test.pyc +0 -0
  82. shapely/topology.py +6 -8
  83. shapely/topology.pyc +0 -0
  84. shapely/wkb.py +2 -2
  85. shapely/wkb.pyc +0 -0
  86. DLLs/libgeos-3-2-2.dll +0 -0
DLLs/geos.dll CHANGED
Binary file
DLLs/geos_c.dll ADDED
Binary file
EGG-INFO/PKG-INFO CHANGED
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: Shapely
3
- Version: 1.2.9
3
+ Version: 1.2.12
4
4
  Summary: Geometric objects, predicates, and operations
5
5
  Home-page: http://trac.gispython.org/lab/wiki/Shapely
6
6
  Author: Sean Gillies
@@ -166,6 +166,28 @@ Description: ======
166
166
  CHANGES
167
167
  =======
168
168
 
169
+ 1.2.12 (2011-08-15)
170
+ -------------------
171
+ - Build Windows distributions with VC7 or VC9 as appropriate.
172
+ - More verbose report on failure to speed up.
173
+ - Fix for prepared geometries broken in 1.2.11.
174
+ - DO NOT INSTALL 1.2.11
175
+
176
+ 1.2.11 (2011-08-04)
177
+ -------------------
178
+ - Ignore AttributeError during exit.
179
+ - PyPy 1.5 support.
180
+ - Prevent operation on prepared geometry crasher (#12).
181
+ - Optional Cython speedups for Windows.
182
+ - Linux 3 platform support.
183
+
184
+ 1.2.10 (2011-05-09)
185
+ -------------------
186
+ - Add optional Cython speedups.
187
+ - Add is_cww predicate to LinearRing.
188
+ - Add function that forces orientation of Polygons.
189
+ - Disable build of speedups on Windows pending packaging work.
190
+
169
191
  1.2.9 (2011-03-31)
170
192
  ------------------
171
193
  - Remove extra glob import.
@@ -0,0 +1 @@
1
+ shapely/speedups/_speedups.pyd
File without changes
Binary file
@@ -0,0 +1,17 @@
1
+ from itertools import islice, izip
2
+
3
+ def signed_area(ring):
4
+ """Return the signed area enclosed by a ring in linear time using the
5
+ algorithm at: http://www.cgafaq.info/wiki/Polygon_Area.
6
+ """
7
+ xs, ys = ring.coords.xy
8
+ xs.append(xs[1])
9
+ ys.append(ys[1])
10
+ return sum(xs[i]*(ys[i+1]-ys[i-1]) for i in range(1, len(ring.coords)))/2.0
11
+
12
+ def is_ccw_impl(name):
13
+ """Predicate implementation"""
14
+ def is_ccw_op(ring):
15
+ return signed_area(ring) >= 0.0
16
+ return is_ccw_op
17
+
Binary file
@@ -6,12 +6,17 @@ import ctypes
6
6
  class allocated_c_char_p(ctypes.c_char_p):
7
7
  pass
8
8
 
9
+ EXCEPTION_HANDLER_FUNCTYPE = ctypes.CFUNCTYPE(None, ctypes.c_char_p, ctypes.c_char_p)
10
+
9
11
  def prototype(lgeos, geosVersion):
10
12
 
13
+ lgeos.initGEOS.argtypes = [EXCEPTION_HANDLER_FUNCTYPE, EXCEPTION_HANDLER_FUNCTYPE]
11
14
  lgeos.initGEOS.restype = None
12
15
 
16
+ lgeos.finishGEOS.argtypes = []
13
17
  lgeos.finishGEOS.restype = None
14
18
 
19
+ lgeos.GEOSversion.argtypes = []
15
20
  lgeos.GEOSversion.restype = ctypes.c_char_p
16
21
 
17
22
  lgeos.GEOSGeomFromWKT.restype = ctypes.c_void_p
Binary file
@@ -0,0 +1 @@
1
+ # Examples module
Binary file
@@ -0,0 +1,53 @@
1
+ # dissolve.py
2
+ #
3
+ # Demonstrate how Shapely can be used to build up a collection of patches by
4
+ # dissolving circular regions and how Shapely supports plotting of the results.
5
+
6
+ from functools import partial
7
+ import random
8
+
9
+ import pylab
10
+
11
+ from shapely.geometry import Point
12
+ from shapely.ops import cascaded_union
13
+
14
+ # Use a partial function to make 100 points uniformly distributed in a 40x40
15
+ # box centered on 0,0.
16
+ r = partial(random.uniform, -20.0, 20.0)
17
+ points = [Point(r(), r()) for i in range(100)]
18
+
19
+ # Buffer the points, producing 100 polygon spots
20
+ spots = [p.buffer(2.5) for p in points]
21
+
22
+ # Perform a cascaded union of the polygon spots, dissolving them into a
23
+ # collection of polygon patches
24
+ patches = cascaded_union(spots)
25
+
26
+ if __name__ == "__main__":
27
+ # Illustrate the results using matplotlib's pylab interface
28
+ pylab.figure(num=None, figsize=(4, 4), dpi=180)
29
+
30
+ for patch in patches.geoms:
31
+ assert patch.geom_type in ['Polygon']
32
+ assert patch.is_valid
33
+
34
+ # Fill and outline each patch
35
+ x, y = patch.exterior.xy
36
+ pylab.fill(x, y, color='#cccccc', aa=True)
37
+ pylab.plot(x, y, color='#666666', aa=True, lw=1.0)
38
+
39
+ # Do the same for the holes of the patch
40
+ for hole in patch.interiors:
41
+ x, y = hole.xy
42
+ pylab.fill(x, y, color='#ffffff', aa=True)
43
+ pylab.plot(x, y, color='#999999', aa=True, lw=1.0)
44
+
45
+ # Plot the original points
46
+ pylab.plot([p.x for p in points], [p.y for p in points], 'b,', alpha=0.75)
47
+
48
+ # Write the number of patches and the total patch area to the figure
49
+ pylab.text(-25, 25,
50
+ "Patches: %d, total area: %.2f" % (len(patches.geoms), patches.area))
51
+
52
+ pylab.savefig('dissolve.png')
53
+
Binary file
@@ -0,0 +1,51 @@
1
+ from numpy import asarray
2
+ import pylab
3
+ from shapely.geometry import Point, LineString, Polygon
4
+
5
+ polygon = Polygon(((-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0), (1.0, -1.0)))
6
+
7
+ point_r = Point(-1.5, 1.2)
8
+ point_g = Point(-1.0, 1.0)
9
+ point_b = Point(-0.5, 0.5)
10
+
11
+ line_r = LineString(((-0.5, 0.5), (0.5, 0.5)))
12
+ line_g = LineString(((1.0, -1.0), (1.8, 0.5)))
13
+ line_b = LineString(((-1.8, -1.2), (1.8, 0.5)))
14
+
15
+ def plot_point(g, o, l):
16
+ pylab.plot([g.x], [g.y], o, label=l)
17
+
18
+ def plot_line(g, o):
19
+ a = asarray(g)
20
+ pylab.plot(a[:,0], a[:,1], o)
21
+
22
+ def fill_polygon(g, o):
23
+ a = asarray(g.exterior)
24
+ pylab.fill(a[:,0], a[:,1], o, alpha=0.5)
25
+
26
+ def fill_multipolygon(g, o):
27
+ for g in g.geoms:
28
+ fill_polygon(g, o)
29
+
30
+ if __name__ == "__main__":
31
+ from numpy import asarray
32
+ import pylab
33
+
34
+ fig = pylab.figure(1, figsize=(4, 3), dpi=150)
35
+ #pylab.axis([-2.0, 2.0, -1.5, 1.5])
36
+ pylab.axis('tight')
37
+
38
+ a = asarray(polygon.exterior)
39
+ pylab.fill(a[:,0], a[:,1], 'c')
40
+
41
+ plot_point(point_r, 'ro', 'b')
42
+ plot_point(point_g, 'go', 'c')
43
+ plot_point(point_b, 'bo', 'd')
44
+
45
+ plot_line(line_r, 'r')
46
+ plot_line(line_g, 'g')
47
+ plot_line(line_b, 'b')
48
+
49
+ pylab.show()
50
+
51
+
Binary file
@@ -0,0 +1,81 @@
1
+ # intersect.py
2
+ #
3
+ # Demonstrate how Shapely can be used to analyze and plot the intersection of
4
+ # a trajectory and regions in space.
5
+
6
+ from functools import partial
7
+ import random
8
+
9
+ import pylab
10
+
11
+ from shapely.geometry import LineString, Point
12
+ from shapely.ops import cascaded_union
13
+
14
+ # Build patches as in dissolved.py
15
+ r = partial(random.uniform, -20.0, 20.0)
16
+ points = [Point(r(), r()) for i in range(100)]
17
+ spots = [p.buffer(2.5) for p in points]
18
+ patches = cascaded_union(spots)
19
+
20
+ # Represent the following geolocation parameters
21
+ #
22
+ # initial position: -25, -25
23
+ # heading: 45.0
24
+ # speed: 50*sqrt(2)
25
+ #
26
+ # as a line
27
+ vector = LineString(((-25.0, -25.0), (25.0, 25.0)))
28
+
29
+ # Find intercepted and missed patches. List the former so we can count them
30
+ # later
31
+ intercepts = [patch for patch in patches.geoms if vector.intersects(patch)]
32
+ misses = (patch for patch in patches.geoms if not vector.intersects(patch))
33
+
34
+ # Plot the intersection
35
+ intersection = vector.intersection(patches)
36
+ assert intersection.geom_type in ['MultiLineString']
37
+
38
+ if __name__ == "__main__":
39
+ # Illustrate the results using matplotlib's pylab interface
40
+ pylab.figure(num=None, figsize=(4, 4), dpi=180)
41
+
42
+ # Plot the misses
43
+ for spot in misses:
44
+ x, y = spot.exterior.xy
45
+ pylab.fill(x, y, color='#cccccc', aa=True)
46
+ pylab.plot(x, y, color='#999999', aa=True, lw=1.0)
47
+
48
+ # Do the same for the holes of the patch
49
+ for hole in spot.interiors:
50
+ x, y = hole.xy
51
+ pylab.fill(x, y, color='#ffffff', aa=True)
52
+ pylab.plot(x, y, color='#999999', aa=True, lw=1.0)
53
+
54
+ # Plot the intercepts
55
+ for spot in intercepts:
56
+ x, y = spot.exterior.xy
57
+ pylab.fill(x, y, color='red', alpha=0.25, aa=True)
58
+ pylab.plot(x, y, color='red', alpha=0.5, aa=True, lw=1.0)
59
+
60
+ # Do the same for the holes of the patch
61
+ for hole in spot.interiors:
62
+ x, y = hole.xy
63
+ pylab.fill(x, y, color='#ffffff', aa=True)
64
+ pylab.plot(x, y, color='red', alpha=0.5, aa=True, lw=1.0)
65
+
66
+ # Draw the projected trajectory
67
+ pylab.arrow(-25, -25, 50, 50, color='#999999', aa=True,
68
+ head_width=1.0, head_length=1.0)
69
+
70
+ for segment in intersection.geoms:
71
+ x, y = segment.xy
72
+ pylab.plot(x, y, color='red', aa=True, lw=1.5)
73
+
74
+ # Write the number of patches and the total patch area to the figure
75
+ pylab.text(-28, 25,
76
+ "Patches: %d/%d (%d), total length: %.1f" \
77
+ % (len(intercepts), len(patches.geoms),
78
+ len(intersection.geoms), intersection.length))
79
+
80
+ pylab.savefig('intersect.png')
81
+
Binary file
@@ -0,0 +1,21 @@
1
+ import ogr
2
+ import pylab
3
+ from numpy import asarray
4
+
5
+ from shapely.wkb import loads
6
+
7
+ source = ogr.Open("/var/gis/data/world/world_borders.shp")
8
+ borders = source.GetLayerByName("world_borders")
9
+
10
+ fig = pylab.figure(1, figsize=(4,2), dpi=300)
11
+
12
+ while 1:
13
+ feature = borders.GetNextFeature()
14
+ if not feature:
15
+ break
16
+
17
+ geom = loads(feature.GetGeometryRef().ExportToWkb())
18
+ a = asarray(geom)
19
+ pylab.plot(a[:,0], a[:,1])
20
+
21
+ pylab.show()
Binary file
shapely/geometry/base.py CHANGED
@@ -104,7 +104,10 @@ class BaseGeometry(object):
104
104
  # TODO: defer cleanup to the implementation. We shouldn't be
105
105
  # explicitly calling a lgeos method here.
106
106
  if not (self._owned or self._is_empty):
107
- self._lgeos.GEOSGeom_destroy(self.__geom__)
107
+ try:
108
+ self._lgeos.GEOSGeom_destroy(self.__geom__)
109
+ except AttributeError:
110
+ pass # _lgeos might be empty on shutdown
108
111
  self.__geom__ = EMPTY
109
112
 
110
113
  def __del__(self):
shapely/geometry/base.pyc CHANGED
Binary file
@@ -167,9 +167,10 @@ def geos_linestring_from_py(ob, update_geom=None, update_ndim=0):
167
167
  assert n == 2 or n == 3
168
168
 
169
169
  # Make pointer to the coordinate array
170
- try:
170
+ if isinstance(array['data'], tuple):
171
+ # numpy tuple (addr, read-only)
171
172
  cp = cast(array['data'][0], POINTER(c_double))
172
- except ArgumentError:
173
+ else:
173
174
  cp = array['data']
174
175
 
175
176
  # Create a coordinate sequence
@@ -226,21 +227,15 @@ def geos_linestring_from_py(ob, update_geom=None, update_ndim=0):
226
227
  # add to coordinate sequence
227
228
  for i in xrange(m):
228
229
  coords = ob[i]
229
- dx = c_double(coords[0])
230
- dy = c_double(coords[1])
231
- dz = None
230
+ # Because of a bug in the GEOS C API,
231
+ # always set X before Y
232
+ lgeos.GEOSCoordSeq_setX(cs, i, coords[0])
233
+ lgeos.GEOSCoordSeq_setY(cs, i, coords[1])
232
234
  if n == 3:
233
235
  try:
234
- dz = c_double(coords[2])
236
+ lgeos.GEOSCoordSeq_setZ(cs, i, coords[2])
235
237
  except IndexError:
236
238
  raise ValueError("Inconsistent coordinate dimensionality")
237
-
238
- # Because of a bug in the GEOS C API,
239
- # always set X before Y
240
- lgeos.GEOSCoordSeq_setX(cs, i, dx)
241
- lgeos.GEOSCoordSeq_setY(cs, i, dy)
242
- if n == 3:
243
- lgeos.GEOSCoordSeq_setZ(cs, i, dz)
244
239
 
245
240
  if update_geom is not None:
246
241
  return None
Binary file
@@ -93,9 +93,6 @@ def geos_multilinestring_from_py(ob):
93
93
  L = array['shape'][0]
94
94
  assert L >= 1
95
95
 
96
- # Make pointer to the coordinate array
97
- cp = cast(array['data'][0], POINTER(c_double))
98
-
99
96
  # Array of pointers to sub-geometries
100
97
  subs = (c_void_p * L)()
101
98
 
Binary file
@@ -138,9 +138,10 @@ def geos_multipoint_from_py(ob):
138
138
  assert n == 2 or n == 3
139
139
 
140
140
  # Make pointer to the coordinate array
141
- try:
141
+ if isinstance(array['data'], tuple):
142
+ # numpy tuple (addr, read-only)
142
143
  cp = cast(array['data'][0], POINTER(c_double))
143
- except ArgumentError:
144
+ else:
144
145
  cp = array['data']
145
146
 
146
147
  # Array of pointers to sub-geometries
Binary file
@@ -4,6 +4,8 @@
4
4
  from ctypes import c_double, c_void_p, cast, POINTER
5
5
  from ctypes import ArgumentError
6
6
  import weakref
7
+
8
+ from shapely.algorithms.cga import signed_area
7
9
  from shapely.geos import lgeos
8
10
  from shapely.geometry.base import BaseGeometry
9
11
  from shapely.geometry.linestring import LineString, LineStringAdapter
@@ -61,6 +63,11 @@ class LinearRing(LineString):
61
63
 
62
64
  coords = property(_get_coords, _set_coords)
63
65
 
66
+ @property
67
+ def is_ccw(self):
68
+ """Brand new"""
69
+ return bool(self.impl['is_ccw'](self))
70
+
64
71
 
65
72
  class LinearRingAdapter(LineStringAdapter):
66
73
 
@@ -277,6 +284,20 @@ def asPolygon(shell, holes=None):
277
284
  """Adapt objects to the Polygon interface"""
278
285
  return PolygonAdapter(shell, holes)
279
286
 
287
+ def orient(polygon, sign=1.0):
288
+ s = float(sign)
289
+ rings = []
290
+ ring = polygon.exterior
291
+ if signed_area(ring)/s >= 0.0:
292
+ rings.append(ring)
293
+ else:
294
+ rings.append(list(ring.coords)[::-1])
295
+ for ring in polygon.interiors:
296
+ if signed_area(ring)/s <= 0.0:
297
+ rings.append(ring)
298
+ else:
299
+ rings.append(list(ring.coords)[::-1])
300
+ return Polygon(rings[0], rings[1:])
280
301
 
281
302
  def geos_linearring_from_py(ob, update_geom=None, update_ndim=0):
282
303
  try:
@@ -291,9 +312,10 @@ def geos_linearring_from_py(ob, update_geom=None, update_ndim=0):
291
312
  assert n == 2 or n == 3
292
313
 
293
314
  # Make pointer to the coordinate array
294
- try:
315
+ if isinstance(array['data'], tuple):
316
+ # numpy tuple (addr, read-only)
295
317
  cp = cast(array['data'][0], POINTER(c_double))
296
- except ArgumentError:
318
+ else:
297
319
  cp = array['data']
298
320
 
299
321
  # Add closing coordinates to sequence?
@@ -314,33 +336,21 @@ def geos_linearring_from_py(ob, update_geom=None, update_ndim=0):
314
336
 
315
337
  # add to coordinate sequence
316
338
  for i in xrange(m):
317
- dx = c_double(cp[n*i])
318
- dy = c_double(cp[n*i+1])
319
- dz = None
320
- if n == 3:
321
- dz = c_double(cp[n*i+2])
322
-
323
339
  # Because of a bug in the GEOS C API,
324
340
  # always set X before Y
325
- lgeos.GEOSCoordSeq_setX(cs, i, dx)
326
- lgeos.GEOSCoordSeq_setY(cs, i, dy)
341
+ lgeos.GEOSCoordSeq_setX(cs, i, cp[n*i])
342
+ lgeos.GEOSCoordSeq_setY(cs, i, cp[n*i+1])
327
343
  if n == 3:
328
- lgeos.GEOSCoordSeq_setZ(cs, i, dz)
344
+ lgeos.GEOSCoordSeq_setZ(cs, i, cp[n*i+2])
329
345
 
330
346
  # Add closing coordinates to sequence?
331
- if M > m:
332
- dx = c_double(cp[0])
333
- dy = c_double(cp[1])
334
- dz = None
335
- if n == 3:
336
- dz = c_double(cp[2])
337
-
347
+ if M > m:
338
348
  # Because of a bug in the GEOS C API,
339
349
  # always set X before Y
340
- lgeos.GEOSCoordSeq_setX(cs, M-1, dx)
341
- lgeos.GEOSCoordSeq_setY(cs, M-1, dy)
350
+ lgeos.GEOSCoordSeq_setX(cs, M-1, cp[0])
351
+ lgeos.GEOSCoordSeq_setY(cs, M-1, cp[1])
342
352
  if n == 3:
343
- lgeos.GEOSCoordSeq_setZ(cs, M-1, dz)
353
+ lgeos.GEOSCoordSeq_setZ(cs, M-1, cp[2])
344
354
 
345
355
  except AttributeError:
346
356
  # Fall back on list
@@ -370,34 +380,25 @@ def geos_linearring_from_py(ob, update_geom=None, update_ndim=0):
370
380
  # add to coordinate sequence
371
381
  for i in xrange(m):
372
382
  coords = ob[i]
373
- dx = c_double(coords[0])
374
- dy = c_double(coords[1])
375
- dz = None
376
- if n == 3:
377
- dz = c_double(coords[2])
378
-
379
383
  # Because of a bug in the GEOS C API,
380
384
  # always set X before Y
381
- lgeos.GEOSCoordSeq_setX(cs, i, dx)
382
- lgeos.GEOSCoordSeq_setY(cs, i, dy)
385
+ lgeos.GEOSCoordSeq_setX(cs, i, coords[0])
386
+ lgeos.GEOSCoordSeq_setY(cs, i, coords[1])
383
387
  if n == 3:
384
- lgeos.GEOSCoordSeq_setZ(cs, i, dz)
388
+ try:
389
+ lgeos.GEOSCoordSeq_setZ(cs, i, coords[2])
390
+ except IndexError:
391
+ raise ValueError("Inconsistent coordinate dimensionality")
385
392
 
386
393
  # Add closing coordinates to sequence?
387
394
  if M > m:
388
395
  coords = ob[0]
389
- dx = c_double(coords[0])
390
- dy = c_double(coords[1])
391
- dz = None
392
- if n == 3:
393
- dz = c_double(coords[2])
394
-
395
396
  # Because of a bug in the GEOS C API,
396
397
  # always set X before Y
397
- lgeos.GEOSCoordSeq_setX(cs, M-1, dx)
398
- lgeos.GEOSCoordSeq_setY(cs, M-1, dy)
398
+ lgeos.GEOSCoordSeq_setX(cs, M-1, coords[0])
399
+ lgeos.GEOSCoordSeq_setY(cs, M-1, coords[1])
399
400
  if n == 3:
400
- lgeos.GEOSCoordSeq_setZ(cs, M-1, dz)
401
+ lgeos.GEOSCoordSeq_setZ(cs, M-1, coords[2])
401
402
 
402
403
  if update_geom is not None:
403
404
  return None
Binary file
shapely/geos.py CHANGED
@@ -12,7 +12,7 @@ from ctypes import cdll, CDLL, CFUNCTYPE, c_char_p, c_void_p, string_at
12
12
  from ctypes.util import find_library
13
13
 
14
14
  import ftools
15
- from ctypes_declarations import prototype
15
+ from ctypes_declarations import prototype, EXCEPTION_HANDLER_FUNCTYPE
16
16
 
17
17
 
18
18
 
@@ -43,7 +43,7 @@ def load_dll(libname, fallbacks=None):
43
43
  "Could not find library %s or load any of its variants %s" % (
44
44
  libname, fallbacks or []))
45
45
 
46
- if sys.platform == 'linux2':
46
+ if sys.platform.startswith('linux'):
47
47
  _lgeos = load_dll('geos_c', fallbacks=['libgeos_c.so.1', 'libgeos_c.so'])
48
48
  free = load_dll('c').free
49
49
  free.argtypes = [c_void_p]
@@ -64,7 +64,7 @@ elif sys.platform == 'darwin':
64
64
  elif sys.platform == 'win32':
65
65
  try:
66
66
  egg_dlls = os.path.abspath(os.path.join(os.path.dirname(__file__),
67
- r"..\DLLs"))
67
+ r"..\DLLs"))
68
68
  wininst_dlls = os.path.abspath(os.__file__ + "../../../DLLs")
69
69
  original_path = os.environ['PATH']
70
70
  os.environ['PATH'] = "%s;%s;%s" % (egg_dlls, wininst_dlls, original_path)
@@ -92,6 +92,7 @@ else: # other *nix systems
92
92
 
93
93
  def _geos_c_version():
94
94
  func = _lgeos.GEOSversion
95
+ func.argtypes = []
95
96
  func.restype = c_char_p
96
97
  v = func().split('-')[2]
97
98
  return tuple(int(n) for n in v.split('.'))
@@ -129,7 +130,7 @@ if geos_c_version >= (1,5,0):
129
130
 
130
131
  # Handle special case.
131
132
  _lgeos.initGEOS_r.restype = c_void_p
132
- _lgeos.initGEOS_r.argtypes = [c_void_p, c_void_p]
133
+ _lgeos.initGEOS_r.argtypes = [EXCEPTION_HANDLER_FUNCTYPE, EXCEPTION_HANDLER_FUNCTYPE]
133
134
  _lgeos.finishGEOS_r.argtypes = [c_void_p]
134
135
 
135
136
  # Exceptions
@@ -148,11 +149,11 @@ class PredicateError(Exception):
148
149
 
149
150
  def error_handler(fmt, list):
150
151
  LOG.error("%s", list)
151
- error_h = CFUNCTYPE(None, c_char_p, c_char_p)(error_handler)
152
+ error_h = EXCEPTION_HANDLER_FUNCTYPE(error_handler)
152
153
 
153
154
  def notice_handler(fmt, list):
154
155
  LOG.warning("%s", list)
155
- notice_h = CFUNCTYPE(None, c_char_p, c_char_p)(notice_handler)
156
+ notice_h = EXCEPTION_HANDLER_FUNCTYPE(notice_handler)
156
157
 
157
158
  def cleanup():
158
159
  if _lgeos is not None :
@@ -166,7 +167,7 @@ def errcheck_wkb(result, func, argtuple):
166
167
  if not result:
167
168
  return None
168
169
  size_ref = argtuple[-1]
169
- size = size_ref._obj
170
+ size = size_ref.contents
170
171
  retval = ctypes.string_at(result, size.value)[:]
171
172
  lgeos.GEOSFree(result)
172
173
  return retval
shapely/geos.pyc CHANGED
Binary file
shapely/impl.py CHANGED
@@ -13,6 +13,7 @@ Shapely 1.2 includes a GEOS backend and it is the default.
13
13
 
14
14
  from ftools import wraps
15
15
 
16
+ from shapely.algorithms import cga
16
17
  from shapely.coords import BoundsOp
17
18
  from shapely.geos import lgeos
18
19
  from shapely.linref import ProjectOp, InterpolateOp
@@ -81,6 +82,9 @@ IMPL14 = {
81
82
  'touches': (BinaryPredicate, 'touches'),
82
83
  'within': (BinaryPredicate, 'within'),
83
84
  'equals_exact': (BinaryPredicate, 'equals_exact'),
85
+
86
+ # First pure Python implementation
87
+ 'is_ccw': (cga.is_ccw_impl, 'is_ccw'),
84
88
  }
85
89
 
86
90
  IMPL15 = {
shapely/impl.pyc CHANGED
Binary file
shapely/predicates.py CHANGED
@@ -7,13 +7,13 @@ from shapely.topology import Delegating
7
7
  class BinaryPredicate(Delegating):
8
8
  def __call__(self, this, other, *args):
9
9
  self._validate(this)
10
- self._validate(other)
10
+ self._validate(other, stop_prepared=True)
11
11
  return self.fn(this._geom, other._geom, *args)
12
12
 
13
13
  class RelateOp(Delegating):
14
14
  def __call__(self, this, other):
15
15
  self._validate(this)
16
- self._validate(other)
16
+ self._validate(other, stop_prepared=True)
17
17
  return self.fn(this._geom, other._geom)
18
18
 
19
19
  class UnaryPredicate(Delegating):
shapely/predicates.pyc CHANGED
Binary file
shapely/prepared.py CHANGED
@@ -27,7 +27,10 @@ class PreparedGeometry(object):
27
27
 
28
28
  def __del__(self):
29
29
  if self.__geom__ is not None:
30
- lgeos.GEOSPreparedGeom_destroy(self.__geom__)
30
+ try:
31
+ lgeos.GEOSPreparedGeom_destroy(self.__geom__)
32
+ except AttributeError:
33
+ pass # lgeos might be empty on shutdown
31
34
  self.__geom__ = None
32
35
  self.context = None
33
36
 
shapely/prepared.pyc CHANGED
Binary file