shapely 1.2.13__py2.6-win-amd64.egg → 1.2.18__py2.6-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 (122) hide show
  1. EGG-INFO/PKG-INFO +451 -376
  2. EGG-INFO/native_libs.txt +2 -0
  3. EGG-INFO/not-zip-safe +1 -1
  4. shapely/DLLs/geos.dll +0 -0
  5. shapely/DLLs/geos_c.dll +0 -0
  6. shapely/__init__.py +1 -2
  7. shapely/__init__.pyc +0 -0
  8. shapely/affinity.py +252 -0
  9. shapely/affinity.pyc +0 -0
  10. shapely/algorithms/__init__.pyc +0 -0
  11. shapely/algorithms/cga.pyc +0 -0
  12. shapely/coords.py +53 -21
  13. shapely/coords.pyc +0 -0
  14. shapely/ctypes_declarations.py +16 -3
  15. shapely/ctypes_declarations.pyc +0 -0
  16. shapely/examples/__init__.pyc +0 -0
  17. shapely/examples/dissolve.pyc +0 -0
  18. shapely/examples/geoms.pyc +0 -0
  19. shapely/examples/intersect.pyc +0 -0
  20. shapely/examples/world.pyc +0 -0
  21. shapely/ftools.pyc +0 -0
  22. shapely/geometry/__init__.py +4 -4
  23. shapely/geometry/__init__.pyc +0 -0
  24. shapely/geometry/base.py +155 -54
  25. shapely/geometry/base.pyc +0 -0
  26. shapely/geometry/collection.pyc +0 -0
  27. shapely/geometry/geo.py +2 -2
  28. shapely/geometry/geo.pyc +0 -0
  29. shapely/geometry/linestring.py +24 -19
  30. shapely/geometry/linestring.pyc +0 -0
  31. shapely/geometry/multilinestring.py +2 -2
  32. shapely/geometry/multilinestring.pyc +0 -0
  33. shapely/geometry/multipoint.py +4 -0
  34. shapely/geometry/multipoint.pyc +0 -0
  35. shapely/geometry/multipolygon.py +8 -5
  36. shapely/geometry/multipolygon.pyc +0 -0
  37. shapely/geometry/point.py +7 -0
  38. shapely/geometry/point.pyc +0 -0
  39. shapely/geometry/polygon.py +28 -9
  40. shapely/geometry/polygon.pyc +0 -0
  41. shapely/geometry/proxy.py +1 -3
  42. shapely/geometry/proxy.pyc +0 -0
  43. shapely/geos.py +45 -14
  44. shapely/geos.pyc +0 -0
  45. shapely/impl.py +8 -5
  46. shapely/impl.pyc +0 -0
  47. shapely/iterops.pyc +0 -0
  48. shapely/linref.pyc +0 -0
  49. shapely/ops.py +125 -3
  50. shapely/ops.pyc +0 -0
  51. shapely/predicates.pyc +0 -0
  52. shapely/prepared.pyc +0 -0
  53. shapely/speedups/__init__.pyc +0 -0
  54. shapely/speedups/_speedups.c +5201 -0
  55. shapely/speedups/_speedups.pyc +0 -0
  56. shapely/speedups/_speedups.pyd +0 -0
  57. shapely/tests/Array.txt +86 -0
  58. shapely/tests/GeoInterface.txt +69 -0
  59. shapely/tests/IterOps.txt +31 -0
  60. shapely/tests/LineString.txt +134 -0
  61. shapely/tests/MultiLineString.txt +81 -0
  62. shapely/tests/MultiPoint.txt +101 -0
  63. shapely/tests/MultiPolygon.txt +71 -0
  64. shapely/tests/Operations.txt +89 -0
  65. shapely/tests/Operators.txt +18 -0
  66. shapely/tests/Persist.txt +35 -0
  67. shapely/tests/Point.txt +148 -0
  68. shapely/tests/Polygon.txt +143 -0
  69. shapely/tests/Predicates.txt +51 -0
  70. shapely/tests/__init__.py +10 -1
  71. shapely/tests/__init__.pyc +0 -0
  72. shapely/tests/attribute-chains.txt +38 -0
  73. shapely/tests/binascii_hex.txt +47 -0
  74. shapely/tests/cascaded_union.txt +26 -0
  75. shapely/tests/dimensions.txt +17 -0
  76. shapely/tests/invalid_intersection.txt +29 -0
  77. shapely/tests/linemerge.txt +61 -0
  78. shapely/tests/polygonize.txt +40 -0
  79. shapely/tests/test_affinity.py +239 -0
  80. shapely/tests/test_affinity.pyc +0 -0
  81. shapely/tests/test_box.pyc +0 -0
  82. shapely/tests/test_cga.pyc +0 -0
  83. shapely/tests/test_collection.py +15 -0
  84. shapely/tests/test_collection.pyc +0 -0
  85. shapely/tests/test_delegated.pyc +0 -0
  86. shapely/tests/test_dlls.py +1 -1
  87. shapely/tests/test_dlls.pyc +0 -0
  88. shapely/tests/test_doctests.pyc +0 -0
  89. shapely/tests/test_emptiness.py +41 -8
  90. shapely/tests/test_emptiness.pyc +0 -0
  91. shapely/tests/test_equality.pyc +0 -0
  92. shapely/tests/test_geomseq.pyc +0 -0
  93. shapely/tests/test_getitem.py +113 -0
  94. shapely/tests/test_getitem.pyc +0 -0
  95. shapely/tests/test_linear_referencing.pyc +0 -0
  96. shapely/tests/test_mapping.pyc +0 -0
  97. shapely/tests/test_ndarrays.py +35 -0
  98. shapely/tests/test_ndarrays.pyc +0 -0
  99. shapely/tests/test_pickle.py +15 -0
  100. shapely/tests/test_pickle.pyc +0 -0
  101. shapely/tests/test_prepared.pyc +0 -0
  102. shapely/tests/test_products_z.pyc +0 -0
  103. shapely/tests/test_singularity.pyc +0 -0
  104. shapely/tests/test_speedups.pyc +0 -0
  105. shapely/tests/test_styles.py +17 -0
  106. shapely/tests/test_styles.pyc +0 -0
  107. shapely/tests/test_transform.py +61 -0
  108. shapely/tests/test_transform.pyc +0 -0
  109. shapely/tests/test_unary_union.py +40 -0
  110. shapely/tests/test_unary_union.pyc +0 -0
  111. shapely/tests/test_validation.pyc +0 -0
  112. shapely/tests/test_xy.pyc +0 -0
  113. shapely/tests/threading_test.pyc +0 -0
  114. shapely/tests/wkt_locale.txt +28 -0
  115. shapely/topology.pyc +0 -0
  116. shapely/validation.pyc +0 -0
  117. shapely/wkb.py +3 -17
  118. shapely/wkb.pyc +0 -0
  119. shapely/wkt.py +3 -13
  120. shapely/wkt.pyc +0 -0
  121. DLLs/geos.dll +0 -0
  122. DLLs/geos_c.dll +0 -0
