shapely 1.2.10__py2.7-win-amd64.egg → 1.2.13__py2.7-win-amd64.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 (79) hide show
  1. EGG-INFO/PKG-INFO +48 -29
  2. EGG-INFO/native_libs.txt +1 -0
  3. shapely/__init__.py +2 -1
  4. shapely/__init__.pyc +0 -0
  5. shapely/ctypes_declarations.py +5 -0
  6. shapely/ctypes_declarations.pyc +0 -0
  7. shapely/examples/__init__.py +1 -0
  8. shapely/examples/__init__.pyc +0 -0
  9. shapely/examples/dissolve.py +53 -0
  10. shapely/examples/dissolve.pyc +0 -0
  11. shapely/examples/geoms.py +51 -0
  12. shapely/examples/geoms.pyc +0 -0
  13. shapely/examples/intersect.py +81 -0
  14. shapely/examples/intersect.pyc +0 -0
  15. shapely/examples/world.py +21 -0
  16. shapely/examples/world.pyc +0 -0
  17. shapely/geometry/base.py +4 -1
  18. shapely/geometry/base.pyc +0 -0
  19. shapely/geometry/linestring.py +8 -13
  20. shapely/geometry/linestring.pyc +0 -0
  21. shapely/geometry/multilinestring.py +0 -3
  22. shapely/geometry/multilinestring.pyc +0 -0
  23. shapely/geometry/multipoint.py +3 -2
  24. shapely/geometry/multipoint.pyc +0 -0
  25. shapely/geometry/polygon.py +19 -39
  26. shapely/geometry/polygon.pyc +0 -0
  27. shapely/geos.py +8 -7
  28. shapely/geos.pyc +0 -0
  29. shapely/predicates.py +2 -2
  30. shapely/predicates.pyc +0 -0
  31. shapely/prepared.py +4 -1
  32. shapely/prepared.pyc +0 -0
  33. shapely/speedups/__init__.py +42 -0
  34. shapely/speedups/__init__.pyc +0 -0
  35. shapely/speedups/_speedups.py +7 -0
  36. shapely/speedups/_speedups.pyc +0 -0
  37. shapely/speedups/_speedups.pyd +0 -0
  38. shapely/tests/__init__.py +28 -0
  39. shapely/tests/__init__.pyc +0 -0
  40. shapely/tests/test_box.py +19 -0
  41. shapely/tests/test_box.pyc +0 -0
  42. shapely/tests/test_cga.py +33 -0
  43. shapely/tests/test_cga.pyc +0 -0
  44. shapely/tests/test_collection.py +11 -0
  45. shapely/tests/test_collection.pyc +0 -0
  46. shapely/tests/test_delegated.py +26 -0
  47. shapely/tests/test_delegated.pyc +0 -0
  48. shapely/tests/test_dlls.py +16 -0
  49. shapely/tests/test_dlls.pyc +0 -0
  50. shapely/tests/test_doctests.py +35 -0
  51. shapely/tests/test_doctests.pyc +0 -0
  52. shapely/tests/test_emptiness.py +19 -0
  53. shapely/tests/test_emptiness.pyc +0 -0
  54. shapely/tests/test_equality.py +30 -0
  55. shapely/tests/test_equality.pyc +0 -0
  56. shapely/tests/test_geomseq.py +11 -0
  57. shapely/tests/test_geomseq.pyc +0 -0
  58. shapely/tests/test_linear_referencing.py +67 -0
  59. shapely/tests/test_linear_referencing.pyc +0 -0
  60. shapely/tests/test_mapping.py +11 -0
  61. shapely/tests/test_mapping.pyc +0 -0
  62. shapely/tests/test_prepared.py +28 -0
  63. shapely/tests/test_prepared.pyc +0 -0
  64. shapely/tests/test_products_z.py +14 -0
  65. shapely/tests/test_products_z.pyc +0 -0
  66. shapely/tests/test_singularity.py +15 -0
  67. shapely/tests/test_singularity.pyc +0 -0
  68. shapely/tests/test_speedups.py +38 -0
  69. shapely/tests/test_speedups.pyc +0 -0
  70. shapely/tests/test_validation.py +10 -0
  71. shapely/tests/test_validation.pyc +0 -0
  72. shapely/tests/test_xy.py +14 -0
  73. shapely/tests/test_xy.pyc +0 -0
  74. shapely/tests/threading_test.py +37 -0
  75. shapely/tests/threading_test.pyc +0 -0
  76. shapely/topology.py +6 -8
  77. shapely/topology.pyc +0 -0
  78. shapely/wkb.py +2 -2
  79. shapely/wkb.pyc +0 -0
