shapely 1.2.13__py2.7-win-amd64.egg → 1.2.14__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.
EGG-INFO/PKG-INFO CHANGED
@@ -1,16 +1,17 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: Shapely
3
- Version: 1.2.13
3
+ Version: 1.2.14
4
4
  Summary: Geometric objects, predicates, and operations
5
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
- Shapely
11
- =======
9
+ Description: ======
10
+ README
11
+ ======
12
12
 
13
- PostGIS-ish operations outside a database context for Pythoneers and Pythonistas
13
+ PostGIS-ish operations outside a database context for Pythoneers and
14
+ Pythonistas.
14
15
 
15
16
  .. image:: http://farm3.static.flickr.com/2738/4511827859_b5822043b7_o_d.png
16
17
  :width: 800
@@ -107,7 +108,7 @@ Description: =======
107
108
  Testing
108
109
  =======
109
110
 
110
- Shapely uses a Zope-stye suite of unittests and doctests, excercised via
111
+ Shapely uses a Zope-stye suite of unittests and doctests, exercised via
111
112
  setup.py.::
112
113
 
113
114
  $ python setup.py test
@@ -118,7 +119,7 @@ Description: =======
118
119
  Support
119
120
  =======
120
121
 
121
- Bugs may be reported and questions asked via https://github.com/sgillies/shapely.
122
+ Bugs may be reported and questions asked via https://github.com/Toblerity/Shapely.
122
123
 
123
124
  Credits
124
125
  =======
@@ -128,22 +129,23 @@ Description: =======
128
129
  * Sean Gillies
129
130
  * Aron Bierbaum
130
131
  * Kai Lautaportti
132
+ * Oliver Tonnhofer
131
133
 
132
134
  Patches contributed by:
133
135
 
134
136
  * Howard Butler
135
- * Fr |eacute| d |eacute| ric Junod
136
- * |Eacute| ric Lemoine
137
+ * Frédéric Junod
138
+ * Éric Lemoine
137
139
  * Jonathan Tartley
138
140
  * Kristian Thy