@@ -0,0 +1,239 @@
1
+ import unittest
2
+ from math import pi
3
+ from shapely import affinity
4
+ from shapely.wkt import loads as load_wkt
5
+ from shapely.geometry import Point
6
+
7
+ class AffineTestCase(unittest.TestCase):
8
+
9
+ def test_affine_params(self):
10
+ g = load_wkt('LINESTRING(2.4 4.1, 2.4 3, 3 3)')
11
+ self.assertRaises(
12
+ TypeError, affinity.affine_transform, g, None)
13
+ self.assertRaises(
14
+ TypeError, affinity.affine_transform, g, '123456')
15
+ self.assertRaises(ValueError,
16
+ affinity.affine_transform, g, [1,2,3,4,5,6,7,8,9])
17
+ self.assertRaises(AttributeError,
18
+ affinity.affine_transform, None, [1,2,3,4,5,6])
19
+
20
+ def test_affine_geom_types(self):
21
+ matrix2d = (1, 0,
22
+ 0, 1,
23
+ 0, 0)
24
+ matrix3d = (1, 0, 0,
25
+ 0, 1, 0,
26
+ 0, 0, 1,
27
+ 0, 0, 0)
28
+ def test_geom(g2, g3=None):
29
+ self.assertFalse(g2.has_z)
30
+ a2 = affinity.affine_transform(g2, matrix2d)
31
+ self.assertFalse(a2.has_z)
32
+ self.assertTrue(g2.equals(a2))
33
+ if g3 is not None:
34
+ self.assertTrue(g3.has_z)
35
+ a3 = affinity.affine_transform(g3, matrix3d)
36
+ self.assertTrue(a3.has_z)
37
+ self.assertTrue(g3.equals(a3))
38
+ return
39
+ pt2d = load_wkt('POINT(12.3 45.6)')
40
+ pt3d = load_wkt('POINT(12.3 45.6 7.89)')
41
+ test_geom(pt2d, pt3d)
42
+ ls2d = load_wkt('LINESTRING(0.9 3.4, 0.7 2, 2.5 2.7)')
43
+ ls3d = load_wkt('LINESTRING(0.9 3.4 3.3, 0.7 2 2.3, 2.5 2.7 5.5)')
44
+ test_geom(ls2d, ls3d)
45
+ test_geom(load_wkt('POLYGON((0.9 2.3, 0.5 1.1, 2.4 0.8, 0.9 2.3), '\
46
+ '(1.1 1.7, 0.9 1.3, 1.4 1.2, 1.1 1.7), '\
47
+ '(1.6 1.3, 1.7 1, 1.9 1.1, 1.6 1.3))'))
48
+ test_geom(load_wkt('MULTIPOINT ((-300 300), (700 300), '\
49
+ '(-800 -1100), (200 -300))'))
50
+ test_geom(load_wkt('MULTILINESTRING((0 0, -0.7 -0.7, 0.6 -1), '\
51
+ '(-0.5 0.5, 0.7 0.6, 0 -0.6))'))
52
+ test_geom(load_wkt('MULTIPOLYGON(((900 4300, -1100 -400, '\
53
+ '900 -800, 900 4300)), '\
54
+ '((1200 4300, 2300 4400, 1900 1000, 1200 4300)))'))
55
+ # GeometryCollection fails, since it does not have a good constructor
56
+ gc = load_wkt('GEOMETRYCOLLECTION(POINT(20 70),'\
57
+ ' POLYGON((60 70, 13 35, 60 -30, 60 70)),'\
58
+ ' LINESTRING(60 70, 50 100, 80 100))')
59
+ self.assertRaises(TypeError, test_geom, gc) # TODO: fix this
60
+
61
+ def test_affine_2d(self):
62
+ g = load_wkt('LINESTRING(2.4 4.1, 2.4 3, 3 3)')
63
+ # custom scale and translate
64
+ expected2d = load_wkt('LINESTRING(-0.2 14.35, -0.2 11.6, 1 11.6)')
65
+ matrix2d = (2, 0,
66
+ 0, 2.5,
67
+ -5, 4.1)
68
+ a2 = affinity.affine_transform(g, matrix2d)
69
+ self.assertTrue(a2.almost_equals(expected2d))
70
+ self.assertFalse(a2.has_z)
71
+ # Make sure a 3D matrix does not make a 3D shape from a 2D input
72
+ matrix3d = (2, 0, 0,
73
+ 0, 2.5, 0,
74
+ 0, 0, 10,
75
+ -5, 4.1, 100)
76
+ a3 = affinity.affine_transform(g, matrix3d)
77
+ self.assertTrue(a3.almost_equals(expected2d))
78
+ self.assertFalse(a3.has_z)
79
+
80
+ def test_affine_3d(self):
81
+ g2 = load_wkt('LINESTRING(2.4 4.1, 2.4 3, 3 3)')
82
+ g3 = load_wkt('LINESTRING(2.4 4.1 100.2, 2.4 3 132.8, 3 3 128.6)')
83
+ # custom scale and translate
84
+ matrix2d = (2, 0,
85
+ 0, 2.5,
86
+ -5, 4.1)
87
+ matrix3d = (2, 0, 0,
88
+ 0, 2.5, 0,
89
+ 0, 0, 0.3048,
90
+ -5, 4.1, 100)
91
+ # Combinations of 2D and 3D geometries and matrices
92
+ a22 = affinity.affine_transform(g2, matrix2d)
93
+ a23 = affinity.affine_transform(g2, matrix3d)
94
+ a32 = affinity.affine_transform(g3, matrix2d)
95
+ a33 = affinity.affine_transform(g3, matrix3d)
96
+ # Check dimensions
97
+ self.assertFalse(a22.has_z)
98
+ self.assertFalse(a23.has_z)
99
+ self.assertTrue(a32.has_z)
100
+ self.assertTrue(a33.has_z)
101
+ # 2D equality checks
102
+ expected2d = load_wkt('LINESTRING(-0.2 14.35, -0.2 11.6, 1 11.6)')
103
+ expected3d = load_wkt('LINESTRING(-0.2 14.35 130.54096, '\
104
+ '-0.2 11.6 140.47744, 1 11.6 139.19728)')
105
+ expected32 = load_wkt('LINESTRING(-0.2 14.35 100.2, '\
106
+ '-0.2 11.6 132.8, 1 11.6 128.6)')
107
+ self.assertTrue(a22.almost_equals(expected2d))
108
+ self.assertTrue(a23.almost_equals(expected2d))
109
+ # Do explicit 3D check of coordinate values
110
+ for a, e in zip(a32.coords, expected32.coords):
111
+ for ap, ep in zip(a, e):
112
+ self.assertAlmostEqual(ap, ep)
113
+ for a, e in zip(a33.coords, expected3d.coords):
114
+ for ap, ep in zip(a, e):
115
+ self.assertAlmostEqual(ap, ep)
116
+
117
+ class TransformOpsTestCase(unittest.TestCase):
118
+
119
+ def test_rotate(self):
120
+ ls = load_wkt('LINESTRING(240 400, 240 300, 300 300)')
121
+ # counter-clockwise degrees
122
+ rls = affinity.rotate(ls, 90)
123
+ els = load_wkt('LINESTRING(220 320, 320 320, 320 380)')
124
+ self.assertTrue(rls.equals(els))
125
+ # retest with named parameters for the same result
126
+ rls = affinity.rotate(geom=ls, angle=90, origin='center')
127
+ self.assertTrue(rls.equals(els))
128
+ # clockwise radians
129
+ rls = affinity.rotate(ls, -pi/2, use_radians=True)
130
+ els = load_wkt('LINESTRING(320 380, 220 380, 220 320)')
131
+ self.assertTrue(rls.equals(els))
132
+ ## other `origin` parameters
133
+ # around the centroid
134
+ rls = affinity.rotate(ls, 90, origin='centroid')
135
+ els = load_wkt('LINESTRING(182.5 320, 282.5 320, 282.5 380)')
136
+ self.assertTrue(rls.equals(els))
137
+ # around the second coordinate tuple
138
+ rls = affinity.rotate(ls, 90, origin=ls.coords[1])
139
+ els = load_wkt('LINESTRING(140 300, 240 300, 240 360)')
140
+ self.assertTrue(rls.equals(els))
141
+ # around the absolute Point of origin
142
+ rls = affinity.rotate(ls, 90, origin=Point(0,0))
143
+ els = load_wkt('LINESTRING(-400 240, -300 240, -300 300)')
144
+ self.assertTrue(rls.equals(els))
145
+
146
+ def test_scale(self):
147
+ ls = load_wkt('LINESTRING(240 400 10, 240 300 30, 300 300 20)')
148
+ # test defaults of 1.0
149
+ sls = affinity.scale(ls)
150
+ self.assertTrue(sls.equals(ls))
151
+ # different scaling in different dimensions
152
+ sls = affinity.scale(ls, 2, 3, 0.5)
153
+ els = load_wkt('LINESTRING(210 500 5, 210 200 15, 330 200 10)')
154
+ self.assertTrue(sls.equals(els))
155
+ # Do explicit 3D check of coordinate values
156
+ for a, b in zip(sls.coords, els.coords):
157
+ for ap, bp in zip(a, b):
158
+ self.assertEqual(ap, bp)
159
+ # retest with named parameters for the same result
160
+ sls = affinity.scale(geom=ls, xfact=2, yfact=3, zfact=0.5,
161
+ origin='center')
162
+ self.assertTrue(sls.equals(els))
163
+ ## other `origin` parameters
164
+ # around the centroid
165
+ sls = affinity.scale(ls, 2, 3, 0.5, origin='centroid')
166
+ els = load_wkt('LINESTRING(228.75 537.5, 228.75 237.5, 348.75 237.5)')
167
+ self.assertTrue(sls.equals(els))
168
+ # around the second coordinate tuple
169
+ sls = affinity.scale(ls, 2, 3, 0.5, origin=ls.coords[1])
170
+ els = load_wkt('LINESTRING(240 600, 240 300, 360 300)')
171
+ self.assertTrue(sls.equals(els))
172
+ # around some other 3D Point of origin
173
+ sls = affinity.scale(ls, 2, 3, 0.5, origin=Point(100, 200, 1000))
174
+ els = load_wkt('LINESTRING(380 800 505, 380 500 515, 500 500 510)')
175
+ self.assertTrue(sls.equals(els))
176
+ # Do explicit 3D check of coordinate values
177
+ for a, b in zip(sls.coords, els.coords):
178
+ for ap, bp in zip(a, b):
179
+ self.assertEqual(ap, bp)
180
+
181
+ def test_skew(self):
182
+ ls = load_wkt('LINESTRING(240 400 10, 240 300 30, 300 300 20)')
183
+ # test default shear angles of 0.0
184
+ sls = affinity.skew(ls)
185
+ self.assertTrue(sls.equals(ls))
186
+ # different shearing in x- and y-directions
187
+ sls = affinity.skew(ls, 15, -30)
188
+ els = load_wkt('LINESTRING (253.39745962155615 417.3205080756888, '\
189
+ '226.60254037844385 317.3205080756888, '\
190
+ '286.60254037844385 282.67949192431126)')
191
+ self.assertTrue(sls.almost_equals(els))
192
+ # retest with radians for the same result
193
+ sls = affinity.skew(ls, pi/12, -pi/6, use_radians=True)
194
+ self.assertTrue(sls.almost_equals(els))
195
+ # retest with named parameters for the same result
196
+ sls = affinity.skew(geom=ls, xs=15, ys=-30,
197
+ origin='center', use_radians=False)
198
+ self.assertTrue(sls.almost_equals(els))
199
+ ## other `origin` parameters
200
+ # around the centroid
201
+ sls = affinity.skew(ls, 15, -30, origin='centroid')
202
+ els = load_wkt('LINESTRING(258.42150697963973 406.49519052838332, '\
203
+ '231.6265877365273980 306.4951905283833185, '\
204
+ '291.6265877365274264 271.8541743770057337)')
205
+ self.assertTrue(sls.almost_equals(els))
206
+ # around the second coordinate tuple
207
+ sls = affinity.skew(ls, 15, -30, origin=ls.coords[1])
208
+ els = load_wkt('LINESTRING(266.7949192431123038 400, 240 300, '\
209
+ '300 265.3589838486224153)')
210
+ self.assertTrue(sls.almost_equals(els))
211
+ # around the absolute Point of origin
212
+ sls = affinity.skew(ls, 15, -30, origin=Point(0,0))
213
+ els = load_wkt('LINESTRING(347.179676972449101 261.435935394489832, '\
214
+ '320.3847577293367976 161.4359353944898317, '\
215
+ '380.3847577293367976 126.7949192431122754)')
216
+ self.assertTrue(sls.almost_equals(els))
217
+
218
+ def test_translate(self):
219
+ ls = load_wkt('LINESTRING(240 400 10, 240 300 30, 300 300 20)')
220
+ # test default offset of 0.0
221
+ tls = affinity.translate(ls)
222
+ self.assertTrue(tls.equals(ls))
223
+ # test all offsets
224
+ tls = affinity.translate(ls, 100, 400, -10)
225
+ els = load_wkt('LINESTRING(340 800 0, 340 700 20, 400 700 10)')
226
+ self.assertTrue(tls.equals(els))
227
+ # Do explicit 3D check of coordinate values
228
+ for a, b in zip(tls.coords, els.coords):
229
+ for ap, bp in zip(a, b):
230
+ self.assertEqual(ap, bp)
231
+ # retest with named parameters for the same result
232
+ tls = affinity.translate(geom=ls, xoff=100, yoff=400, zoff=-10)
233
+ self.assertTrue(tls.equals(els))
234
+
235
+ def test_suite():
236
+ loader = unittest.TestLoader()
237
+ return unittest.TestSuite([
238
+ unittest.TestLoader().loadTestsFromTestCase(AffineTestCase),
239
+ unittest.TestLoader().loadTestsFromTestCase(TransformOpsTestCase)])
Binary file
Binary file
Binary file
@@ -1,4 +1,5 @@
1
1
  import unittest