EGG-INFO/PKG-INFO CHANGED
@@ -1,34 +1,34 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: Shapely
3
- Version: 1.2.10
3
+ Version: 1.2.13
4
4
  Summary: Geometric objects, predicates, and operations
5
- Home-page: http://trac.gispython.org/lab/wiki/Shapely
5
+ Home-page: https://github.com/sgillies/shapely
6
6
  Author: Sean Gillies
7
7
  Author-email: sean.gillies@gmail.com
8
8
  License: BSD
9
- Description: ======
10
- README
11
- ======
9
+ Description: =======
10
+ Shapely
11
+ =======
12
+
13
+ PostGIS-ish operations outside a database context for Pythoneers and Pythonistas
12
14
 
13
15
  .. image:: http://farm3.static.flickr.com/2738/4511827859_b5822043b7_o_d.png
14
16
  :width: 800
15
17
  :height: 400
16
18
 
17
19
  Shapely is a BSD-licensed Python package for manipulation and analysis of
18
- planar geometric objects. It is not concerned with data formats or coordinate
19
- systems. It is based on the widely deployed GEOS_ (the engine of PostGIS_) and
20
- JTS_ (from which GEOS is ported) libraries. This C dependency is traded for the
21
- ability to execute with blazing speed.
22
-
23
- In a nutshell: Shapely lets you do PostGIS-ish stuff outside the context of a
24
- database using idiomatic Python. For more details, see:
20
+ planar geometric objects. It is based on the widely deployed GEOS_ (the engine
21
+ of PostGIS_) and JTS_ (from which GEOS is ported) libraries. This C dependency
22
+ is traded for the ability to execute with blazing speed. Shapely is not
23
+ concerned with data formats or coordinate systems, but can be readily
24
+ integrated with packages that are. For more details, see:
25
25
 
26
26
  * Shapely wiki_
27
27
  * Shapely manual_
28
28
  * Shapely `example apps`_
29
29
 
30
30
  Dependencies
31
- ------------
31
+ ============
32
32
 
33
33
  Shapely 1.2 depends on:
34
34
 
@@ -36,7 +36,7 @@ Description: ======
36
36
  * libgeos_c >=3.1 (3.0 and below have not been tested, YMMV)
37
37
 
38
38
  Installation
39
- ------------
39
+ ============
40
40
 
41
41
  Windows users should use the executable installer, which contains the required
42
42
  GEOS DLL. Other users should acquire libgeos_c by any means, make sure that it
@@ -49,7 +49,7 @@ Description: ======
49
49
  $ python setup.py install
50
50
 
51
51
  Usage
52
- -----
52
+ =====
53
53
 
54
54
  Here is the canonical example of building an approximately circular patch by
55
55
  buffering a point::
@@ -65,7 +65,7 @@ Description: ======
65
65
  intersect.py `example apps`_.
66
66
 
67
67
  Integration
68
- -----------
68
+ ===========
69
69
 
70
70
  Shapely does not read or write data files, but it can serialize and deserialize
71
71
  using several well known formats and protocols. The shapely.wkb and shapely.wkt
@@ -88,8 +88,8 @@ Description: ======
88
88
  [ 1.00000000e+01, 0.00000000e+00]])
