shapely 1.2.14__py2.7-win-amd64.egg → 1.2.18__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 +452 -381
- EGG-INFO/SOURCES.txt +96 -0
- EGG-INFO/dependency_links.txt +1 -0
- EGG-INFO/native_libs.txt +2 -0
- EGG-INFO/not-zip-safe +1 -1
- EGG-INFO/top_level.txt +1 -0
- shapely/DLLs/geos.dll +0 -0
- shapely/DLLs/geos_c.dll +0 -0
- shapely/__init__.py +1 -2
- shapely/__init__.pyc +0 -0
- shapely/affinity.py +252 -0
- shapely/affinity.pyc +0 -0
- shapely/algorithms/__init__.pyc +0 -0
- shapely/algorithms/cga.pyc +0 -0
- shapely/coords.py +15 -0
- shapely/coords.pyc +0 -0
- shapely/ctypes_declarations.py +16 -3
- shapely/ctypes_declarations.pyc +0 -0
- shapely/examples/__init__.pyc +0 -0
- shapely/examples/dissolve.pyc +0 -0
- shapely/examples/geoms.pyc +0 -0
- shapely/examples/intersect.pyc +0 -0
- shapely/examples/world.pyc +0 -0
- shapely/ftools.pyc +0 -0
- shapely/geometry/__init__.py +4 -4
- shapely/geometry/__init__.pyc +0 -0
- shapely/geometry/base.py +127 -38
- shapely/geometry/base.pyc +0 -0
- shapely/geometry/collection.pyc +0 -0
- shapely/geometry/geo.py +2 -2
- shapely/geometry/geo.pyc +0 -0
- shapely/geometry/linestring.py +24 -19
- shapely/geometry/linestring.pyc +0 -0
- shapely/geometry/multilinestring.py +1 -1
- shapely/geometry/multilinestring.pyc +0 -0
- shapely/geometry/multipoint.py +4 -0
- shapely/geometry/multipoint.pyc +0 -0
- shapely/geometry/multipolygon.py +7 -4
- shapely/geometry/multipolygon.pyc +0 -0
- shapely/geometry/point.py +7 -0
- shapely/geometry/point.pyc +0 -0
- shapely/geometry/polygon.py +11 -1
- shapely/geometry/polygon.pyc +0 -0
- shapely/geometry/proxy.py +1 -3
- shapely/geometry/proxy.pyc +0 -0
- shapely/geos.py +45 -14
- shapely/geos.pyc +0 -0
- shapely/impl.py +8 -5
- shapely/impl.pyc +0 -0
- shapely/iterops.pyc +0 -0
- shapely/linref.pyc +0 -0
- shapely/ops.py +125 -3
- shapely/ops.pyc +0 -0
- shapely/predicates.pyc +0 -0
- shapely/prepared.pyc +0 -0
- shapely/speedups/__init__.pyc +0 -0
- shapely/speedups/_speedups.c +5201 -0
- shapely/speedups/_speedups.pyc +0 -0
- shapely/speedups/_speedups.pyd +0 -0
- shapely/tests/Array.txt +86 -0
- shapely/tests/GeoInterface.txt +69 -0
- shapely/tests/IterOps.txt +31 -0
- shapely/tests/LineString.txt +134 -0
- shapely/tests/MultiLineString.txt +81 -0
- shapely/tests/MultiPoint.txt +101 -0
- shapely/tests/MultiPolygon.txt +71 -0
- shapely/tests/Operations.txt +89 -0
- shapely/tests/Operators.txt +18 -0
- shapely/tests/Persist.txt +35 -0
- shapely/tests/Point.txt +148 -0
- shapely/tests/Polygon.txt +143 -0
- shapely/tests/Predicates.txt +51 -0
- shapely/tests/__init__.py +8 -0
- shapely/tests/__init__.pyc +0 -0
- shapely/tests/attribute-chains.txt +38 -0
- shapely/tests/binascii_hex.txt +47 -0
- shapely/tests/cascaded_union.txt +26 -0
- shapely/tests/dimensions.txt +17 -0
- shapely/tests/invalid_intersection.txt +29 -0
- shapely/tests/linemerge.txt +61 -0
- shapely/tests/polygonize.txt +40 -0
- shapely/tests/test_affinity.py +239 -0
- shapely/tests/test_affinity.pyc +0 -0
- shapely/tests/test_box.pyc +0 -0
- shapely/tests/test_cga.pyc +0 -0
- shapely/tests/test_collection.py +15 -0
- shapely/tests/test_collection.pyc +0 -0
- shapely/tests/test_delegated.pyc +0 -0
- shapely/tests/test_dlls.py +1 -1
- shapely/tests/test_dlls.pyc +0 -0
- shapely/tests/test_doctests.pyc +0 -0
- shapely/tests/test_emptiness.py +41 -8
- shapely/tests/test_emptiness.pyc +0 -0
- shapely/tests/test_equality.pyc +0 -0
- shapely/tests/test_geomseq.pyc +0 -0
- shapely/tests/test_getitem.pyc +0 -0
- shapely/tests/test_linear_referencing.pyc +0 -0
- shapely/tests/test_mapping.pyc +0 -0
- shapely/tests/test_ndarrays.py +35 -0
- shapely/tests/test_ndarrays.pyc +0 -0
- shapely/tests/test_pickle.py +15 -0
- shapely/tests/test_pickle.pyc +0 -0
- shapely/tests/test_prepared.pyc +0 -0
- shapely/tests/test_products_z.pyc +0 -0
- shapely/tests/test_singularity.pyc +0 -0
- shapely/tests/test_speedups.pyc +0 -0
- shapely/tests/test_styles.py +17 -0
- shapely/tests/test_styles.pyc +0 -0
- shapely/tests/test_transform.py +61 -0
- shapely/tests/test_transform.pyc +0 -0
- shapely/tests/test_unary_union.py +40 -0
- shapely/tests/test_unary_union.pyc +0 -0
- shapely/tests/test_validation.pyc +0 -0
- shapely/tests/test_xy.pyc +0 -0
- shapely/tests/threading_test.pyc +0 -0
- shapely/tests/wkt_locale.txt +28 -0
- shapely/topology.pyc +0 -0
- shapely/validation.pyc +0 -0
- shapely/wkb.py +3 -17
- shapely/wkb.pyc +0 -0
- shapely/wkt.py +3 -13
- shapely/wkt.pyc +0 -0
- DLLs/geos.dll +0 -0
- 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
|
shapely/tests/test_box.pyc
CHANGED
|
Binary file
|
shapely/tests/test_cga.pyc
CHANGED
|
Binary file
|
shapely/tests/test_collection.py
CHANGED
|
@@ -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
|
shapely/tests/test_delegated.pyc
CHANGED
|
Binary file
|
shapely/tests/test_dlls.py
CHANGED
|
@@ -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('
|
|
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',
|
shapely/tests/test_dlls.pyc
CHANGED
|
Binary file
|
shapely/tests/test_doctests.pyc
CHANGED
|
Binary file
|
shapely/tests/test_emptiness.py
CHANGED
|
@@ -1,19 +1,52 @@
|
|
|
1
1
|
import unittest
|
|
2
2
|
from shapely.geometry.base import BaseGeometry
|
|
3
|
-
|
|
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.
|
|
9
|
-
|
|
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.
|
|
13
|
+
p = sgeom.Point(0, 0)
|
|
14
|
+
self.assertFalse(p._is_empty)
|
|
15
15
|
p.empty()
|
|
16
|
-
self.
|
|
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()
|
shapely/tests/test_emptiness.pyc
CHANGED
|
Binary file
|
shapely/tests/test_equality.pyc
CHANGED
|
Binary file
|
shapely/tests/test_geomseq.pyc
CHANGED
|
Binary file
|
shapely/tests/test_getitem.pyc
CHANGED
|
Binary file
|
|
Binary file
|
shapely/tests/test_mapping.pyc
CHANGED
|
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
|
shapely/tests/test_prepared.pyc
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
shapely/tests/test_speedups.pyc
CHANGED
|
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
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from itertools import islice
|
|
2
|
+
import unittest
|
|
3
|
+
from shapely.geometry import Point
|
|
4
|
+
from shapely.ops import unary_union
|
|
5
|
+
|
|
6
|
+
def halton(base):
|
|
7
|
+
"""Returns an iterator over an infinite Halton sequence"""
|
|
8
|
+
def value(index):
|
|
9
|
+
result = 0.0
|
|
10
|
+
f = 1.0/base
|
|
11
|
+
i = index
|
|
12
|
+
while i > 0:
|
|
13
|
+
result += f * (i % base)
|
|
14
|
+
i = i/base
|
|
15
|
+
f = f/base
|
|
16
|
+
return result
|
|
17
|
+
i = 1
|
|
18
|
+
while i > 0:
|
|
19
|
+
yield value(i)
|
|
20
|
+
i += 1
|
|
21
|
+
|
|
22
|
+
class UnionTestCase(unittest.TestCase):
|
|
23
|
+
def test_1(self):
|
|
24
|
+
# Instead of random points, use deterministic, pseudo-random Halton
|
|
25
|
+
# sequences for repeatability sake.
|
|
26
|
+
coords = zip(
|
|
27
|
+
list(islice(halton(5), 20, 120)),
|
|
28
|
+
list(islice(halton(7), 20, 120)) )
|
|
29
|
+
patches = [Point(xy).buffer(0.05) for xy in coords]
|
|
30
|
+
u = unary_union(patches)
|
|
31
|
+
self.failUnlessEqual(u.geom_type, 'MultiPolygon')
|
|
32
|
+
self.failUnlessAlmostEqual(u.area, 0.71857254056)
|
|
33
|
+
|
|
34
|
+
def test_suite():
|
|
35
|
+
try:
|
|
36
|
+
patches = [Point((0, 0)).buffer(0.05)]
|
|
37
|
+
unary_union(patches)
|
|
38
|
+
except KeyError:
|
|
39
|
+
return lambda x: None
|
|
40
|
+
return unittest.TestLoader().loadTestsFromTestCase(UnionTestCase)
|
|
Binary file
|
|
Binary file
|
shapely/tests/test_xy.pyc
CHANGED
|
Binary file
|
shapely/tests/threading_test.pyc
CHANGED
|
Binary file
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Test locale independence of WKT
|
|
2
|
+
===============================
|
|
3
|
+
|
|
4
|
+
Set locale to one that uses a comma as decimal seperator`
|
|
5
|
+
|
|
6
|
+
>>> import locale, sys
|
|
7
|
+
>>> if sys.platform == 'win32':
|
|
8
|
+
... _ = locale.setlocale(locale.LC_ALL, 'portuguese_brazil')
|
|
9
|
+
... else:
|
|
10
|
+
... _ = locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8')
|
|
11
|
+
|
|
12
|
+
Test reading and writing`
|
|
13
|
+
|
|
14
|
+
>>> from shapely.wkt import loads
|
|
15
|
+
>>> p = loads('POINT (0.0 0.0)')
|
|
16
|
+
>>> p.x == 0.0
|
|
17
|
+
True
|
|
18
|
+
>>> p.y == 0.0
|
|
19
|
+
True
|
|
20
|
+
>>> p.wkt
|
|
21
|
+
'POINT (0.0...)'
|
|
22
|
+
>>> from shapely.wkt import dumps
|
|
23
|
+
>>> dumps(p)
|
|
24
|
+
'POINT (0.0...)'
|
|
25
|
+
|
|
26
|
+
Reset locale
|
|
27
|
+
|
|
28
|
+
>>> _ = locale.setlocale(locale.LC_ALL, '')
|
shapely/topology.pyc
CHANGED
|
Binary file
|
shapely/validation.pyc
CHANGED
|
Binary file
|
shapely/wkb.py
CHANGED
|
@@ -1,24 +1,13 @@
|
|
|
1
1
|
"""Load/dump geometries using the well-known binary (WKB) format
|
|
2
2
|
"""
|
|
3
3
|
|
|
4
|
-
from
|
|
5
|
-
|
|
6
|
-
from shapely.geos import lgeos, ReadingError
|
|
7
|
-
|
|
4
|
+
from shapely.geometry.base import geom_from_wkb, geom_to_wkb
|
|
8
5
|
|
|
9
6
|
# Pickle-like convenience functions
|
|
10
7
|
|
|
11
|
-
def deserialize(data):
|
|
12
|
-
geom = lgeos.GEOSGeomFromWKB_buf(c_char_p(data), c_size_t(len(data)));
|
|
13
|
-
if not geom:
|
|
14
|
-
raise ReadingError(
|
|
15
|
-
"Could not create geometry because of errors while reading input.")
|
|
16
|
-
return geom
|
|
17
|
-
|
|
18
8
|
def loads(data):
|
|
19
9
|
"""Load a geometry from a WKB string."""
|
|
20
|
-
|
|
21
|
-
return geom_factory(deserialize(data))
|
|
10
|
+
return geom_from_wkb(data)
|
|
22
11
|
|
|
23
12
|
def load(fp):
|
|
24
13
|
"""Load a geometry from an open file."""
|
|
@@ -27,10 +16,7 @@ def load(fp):
|
|
|
27
16
|
|
|
28
17
|
def dumps(ob):
|
|
29
18
|
"""Dump a WKB representation of a geometry to a byte string."""
|
|
30
|
-
|
|
31
|
-
raise ValueError("Null geometry supports no operations")
|
|
32
|
-
size = c_size_t()
|
|
33
|
-
return lgeos.GEOSGeomToWKB_buf(c_void_p(ob._geom), pointer(size))
|
|
19
|
+
return geom_to_wkb(ob)
|
|
34
20
|
|
|
35
21
|
def dump(ob, fp):
|
|
36
22
|
"""Dump a geometry to an open file."""
|
shapely/wkb.pyc
CHANGED
|
Binary file
|