2
+ from shapely.geometry import LineString
2
3
  from shapely.geometry.collection import GeometryCollection
3
4
 
4
5
  class CollectionTestCase(unittest.TestCase):
@@ -7,5 +8,19 @@ class CollectionTestCase(unittest.TestCase):
7
8
  self.failUnlessEqual(len(m), 0)
8
9
  self.failUnlessEqual(m.geoms, [])
9
10
 
11
+ def test_child_with_deleted_parent(self):
12
+ # test that we can remove a collection while having
13
+ # childs around
14
+ a = LineString([(0, 0), (1, 1), (1,2), (2,2)])
15
+ b = LineString([(0, 0), (1, 1), (2,1), (2,2)])
16
+ collection = a.intersection(b)
17
+
18
+ child = collection.geoms[0]
19
+ # delete parent of child
20
+ del collection
21
+
22
+ # access geometry, this should not seg fault as 1.2.15 did
23
+ child.to_wkt()
24
+
10
25
  def test_suite():
11
26
  return unittest.TestLoader().loadTestsFromTestCase(CollectionTestCase)
Binary file
Binary file
@@ -6,7 +6,7 @@ class LoadingTestCase(unittest.TestCase):
6
6
  def test_load(self):
7
7
  self.assertRaises(OSError, load_dll, 'geosh_c')