139
- * Oliver Tonnhofer
141
+ * Mike Toews (https://github.com/mwtoews)
140
142
 
141
143
  Additional help from:
142
144
 
143
145
  * Justin Bronn (GeoDjango) for ctypes inspiration
144
146
  * Martin Davis (JTS)
145
147
  * Jaakko Salli for the Windows distributions
146
- * Sandro Santilli, Mateusz Loskot, Paul Ramsey, et al (GEOS Project)
148
+ * Sandro Santilli, Mateusz Loskot, Paul Ramsey, et al (GEOS_ Project)
147
149
 
148
150
  Major portions of this work were supported by a grant (for Pleiades_) from the
149
151
  U.S. National Endowment for the Humanities (http://www.neh.gov).
@@ -153,20 +155,24 @@ Description: =======
153
155
  .. _GEOS: http://trac.osgeo.org/geos/
154
156
  .. _example apps: http://trac.gispython.org/lab/wiki/Examples
155
157
  .. _wiki: http://trac.gispython.org/lab/wiki/Shapely
156
- .. _manual: http://gispython.org/shapely/docs/1.2
157
- .. |eacute| unicode:: U+00E9
158
- :trim:
159
- .. |Eacute| unicode:: U+00C9
160
- :trim:
158
+ .. _manual: http://toblerity.github.com/shapely/manual.html
161
159
  .. _Pleiades: http://pleiades.stoa.org
160
+
162
161
 
162
+ Changes
163
163
  =======
164
- CHANGES
165
- =======
164
+
165
+ 1.2.14 (2012-01-23)
166
+ -------------------
167
+ - A geometry's coords property is now sliceable, yielding a list of coordinate
168
+ values.
169
+ - Homogeneous collections are now sliceable, yielding a new collection of the
170
+ same type.
166
171
 
167
172
  1.2.13 (2011-09-16)
168
173
  -------------------
169
- - Fixed errors in speedups on 32bit systems when GEOS references memory above 2GB.
174
+ - Fixed errors in speedups on 32bit systems when GEOS references memory above
175
+ 2GB.
170
176
  - Add shapely.__version__ attribute.
171
177
  - Update the manual.
172
178
 
@@ -301,9 +307,7 @@ Description: =======
301
307
  - Prototype libgeos_c functions in a way that lets py2exe apps import shapely
302
308
  (#189).
303
309
 
304
- =========================
305
310
  1.2 Branched (2009-09-19)
306
- =========================
307
311
 
308
312
  1.0.12 (2009-04-09)
309
313
  -------------------
shapely/__init__.py CHANGED
@@ -1,2 +1,2 @@
1
- __version__ = "1.2.13"
1
+ __version__ = "1.2.14"
2
2
 
shapely/__init__.pyc CHANGED
Binary file
shapely/coords.py CHANGED
@@ -30,7 +30,7 @@ class CoordinateSequence(object):
30
30
  # _ndim : int
31
31
  # Number of dimensions (2 or 3, generally)
32
32
  # __p__ : object
33
- # Parent (Shapely) geometry
33
+ # Parent (Shapely) geometry
34
34
  _cseq = None
35
35
  _ndim = None
36
36
  __p__ = None
@@ -41,7 +41,7 @@ class CoordinateSequence(object):
41
41
  def _update(self):
42
42
  self._ndim = self.__p__._ndim
43
43
  self._cseq = lgeos.GEOSGeom_getCoordSeq(self.__p__._geom)
44
-
44
+
45
45
  def __len__(self):
46
46
  self._update()
47
47
  cs_len = c_uint(0)
@@ -53,38 +53,56 @@ class CoordinateSequence(object):
53
53
  dx = c_double()
54
54
  dy = c_double()
55
55
  dz = c_double()
56
- for i in range(self.__len__()):
56
+ has_z = self._ndim == 3
57
+ for i in xrange(self.__len__()):
57
58
  lgeos.GEOSCoordSeq_getX(self._cseq, i, byref(dx))
58
59
  lgeos.GEOSCoordSeq_getY(self._cseq, i, byref(dy))
59
- if self._ndim == 3: # TODO: use hasz
60
+ if has_z:
60
61
  lgeos.GEOSCoordSeq_getZ(self._cseq, i, byref(dz))
61
62
  yield (dx.value, dy.value, dz.value)
62
63
  else:
63
64
  yield (dx.value, dy.value)
64
65
 
65
- def __getitem__(self, i):
66
+ def __getitem__(self, key):
66
67
  self._update()
67
- M = self.__len__()
68
- if i + M < 0 or i >= M:
69
- raise IndexError("index out of range")
70
- if i < 0:
71
- ii = M + i
72
- else:
73
- ii = i
74
68
  dx = c_double()
75
69
  dy = c_double()
76
70
  dz = c_double()
77
- lgeos.GEOSCoordSeq_getX(self._cseq, ii, byref(dx))
78
- lgeos.GEOSCoordSeq_getY(self._cseq, ii, byref(dy))
79
- if self._ndim == 3: # TODO: use hasz
80
- lgeos.GEOSCoordSeq_getZ(self._cseq, ii, byref(dz))
81
- return (dx.value, dy.value, dz.value)
71
+ m = self.__len__()
72
+ has_z = self._ndim == 3
73
+ if isinstance(key, int):
74
+ if key + m < 0 or key >= m:
75
+ raise IndexError("index out of range")
76
+ if key < 0:
77
+ i = m + key
78
+ else:
79
+ i = key
80
+ lgeos.GEOSCoordSeq_getX(self._cseq, i, byref(dx))
81
+ lgeos.GEOSCoordSeq_getY(self._cseq, i, byref(dy))
82
+ if has_z:
83
+ lgeos.GEOSCoordSeq_getZ(self._cseq, i, byref(dz))
84
+ return (dx.value, dy.value, dz.value)
85
+ else:
86
+ return (dx.value, dy.value)
87
+ elif isinstance(key, slice):
88
+ res = []
89
+ start, stop, stride = key.indices(m)
90
+ for i in xrange(start, stop, stride):
91
+ lgeos.GEOSCoordSeq_getX(self._cseq, i, byref(dx))
92
+ lgeos.GEOSCoordSeq_getY(self._cseq, i, byref(dy))
93
+ if has_z:
94
+ lgeos.GEOSCoordSeq_getZ(self._cseq, i, byref(dz))
95
+ res.append((dx.value, dy.value, dz.value))
96
+ else:
97
+ res.append((dx.value, dy.value))
98
+ return res
82
99
  else:
83
- return (dx.value, dy.value)
100
+ raise TypeError("key must be an index or slice")
84
101
 
85
102
  @property
86
103
  def ctypes(self):
87
104
  self._update()
105
+ has_z = self._ndim == 3
88
106
  n = self._ndim
89
107
  m = self.__len__()
90
108
  array_type = c_double * (m * n)
@@ -95,7 +113,7 @@ class CoordinateSequence(object):
95
113
  data[n*i] = temp.value
96
114
  lgeos.GEOSCoordSeq_getY(self._cseq, i, byref(temp))
97
115
  data[n*i+1] = temp.value
98
- if n == 3: # TODO: use hasz
116
+ if has_z:
99
117
  lgeos.GEOSCoordSeq_getZ(self._cseq, i, byref(temp))
100
118
  data[n*i+2] = temp.value
101
119
  return data
@@ -133,7 +151,7 @@ class CoordinateSequence(object):
133
151
  lgeos.GEOSCoordSeq_getY(self._cseq, i, byref(temp))
134
152
  y.append(temp.value)
135
153
  return x, y
136
-
154
+
137
155
 
138
156
  class BoundsOp(Validating):
139
157
 
@@ -163,4 +181,3 @@ class BoundsOp(Validating):
163
181
  if y < miny: miny = y
164
182
  if y > maxy: maxy = y
165
183
  return (minx, miny, maxx, maxy)
166
-
shapely/coords.pyc CHANGED
Binary file
shapely/geometry/base.py CHANGED
@@ -12,13 +12,13 @@ from shapely import wkb, wkt
12
12
 
13
13
  GEOMETRY_TYPES = [
14
14
  'Point',
15
- 'LineString',
16
- 'LinearRing',
17
- 'Polygon',
18
- 'MultiPoint',
19
- 'MultiLineString',
20
- 'MultiPolygon',
21
- 'GeometryCollection'
15
+ 'LineString',
16
+ 'LinearRing',
17
+ 'Polygon',
18
+ 'MultiPoint',
19
+ 'MultiLineString',
20
+ 'MultiPolygon',
21
+ 'GeometryCollection'
22
22
  ]
23
23
 
24
24
  def geometry_type_name(g):
@@ -548,23 +548,35 @@ class GeometrySequence(object):
548
548
 
549
549
  def __iter__(self):
550
550
  self._update()
551
- for i in range(self.__len__()):
551
+ for i in xrange(self.__len__()):
552
552
  yield self._get_geom_item(i)
553
553
 
554
554
  def __len__(self):
555
555
  self._update()
556
556
  return lgeos.GEOSGetNumGeometries(self._geom)
557
557
 
558
- def __getitem__(self, i):
558
+ def __getitem__(self, key):
559
559
  self._update()
560
- M = self.__len__()
561
- if i + M < 0 or i >= M:
562
- raise IndexError("index out of range")
563
- if i < 0:
564
- ii = M + i
560
+ m = self.__len__()
561
+ if isinstance(key, int):
562
+ if key + m < 0 or key >= m:
563
+ raise IndexError("index out of range")
564
+ if key < 0:
565
+ i = m + key
566
+ else:
567
+ i = key
568
+ return self._get_geom_item(i)
569
+ elif isinstance(key, slice):
570
+ if type(self) == HeterogeneousGeometrySequence:
571
+ raise TypeError(
572
+ "Heterogenous geometry collections are not sliceable")
573
+ res = []
574
+ start, stop, stride = key.indices(m)
575
+ for i in xrange(start, stop, stride):
576
+ res.append(self._get_geom_item(i))
577
+ return type(self.__p__)(res or None)
565
578
  else:
566
- ii = i
567
- return self._get_geom_item(i)
579
+ raise TypeError("key must be an index or slice")
568
580
 
569
581
  @property
570
582
  def _longest(self):
shapely/geometry/base.pyc CHANGED
Binary file
@@ -41,7 +41,7 @@ class MultiLineString(BaseMultipartGeometry):
41
41
  super(MultiLineString, self).__init__()
42
42
 
43
43
  if lines is None:
44
- # allow creation of null lines, to support unpickling
44
+ # allow creation of empty multilinestrings, to support unpickling
45
45
  pass
46
46
  else:
47
47
  self._geom, self._ndim = geos_multilinestring_from_py(lines)
Binary file
@@ -51,7 +51,7 @@ class MultiPolygon(BaseMultipartGeometry):
51
51
  super(MultiPolygon, self).__init__()
52
52
 
53
53
  if polygons is None:
54
- # allow creation of null collections, to support unpickling
54
+ # allow creation of empty multipolygons, to support unpickling
55
55
  pass
56
56
  elif context_type == 'polygons':
57
57
  self._geom, self._ndim = geos_multipolygon_from_polygons(polygons)
Binary file
@@ -124,15 +124,24 @@ class InteriorRingSequence(object):
124
124
  def __len__(self):
125
125
  return lgeos.GEOSGetNumInteriorRings(self._geom)
126
126
 
127
- def __getitem__(self, i):
128
- M = self.__len__()
129
- if i + M < 0 or i >= M:
130
- raise IndexError("index out of range")
131
- if i < 0:
132
- ii = M + i
127
+ def __getitem__(self, key):
128
+ m = self.__len__()
129
+ if isinstance(key, int):
130
+ if key + m < 0 or key >= m:
131
+ raise IndexError("index out of range")
132
+ if key < 0:
133
+ i = m + key
134
+ else:
135
+ i = key
136
+ return self._get_ring(i)
137
+ elif isinstance(key, slice):
138
+ res = []
139
+ start, stop, stride = key.indices(m)
140
+ for i in xrange(start, stop, stride):
141
+ res.append(self._get_ring(i))
142
+ return res
133
143
  else:
134
- ii = i
135
- return self._get_ring(i)
144
+ raise TypeError("key must be an index or slice")
136
145
 
137
146
  @property
138
147
  def _longest(self):
Binary file
Binary file
shapely/tests/__init__.py CHANGED
@@ -3,7 +3,7 @@ from unittest import TestSuite
3
3
  import test_doctests, test_prepared, test_equality, test_geomseq, test_xy
4
4
  import test_collection, test_emptiness, test_singularity, test_validation
5
5
  import test_mapping, test_delegated, test_dlls, test_linear_referencing
6
- import test_products_z, test_box, test_speedups, test_cga
6
+ import test_products_z, test_box, test_speedups, test_cga, test_getitem
7
7
 
8
8
  def test_suite():
9
9
  suite = TestSuite()
@@ -24,5 +24,6 @@ def test_suite():
24
24
  suite.addTest(test_box.test_suite())
25
25
  suite.addTest(test_speedups.test_suite())
26
26
  suite.addTest(test_cga.test_suite())
27
+ suite.addTest(test_getitem.test_suite())
27
28
  return suite
28
29
 
Binary file
@@ -0,0 +1,113 @@
1
+ import unittest
2
+ from shapely import geometry
3
+
4
+ class CoordsGetItemTestCase(unittest.TestCase):
5
+ def test_index_2d_coords(self):
6
+ c = [(float(x), float(-x)) for x in range(4)]
7
+ g = geometry.LineString(c)
8
+ for i in range(-4,4):
9
+ self.assertTrue(g.coords[i] == c[i])
10
+ self.assertRaises(IndexError, lambda: g.coords[4])
11
+ self.assertRaises(IndexError, lambda: g.coords[-5])
12
+
13
+ def test_index_3d_coords(self):
14
+ c = [(float(x), float(-x), float(x*2)) for x in range(4)]
15
+ g = geometry.LineString(c)
16
+ for i in range(-4,4):
17
+ self.assertTrue(g.coords[i] == c[i])
18
+ self.assertRaises(IndexError, lambda: g.coords[4])
19
+ self.assertRaises(IndexError, lambda: g.coords[-5])
20
+
21
+ def test_index_coords_misc(self):
22
+ g = geometry.LineString() # empty
23
+ self.assertRaises(IndexError, lambda: g.coords[0])
24
+ self.assertRaises(TypeError, lambda: g.coords[0.0])
25
+
26
+ def test_slice_2d_coords(self):
27
+ c = [(float(x), float(-x)) for x in range(4)]
28
+ g = geometry.LineString(c)
29
+ self.assertTrue(g.coords[1:] == c[1:])
30
+ self.assertTrue(g.coords[:-1] == c[:-1])
31
+ self.assertTrue(g.coords[::-1] == c[::-1])
32
+ self.assertTrue(g.coords[::2] == c[::2])
33
+ self.assertTrue(g.coords[:4] == c[:4])
34
+ self.assertTrue(g.coords[4:] == c[4:] == [])
35
+
36
+ def test_slice_3d_coords(self):
37
+ c = [(float(x), float(-x), float(x*2)) for x in range(4)]
38
+ g = geometry.LineString(c)
39
+ self.assertTrue(g.coords[1:] == c[1:])
40
+ self.assertTrue(g.coords[:-1] == c[:-1])
41
+ self.assertTrue(g.coords[::-1] == c[::-1])
42
+ self.assertTrue(g.coords[::2] == c[::2])
43
+ self.assertTrue(g.coords[:4] == c[:4])
44
+ self.assertTrue(g.coords[4:] == c[4:] == [])
45
+
46
+ class MultiGeomGetItemTestCase(unittest.TestCase):
47
+ def test_index_multigeom(self):
48
+ c = [(float(x), float(-x)) for x in range(4)]
49
+ g = geometry.MultiPoint(c)
50
+ for i in range(-4,4):
51
+ self.assertTrue(g[i].equals(geometry.Point(c[i])))
52
+ self.assertRaises(IndexError, lambda: g[4])
53
+ self.assertRaises(IndexError, lambda: g[-5])
54
+
55
+ def test_index_multigeom_misc(self):
56
+ g = geometry.MultiLineString() # empty
57
+ self.assertRaises(IndexError, lambda: g[0])
58
+ self.assertRaises(TypeError, lambda: g[0.0])
59
+
60
+ def test_slice_multigeom(self):
61
+ c = [(float(x), float(-x)) for x in range(4)]
62
+ g = geometry.MultiPoint(c)
63
+ self.failUnlessEqual(type(g[:]), type(g))
64
+ self.failUnlessEqual(len(g[:]), len(g))
65
+ self.failUnless(g[1:].equals(geometry.MultiPoint(c[1:])))
66
+ self.failUnless(g[:-1].equals(geometry.MultiPoint(c[:-1])))
67
+ self.failUnless(g[::-1].equals(geometry.MultiPoint(c[::-1])))
68
+ self.failUnless(g[4:].is_empty)
69
+
70
+ class LinearRingGetItemTestCase(unittest.TestCase):
71
+ def test_index_linearring(self):
72
+ shell = geometry.polygon.LinearRing([(0.0, 0.0), (70.0, 120.0),
73
+ (140.0, 0.0), (0.0, 0.0)])
74
+ holes = [geometry.polygon.LinearRing([(60.0, 80.0), (80.0, 80.0),
75
+ (70.0, 60.0), (60.0, 80.0)]),
76
+ geometry.polygon.LinearRing([(30.0, 10.0), (50.0, 10.0),
77
+ (40.0, 30.0), (30.0, 10.0)]),
78
+ geometry.polygon.LinearRing([(90.0, 10), (110.0, 10.0),
79
+ (100.0, 30.0), (90.0, 10.0)])]
80
+ g = geometry.Polygon(shell, holes)
81
+ for i in range(-3,3):
82
+ self.assertTrue(g.interiors[i].equals(holes[i]))
83
+ self.assertRaises(IndexError, lambda: g.interiors[3])
84
+ self.assertRaises(IndexError, lambda: g.interiors[-4])
85
+
86
+ def test_index_linearring_misc(self):
87
+ g = geometry.Polygon() # empty
88
+ self.assertRaises(IndexError, lambda: g.interiors[0])
89
+ self.assertRaises(TypeError, lambda: g.interiors[0.0])
90
+
91
+ def test_slice_linearring(self):
92
+ shell = geometry.polygon.LinearRing([(0.0, 0.0), (70.0, 120.0),
93
+ (140.0, 0.0), (0.0, 0.0)])
94
+ holes = [geometry.polygon.LinearRing([(60.0, 80.0), (80.0, 80.0),
95
+ (70.0, 60.0), (60.0, 80.0)]),
96
+ geometry.polygon.LinearRing([(30.0, 10.0), (50.0, 10.0),
97
+ (40.0, 30.0), (30.0, 10.0)]),
98
+ geometry.polygon.LinearRing([(90.0, 10), (110.0, 10.0),
99
+ (100.0, 30.0), (90.0, 10.0)])]
100
+ g = geometry.Polygon(shell, holes)
101
+ self.assertTrue(all([a.equals(b) for (a, b) in zip(g.interiors[1:], holes[1:])]))
102
+ self.assertTrue(all([a.equals(b) for (a, b) in zip(g.interiors[:-1], holes[:-1])]))
103
+ self.assertTrue(all([a.equals(b) for (a, b) in zip(g.interiors[::-1], holes[::-1])]))
104
+ self.assertTrue(all([a.equals(b) for (a, b) in zip(g.interiors[::2], holes[::2])]))
105
+ self.assertTrue(all([a.equals(b) for (a, b) in zip(g.interiors[:3], holes[:3])]))
106
+ self.assertTrue(g.interiors[3:] == holes[3:] == [])
107
+
108
+ def test_suite():
109
+ loader = unittest.TestLoader()
110
+ return unittest.TestSuite([
111
+ unittest.TestLoader().loadTestsFromTestCase(CoordsGetItemTestCase),
112
+ unittest.TestLoader().loadTestsFromTestCase(MultiGeomGetItemTestCase),
113
+ unittest.TestLoader().loadTestsFromTestCase(LinearRingGetItemTestCase)])
Binary file