89
89
 
90
90
  That yields a numpy array of [x, y] arrays. This is not always exactly what one
91
- wants for plotting shapes with Matplotlib, so Shapely 1.2 adds a `xy` property
92
- for getting separate arrays of coordinate x and y values.::
91
+ wants for plotting shapes with Matplotlib (for example), so Shapely 1.2 adds
92
+ a `xy` property for obtaining separate arrays of coordinate x and y values.::
93
93
 
94
94
  >>> x, y = patch.exterior.xy
95
95
  >>> ax = asarray(x)
@@ -105,7 +105,7 @@ Description: ======
105
105
  'LINESTRING (10.0000000000000000 0.0000000000000000, ...)'
106
106
 
107
107
  Testing
108
- -------
108
+ =======
109
109
 
110
110
  Shapely uses a Zope-stye suite of unittests and doctests, excercised via
111
111
  setup.py.::
@@ -116,16 +116,12 @@ Description: ======
116
116
  supported well by nose.
117
117
 
118
118
  Support
119
- -------
120
-
121
- For current information about this project, see the wiki_.
122
-
123
- If you have questions, please consider joining our community list:
119
+ =======
124
120
 
125
- http://trac.gispython.org/projects/PCL/wiki/CommunityList
121
+ Bugs may be reported and questions asked via https://github.com/sgillies/shapely.
126
122
 
127
123
  Credits
128
- -------
124
+ =======
129
125
 
130
126
  Shapely is written by:
131
127
 
@@ -136,8 +132,8 @@ Description: ======
136
132
  Patches contributed by:
137
133
 
138
134
  * Howard Butler
139
- * Fr |eaigue| d |eaigue| ric Junod
140
- * Eric Lemoine
135
+ * Fr |eacute| d |eacute| ric Junod
136
+ * |Eacute| ric Lemoine
141
137
  * Jonathan Tartley
142
138
  * Kristian Thy
143
139
  * Oliver Tonnhofer
@@ -158,7 +154,9 @@ Description: ======
158
154
  .. _example apps: http://trac.gispython.org/lab/wiki/Examples
159
155
  .. _wiki: http://trac.gispython.org/lab/wiki/Shapely
160
156
  .. _manual: http://gispython.org/shapely/docs/1.2
161
- .. |eaigue| unicode:: U+00E9
157
+ .. |eacute| unicode:: U+00E9
158
+ :trim:
159
+ .. |Eacute| unicode:: U+00C9
162
160
  :trim:
163
161
  .. _Pleiades: http://pleiades.stoa.org
164
162
 
@@ -166,6 +164,27 @@ Description: ======
166
164
  CHANGES
167
165
  =======
168
166
 