8
8
  def test_fallbacks(self):
9
- a = load_dll('geosh_c', fallbacks=[
9
+ a = load_dll('geos_c', fallbacks=[
10
10
  '/opt/local/lib/libgeos_c.dylib', # MacPorts
11
11
  '/usr/local/lib/libgeos_c.dylib', # homebrew (Mac OS X)
12
12
  'libgeos_c.so.1',
Binary file
Binary file
@@ -1,19 +1,52 @@
1
1
  import unittest
2
2
  from shapely.geometry.base import BaseGeometry
3
- from shapely.geometry import Point
3
+ import shapely.geometry as sgeom
4
+ from shapely.geometry.polygon import LinearRing
5
+
4
6
 
5
7
  class EmptinessTestCase(unittest.TestCase):
6
8
  def test_empty_base(self):
7
9
  g = BaseGeometry()
8
- self.failUnless(g._is_empty, True)
9
- def test_empty_point(self):
10
- p = Point()
11
- self.failUnless(p._is_empty, True)
10
+ self.assertTrue(g._is_empty)
11
+
12
12
  def test_emptying_point(self):
13
- p = Point(0, 0)
14
- self.failIf(p._is_empty, False)
13
+ p = sgeom.Point(0, 0)
14
+ self.assertFalse(p._is_empty)
15
15
  p.empty()
16
- self.failUnless(p._is_empty, True)
16
+ self.assertTrue(p._is_empty)
17
+
18
+ def test_none_geom(self):
19
+ p = BaseGeometry()
20
+ p._geom = None
21
+ self.assertTrue(p.is_empty)
22
+
23
+ def test_empty_point(self):
24
+ self.assertTrue(sgeom.Point().is_empty)
25
+
26
+ def test_empty_multipoint(self):
27
+ self.assertTrue(sgeom.MultiPoint().is_empty)
28
+
29
+ def test_empty_geometry_collection(self):
30
+ self.assertTrue(sgeom.GeometryCollection().is_empty)
31
+
32
+ def test_empty_linestring(self):
33
+ self.assertTrue(sgeom.LineString().is_empty)
34
+
35
+ def test_empty_multilinestring(self):
36
+ self.assertTrue(sgeom.MultiLineString([]).is_empty)
37
+
38
+ def test_empty_polygon(self):
39
+ self.assertTrue(sgeom.Polygon().is_empty)
40
+
41
+ def test_empty_multipolygon(self):
42
+ self.assertTrue(sgeom.MultiPolygon([]).is_empty)
43
+
44
+ def test_empty_linear_ring(self):
45
+ self.assertTrue(LinearRing().is_empty)
46
+
17
47
 
18
48
  def test_suite():
19
49
  return unittest.TestLoader().loadTestsFromTestCase(EmptinessTestCase)
50
+
51
+ if __name__ == '__main__':
52
+ unittest.main()
Binary file
Binary file
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
Binary file
Binary file
@@ -0,0 +1,35 @@
1
+ # Tests of support for Numpy ndarrays. See
2
+ # https://github.com/sgillies/shapely/issues/26 for discussion.
3
+ # Requires numpy.
4
+
5
+ import unittest
6
+ from shapely import geometry
7
+ import numpy
8
+
9
+ class TransposeTestCase(unittest.TestCase):
10
+ def test_multipoint(self):
11
+ a = numpy.array([[1.0, 1.0, 2.0, 2.0, 1.0], [3.0, 4.0, 4.0, 3.0, 3.0]])
12
+ t = a.T
13
+ s = geometry.asMultiPoint(t)
14
+ coords = reduce(lambda x, y: x + y, [list(g.coords) for g in s])
15
+ self.failUnlessEqual(
16
+ coords,
17
+ [(1.0, 3.0), (1.0, 4.0), (2.0, 4.0), (2.0, 3.0), (1.0, 3.0)] )
18
+ def test_linestring(self):
19
+ a = numpy.array([[1.0, 1.0, 2.0, 2.0, 1.0], [3.0, 4.0, 4.0, 3.0, 3.0]])
20
+ t = a.T
21
+ s = geometry.asLineString(t)
22
+ self.failUnlessEqual(
23
+ list(s.coords),
24
+ [(1.0, 3.0), (1.0, 4.0), (2.0, 4.0), (2.0, 3.0), (1.0, 3.0)] )
25
+ def test_polygon(self):
26
+ a = numpy.array([[1.0, 1.0, 2.0, 2.0, 1.0], [3.0, 4.0, 4.0, 3.0, 3.0]])
27
+ t = a.T
28
+ s = geometry.asPolygon(t)
29
+ self.failUnlessEqual(
30
+ list(s.exterior.coords),
31
+ [(1.0, 3.0), (1.0, 4.0), (2.0, 4.0), (2.0, 3.0), (1.0, 3.0)] )
32
+
33
+ def test_suite():
34
+ return unittest.TestLoader().loadTestsFromTestCase(TransposeTestCase)
35
+
Binary file
@@ -0,0 +1,15 @@
1
+ from cPickle import dumps, loads, HIGHEST_PROTOCOL
2
+ import unittest
3
+ from shapely import geometry
4
+
5
+ class TwoDeeTestCase(unittest.TestCase):
6
+ """."""
7
+ def test_linestring(self):
8
+ l = geometry.LineString(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0)))
9
+ self.failUnlessEqual(l._ndim, 2)
10
+ s = dumps(l, HIGHEST_PROTOCOL)
11
+ t = loads(s)
12
+ self.failUnlessEqual(t._ndim, 2)
13
+
14
+ def test_suite():
15
+ return unittest.TestLoader().loadTestsFromTestCase(TwoDeeTestCase)
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,17 @@
1
+ import unittest
2
+ from shapely.geometry import CAP_STYLE, JOIN_STYLE
3
+
4
+ class StylesTest(unittest.TestCase):
5
+ def test_cap(self):
6
+ self.assertEqual(CAP_STYLE.round, 1)
7
+ self.assertEqual(CAP_STYLE.flat, 2)
8
+ self.assertEqual(CAP_STYLE.square, 3)
9
+ def test_join(self):
10
+ self.assertEqual(JOIN_STYLE.round, 1)
11
+ self.assertEqual(JOIN_STYLE.mitre, 2)
12
+ self.assertEqual(JOIN_STYLE.bevel, 3)
13
+
14
+ def test_suite():
15
+ loader = unittest.TestLoader()
16
+ return unittest.TestSuite([
17
+ unittest.TestLoader().loadTestsFromTestCase(StylesTest)])
Binary file
@@ -0,0 +1,61 @@
1
+ import unittest
2
+ from shapely import geometry
3
+ from shapely.ops import transform
4
+
5
+ class IdentityTestCase(unittest.TestCase):
6
+ """New geometry/coordseq method 'xy' makes numpy interop easier"""
7
+ def func(self, x, y, z=None):
8
+ return tuple(filter(None, [x, y, z]))
9
+ def test_point(self):
10
+ g = geometry.Point(0, 1)
11
+ h = transform(self.func, g)
12
+ self.failUnlessEqual(h.geom_type, 'Point')
13
+ self.failUnlessEqual(list(h.coords), [(0, 1)])
14
+ def test_line(self):
15
+ g = geometry.LineString(((0, 1), (2, 3)))
16
+ h = transform(self.func, g)
17
+ self.failUnlessEqual(h.geom_type, 'LineString')
18
+ self.failUnlessEqual(list(h.coords), [(0, 1), (2, 3)])
19
+ def test_polygon(self):
20
+ g = geometry.Point(0, 1).buffer(1.0)
21
+ h = transform(self.func, g)
22
+ self.failUnlessEqual(h.geom_type, 'Polygon')
23
+ self.failUnlessAlmostEqual(g.area, h.area)
24
+ def test_multipolygon(self):
25
+ g = geometry.MultiPoint([(0, 1), (0, 4)]).buffer(1.0)
26
+ h = transform(self.func, g)
27
+ self.failUnlessEqual(h.geom_type, 'MultiPolygon')
28
+ self.failUnlessAlmostEqual(g.area, h.area)
29
+
30
+ class LambdaTestCase(unittest.TestCase):
31
+ """New geometry/coordseq method 'xy' makes numpy interop easier"""
32
+ def test_point(self):
33
+ g = geometry.Point(0, 1)
34
+ h = transform(lambda x, y, z=None: (x+1.0, y+1.0), g)
35
+ self.failUnlessEqual(h.geom_type, 'Point')
36
+ self.failUnlessEqual(list(h.coords), [(1.0, 2.0)])
37
+ def test_line(self):
38
+ g = geometry.LineString(((0, 1), (2, 3)))
39
+ h = transform(lambda x, y, z=None: (x+1.0, y+1.0), g)
40
+ self.failUnlessEqual(h.geom_type, 'LineString')
41
+ self.failUnlessEqual(list(h.coords), [(1.0, 2.0), (3.0, 4.0)])
42
+ def test_polygon(self):
43
+ g = geometry.Point(0, 1).buffer(1.0)
44
+ h = transform(lambda x, y, z=None: (x+1.0, y+1.0), g)
45
+ self.failUnlessEqual(h.geom_type, 'Polygon')
46
+ self.failUnlessAlmostEqual(g.area, h.area)
47
+ self.failUnlessAlmostEqual(h.centroid.x, 1.0)
48
+ self.failUnlessAlmostEqual(h.centroid.y, 2.0)
49
+ def test_multipolygon(self):
50
+ g = geometry.MultiPoint([(0, 1), (0, 4)]).buffer(1.0)
51
+ h = transform(lambda x, y, z=None: (x+1.0, y+1.0), g)
52
+ self.failUnlessEqual(h.geom_type, 'MultiPolygon')
53
+ self.failUnlessAlmostEqual(g.area, h.area)
54
+ self.failUnlessAlmostEqual(h.centroid.x, 1.0)
55
+ self.failUnlessAlmostEqual(h.centroid.y, 3.5)
56
+
57
+ def test_suite():
58
+ loader = unittest.TestLoader()
59
+ return unittest.TestSuite([
60
+ unittest.TestLoader().loadTestsFromTestCase(IdentityTestCase),
61
+ unittest.TestLoader().loadTestsFromTestCase(LambdaTestCase)])
Binary file