167
+ 1.2.13 (2011-09-16)
168
+ -------------------
169
+ - Fixed errors in speedups on 32bit systems when GEOS references memory above 2GB.
170
+ - Add shapely.__version__ attribute.
171
+ - Update the manual.
172
+
173
+ 1.2.12 (2011-08-15)
174
+ -------------------
175
+ - Build Windows distributions with VC7 or VC9 as appropriate.
176
+ - More verbose report on failure to speed up.
177
+ - Fix for prepared geometries broken in 1.2.11.
178
+ - DO NOT INSTALL 1.2.11
179
+
180
+ 1.2.11 (2011-08-04)
181
+ -------------------
182
+ - Ignore AttributeError during exit.
183
+ - PyPy 1.5 support.
184
+ - Prevent operation on prepared geometry crasher (#12).
185
+ - Optional Cython speedups for Windows.
186
+ - Linux 3 platform support.
187
+
169
188
  1.2.10 (2011-05-09)
170
189
  -------------------
171
190
  - Add optional Cython speedups.
@@ -0,0 +1 @@
1
+ shapely/speedups/_speedups.pyd
shapely/__init__.py CHANGED
@@ -1 +1,2 @@
1
- # package
1
+ __version__ = "1.2.13"
2
+
shapely/__init__.pyc CHANGED
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
@@ -312,9 +312,10 @@ def geos_linearring_from_py(ob, update_geom=None, update_ndim=0):
312
312
  assert n == 2 or n == 3
313
313
 
314
314
  # Make pointer to the coordinate array
315
- try:
315
+ if isinstance(array['data'], tuple):
316
+ # numpy tuple (addr, read-only)
316
317
  cp = cast(array['data'][0], POINTER(c_double))
317
- except ArgumentError:
318
+ else:
318
319
  cp = array['data']
319
320
 
320
321
  # Add closing coordinates to sequence?
@@ -335,33 +336,21 @@ def geos_linearring_from_py(ob, update_geom=None, update_ndim=0):
335
336
 
336
337
  # add to coordinate sequence
337
338
  for i in xrange(m):
338
- dx = c_double(cp[n*i])
339
- dy = c_double(cp[n*i+1])
340
- dz = None
341
- if n == 3:
342
- dz = c_double(cp[n*i+2])
343
-
344
339
  # Because of a bug in the GEOS C API,
345
340
  # always set X before Y
346
- lgeos.GEOSCoordSeq_setX(cs, i, dx)
347
- 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])
348
343
  if n == 3:
349
- lgeos.GEOSCoordSeq_setZ(cs, i, dz)
344
+ lgeos.GEOSCoordSeq_setZ(cs, i, cp[n*i+2])
350
345
 
351
346
  # Add closing coordinates to sequence?
352
- if M > m:
353
- dx = c_double(cp[0])
354
- dy = c_double(cp[1])
355
- dz = None
356
- if n == 3:
357
- dz = c_double(cp[2])
358
-
347
+ if M > m:
359
348
  # Because of a bug in the GEOS C API,
360
349
  # always set X before Y
361
- lgeos.GEOSCoordSeq_setX(cs, M-1, dx)
362
- 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])
363
352
  if n == 3:
364
- lgeos.GEOSCoordSeq_setZ(cs, M-1, dz)
353
+ lgeos.GEOSCoordSeq_setZ(cs, M-1, cp[2])
365
354
 
366
355
  except AttributeError:
367
356
  # Fall back on list
@@ -391,34 +380,25 @@ def geos_linearring_from_py(ob, update_geom=None, update_ndim=0):
391
380
  # add to coordinate sequence
392
381
  for i in xrange(m):
393
382
  coords = ob[i]
394
- dx = c_double(coords[0])
395
- dy = c_double(coords[1])
396
- dz = None
397
- if n == 3:
398
- dz = c_double(coords[2])
399
-
400
383
  # Because of a bug in the GEOS C API,
401
384
  # always set X before Y
402
- lgeos.GEOSCoordSeq_setX(cs, i, dx)
403
- lgeos.GEOSCoordSeq_setY(cs, i, dy)
385
+ lgeos.GEOSCoordSeq_setX(cs, i, coords[0])
386
+ lgeos.GEOSCoordSeq_setY(cs, i, coords[1])
404
387
  if n == 3:
405
- 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")
406
392
 
407
393
  # Add closing coordinates to sequence?
408
394
  if M > m:
409
395
  coords = ob[0]
410
- dx = c_double(coords[0])
411
- dy = c_double(coords[1])
412
- dz = None
413
- if n == 3:
414
- dz = c_double(coords[2])
415
-
416
396
  # Because of a bug in the GEOS C API,
417
397
  # always set X before Y
418
- lgeos.GEOSCoordSeq_setX(cs, M-1, dx)
419
- 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])
420
400
  if n == 3:
421
- lgeos.GEOSCoordSeq_setZ(cs, M-1, dz)
401
+ lgeos.GEOSCoordSeq_setZ(cs, M-1, coords[2])
422
402
 
423
403
  if update_geom is not None:
424
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