shapely 1.2.14__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.
- EGG-INFO/PKG-INFO +451 -380
- EGG-INFO/native_libs.txt +2 -0
- EGG-INFO/not-zip-safe +1 -1
- 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,35 @@
|
|
|
1
|
+
Persistence tests
|
|
2
|
+
=================
|
|
3
|
+
|
|
4
|
+
Pickle
|
|
5
|
+
------
|
|
6
|
+
|
|
7
|
+
>>> from shapely.geometry import Point
|
|
8
|
+
>>> import pickle
|
|
9
|
+
>>> p = Point(0.0, 0.0)
|
|
10
|
+
>>> data = pickle.dumps(p)
|
|
11
|
+
>>> q = pickle.loads(data)
|
|
12
|
+
>>> q.equals(p)
|
|
13
|
+
True
|
|
14
|
+
|
|
15
|
+
WKB
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
>>> from shapely import wkb
|
|
19
|
+
>>> bytes = wkb.dumps(p)
|
|
20
|
+
>>> pb = wkb.loads(bytes)
|
|
21
|
+
>>> pb.equals(p)
|
|
22
|
+
True
|
|
23
|
+
|
|
24
|
+
WKT
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
>>> from shapely import wkt
|
|
28
|
+
>>> text = wkt.dumps(p)
|
|
29
|
+
>>> text
|
|
30
|
+
'POINT (0.0000000000000000 0.0000000000000000)'
|
|
31
|
+
>>> pt = wkt.loads(text)
|
|
32
|
+
>>> pt.equals(p)
|
|
33
|
+
True
|
|
34
|
+
|
|
35
|
+
|
shapely/tests/Point.txt
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
Testing Point
|
|
2
|
+
=============
|
|
3
|
+
|
|
4
|
+
>>> from shapely.geometry import Point
|
|
5
|
+
|
|
6
|
+
Test 2D points
|
|
7
|
+
|
|
8
|
+
>>> p = Point(0.0, 0.0)
|
|
9
|
+
>>> str(p)
|
|
10
|
+
'POINT (0.0000000000000000 0.0000000000000000)'
|
|
11
|
+
>>> p.wkt
|
|
12
|
+
'POINT (0.0000000000000000 0.0000000000000000)'
|
|
13
|
+
|
|
14
|
+
Check 3D
|
|
15
|
+
|
|
16
|
+
>>> p = Point(0.0, 0.0, 1.0)
|
|
17
|
+
>>> p.z
|
|
18
|
+
1.0
|
|
19
|
+
>>> str(p)
|
|
20
|
+
'POINT (0.0000000000000000 0.0000000000000000)'
|
|
21
|
+
>>> p.wkt
|
|
22
|
+
'POINT (0.0000000000000000 0.0000000000000000)'
|
|
23
|
+
|
|
24
|
+
Construct from a numpy array
|
|
25
|
+
|
|
26
|
+
>>> from numpy import array
|
|
27
|
+
>>> p = Point(array([1.0, 2.0]))
|
|
28
|
+
>>> p.wkt
|
|
29
|
+
'POINT (1.0000000000000000 2.0000000000000000)'
|
|
30
|
+
|
|
31
|
+
From coordinate sequence
|
|
32
|
+
|
|
33
|
+
>>> p = Point((3.0, 4.0))
|
|
34
|
+
>>> p.wkt
|
|
35
|
+
'POINT (3.0000000000000000 4.0000000000000000)'
|
|
36
|
+
|
|
37
|
+
From another point
|
|
38
|
+
|
|
39
|
+
>>> q = Point(p)
|
|
40
|
+
>>> print p.wkt
|
|
41
|
+
POINT (3.0000000000000000 4.0000000000000000)
|
|
42
|
+
|
|
43
|
+
Coordinate access
|
|
44
|
+
-----------------
|
|
45
|
+
|
|
46
|
+
>>> p.x
|
|
47
|
+
3.0
|
|
48
|
+
>>> p.y
|
|
49
|
+
4.0
|
|
50
|
+
|
|
51
|
+
>>> tuple(p.coords)
|
|
52
|
+
((3.0, 4.0),)
|
|
53
|
+
|
|
54
|
+
>>> p.coords[0]
|
|
55
|
+
(3.0, 4.0)
|
|
56
|
+
>>> p.coords[1] # doctest: +ELLIPSIS
|
|
57
|
+
Traceback (most recent call last):
|
|
58
|
+
...
|
|
59
|
+
IndexError: index out of range
|
|
60
|
+
|
|
61
|
+
Bounds
|
|
62
|
+
------
|
|
63
|
+
|
|
64
|
+
>>> p.bounds
|
|
65
|
+
(3.0, 4.0, 3.0, 4.0)
|
|
66
|
+
|
|
67
|
+
Geo interface
|
|
68
|
+
-------------
|
|
69
|
+
|
|
70
|
+
>>> p.__geo_interface__
|
|
71
|
+
{'type': 'Point', 'coordinates': (3.0, 4.0)}
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
Modify coordinates
|
|
75
|
+
------------------
|
|
76
|
+
|
|
77
|
+
>>> p.coords = (0.0, 0.0)
|
|
78
|
+
>>> p.__geo_interface__
|
|
79
|
+
{'type': 'Point', 'coordinates': (0.0, 0.0)}
|
|
80
|
+
|
|
81
|
+
Alternate method
|
|
82
|
+
|
|
83
|
+
>>> p.coords = ((0.0, 0.0),)
|
|
84
|
+
>>> p.__geo_interface__
|
|
85
|
+
{'type': 'Point', 'coordinates': (0.0, 0.0)}
|
|
86
|
+
|
|
87
|
+
Adapter
|
|
88
|
+
-------
|
|
89
|
+
|
|
90
|
+
>>> from shapely.geometry import asPoint
|
|
91
|
+
|
|
92
|
+
Adapt a Numpy array to a point
|
|
93
|
+
|
|
94
|
+
>>> a = array([1.0, 2.0])
|
|
95
|
+
>>> pa = asPoint(a)
|
|
96
|
+
>>> pa.context
|
|
97
|
+
array([ 1., 2.])
|
|
98
|
+
>>> pa.wkt
|
|
99
|
+
'POINT (1.0000000000000000 2.0000000000000000)'
|
|
100
|
+
|
|
101
|
+
Now, the inverse
|
|
102
|
+
|
|
103
|
+
>>> pa.__array_interface__ == pa.context.__array_interface__
|
|
104
|
+
True
|
|
105
|
+
>>> from numpy import asarray
|
|
106
|
+
>>> pas = asarray(pa)
|
|
107
|
+
>>> pas
|
|
108
|
+
array([ 1., 2.])
|
|
109
|
+
|
|
110
|
+
Adapt a coordinate list to a point
|
|
111
|
+
|
|
112
|
+
>>> coords = [3.0, 4.0]
|
|
113
|
+
>>> pa = asPoint(coords)
|
|
114
|
+
>>> pa.wkt
|
|
115
|
+
'POINT (3.0000000000000000 4.0000000000000000)'
|
|
116
|
+
>>> pa.distance(p)
|
|
117
|
+
5.0
|
|
118
|
+
|
|
119
|
+
Move the coordinates and watch the distance change
|
|
120
|
+
|
|
121
|
+
>>> coords[0] = 1.0
|
|
122
|
+
>>> pa.wkt
|
|
123
|
+
'POINT (1.0000000000000000 4.0000000000000000)'
|
|
124
|
+
>>> '%.10f' % pa.distance(p)
|
|
125
|
+
'4.1231056256'
|
|
126
|
+
|
|
127
|
+
Now, the inverse
|
|
128
|
+
|
|
129
|
+
>>> ai = pa.__array_interface__
|
|
130
|
+
>>> pas = asarray(pa)
|
|
131
|
+
>>> pas
|
|
132
|
+
array([ 1., 4.])
|
|
133
|
+
|
|
134
|
+
Test Non-operability of Null geometry
|
|
135
|
+
|
|
136
|
+
>>> p_null = Point()
|
|
137
|
+
>>> p_null.wkt # doctest: +ELLIPSIS
|
|
138
|
+
'GEOMETRYCOLLECTION EMPTY'
|
|
139
|
+
|
|
140
|
+
>>> p_null.area # doctest: +ELLIPSIS
|
|
141
|
+
0.0
|
|
142
|
+
|
|
143
|
+
Check that we can set coordinates of a null geometry
|
|
144
|
+
|
|
145
|
+
>>> p_null.coords = (0, 0)
|
|
146
|
+
>>> p_null.wkt
|
|
147
|
+
'POINT (0.0000000000000000 0.0000000000000000)'
|
|
148
|
+
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
Polygons and Linear Rings
|
|
2
|
+
=========================
|
|
3
|
+
|
|
4
|
+
Initialization
|
|
5
|
+
--------------
|
|
6
|
+
|
|
7
|
+
Linear rings won't usually be created by users, but by polygons
|
|
8
|
+
|
|
9
|
+
>>> coords = ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0))
|
|
10
|
+
>>> from shapely.geometry.polygon import LinearRing
|
|
11
|
+
>>> ring = LinearRing(coords)
|
|
12
|
+
>>> len(ring.coords)
|
|
13
|
+
5
|
|
14
|
+
>>> ring.coords[0] == ring.coords[4]
|
|
15
|
+
True
|
|
16
|
+
>>> ring.coords[0] == ring.coords[-1]
|
|
17
|
+
True
|
|
18
|
+
>>> ring.is_ring
|
|
19
|
+
True
|
|
20
|
+
|
|
21
|
+
Coordinate modification
|
|
22
|
+
-----------------------
|
|
23
|
+
|
|
24
|
+
>>> ring.coords = ((0.0, 0.0), (0.0, 2.0), (2.0, 2.0), (2.0, 0.0))
|
|
25
|
+
>>> ring.__geo_interface__
|
|
26
|
+
{'type': 'LinearRing', 'coordinates': ((0.0, 0.0), (0.0, 2.0), (2.0, 2.0), (2.0, 0.0), (0.0, 0.0))}
|
|
27
|
+
|
|
28
|
+
Test ring adapter
|
|
29
|
+
|
|
30
|
+
>>> coords = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]]
|
|
31
|
+
>>> from shapely.geometry.polygon import asLinearRing
|
|
32
|
+
>>> ra = asLinearRing(coords)
|
|
33
|
+
>>> ra.wkt
|
|
34
|
+
'LINEARRING (0.0000000000000000 0.0000000000000000, 0.0000000000000000 1.0000000000000000, 1.0000000000000000 1.0000000000000000, 1.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000)'
|
|
35
|
+
>>> coords[3] = [2.0, -1.0]
|
|
36
|
+
>>> ra.wkt
|
|
37
|
+
'LINEARRING (0.0000000000000000 0.0000000000000000, 0.0000000000000000 1.0000000000000000, 1.0000000000000000 1.0000000000000000, 2.0000000000000000 -1.0000000000000000, 0.0000000000000000 0.0000000000000000)'
|
|
38
|
+
|
|
39
|
+
Construct a polygon, exterior ring only
|
|
40
|
+
|
|
41
|
+
>>> from shapely.geometry import Polygon
|
|
42
|
+
>>> polygon = Polygon(coords)
|
|
43
|
+
>>> len(polygon.exterior.coords)
|
|
44
|
+
5
|
|
45
|
+
|
|
46
|
+
Ring Access
|
|
47
|
+
-----------
|
|
48
|
+
|
|
49
|
+
>>> polygon.exterior # doctest: +ELLIPSIS
|
|
50
|
+
<shapely.geometry.polygon.LinearRing object at ...>
|
|
51
|
+
>>> ring = polygon.exterior
|
|
52
|
+
>>> len(ring.coords)
|
|
53
|
+
5
|
|
54
|
+
>>> ring.coords[0] == ring.coords[4] == (0., 0.)
|
|
55
|
+
True
|
|
56
|
+
>>> ring.is_ring
|
|
57
|
+
True
|
|
58
|
+
>>> len(polygon.interiors)
|
|
59
|
+
0
|
|
60
|
+
|
|
61
|
+
Create a new polygon from WKB
|
|
62
|
+
|
|
63
|
+
>>> data = polygon.wkb
|
|
64
|
+
>>> polygon = None
|
|
65
|
+
>>> ring = None
|
|
66
|
+
>>> from shapely.wkb import loads
|
|
67
|
+
>>> polygon = loads(data)
|
|
68
|
+
>>> ring = polygon.exterior
|
|
69
|
+
>>> len(ring.coords)
|
|
70
|
+
5
|
|
71
|
+
>>> ring.coords[0] == ring.coords[4] == (0., 0.)
|
|
72
|
+
True
|
|
73
|
+
>>> ring.is_ring
|
|
74
|
+
True
|
|
75
|
+
>>> polygon = None
|
|
76
|
+
|
|
77
|
+
Interior rings (holes)
|
|
78
|
+
----------------------
|
|
79
|
+
|
|
80
|
+
>>> polygon = Polygon(coords, [((0.25,0.25), (0.25,0.5), (0.5,0.5), (0.5,0.25))])
|
|
81
|
+
>>> len(polygon.exterior.coords)
|
|
82
|
+
5
|
|
83
|
+
>>> len(polygon.interiors[0].coords)
|
|
84
|
+
5
|
|
85
|
+
>>> polygon.interiors[1] # doctest: +ELLIPSIS
|
|
86
|
+
Traceback (most recent call last):
|
|
87
|
+
...
|
|
88
|
+
IndexError: index out of range
|
|
89
|
+
|
|
90
|
+
Coordinate getters and setters raise exceptions
|
|
91
|
+
|
|
92
|
+
>>> polygon._get_coords()
|
|
93
|
+
Traceback (most recent call last):
|
|
94
|
+
...
|
|
95
|
+
NotImplementedError: Component rings have coordinate sequences, but the polygon does not
|
|
96
|
+
>>> polygon.coords
|
|
97
|
+
Traceback (most recent call last):
|
|
98
|
+
...
|
|
99
|
+
NotImplementedError: Component rings have coordinate sequences, but the polygon does not
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
Geo interface
|
|
103
|
+
-------------
|
|
104
|
+
|
|
105
|
+
>>> polygon.__geo_interface__
|
|
106
|
+
{'type': 'Polygon', 'coordinates': (((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (2.0, -1.0), (0.0, 0.0)), ((0.25, 0.25), (0.25, 0.5), (0.5, 0.5), (0.5, 0.25), (0.25, 0.25)))}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
Adapter
|
|
110
|
+
-------
|
|
111
|
+
|
|
112
|
+
>>> hole_coords = [((0.25,0.25), (0.25,0.5), (0.5,0.5), (0.5,0.25))]
|
|
113
|
+
>>> from shapely.geometry import asPolygon
|
|
114
|
+
>>> pa = asPolygon(coords, hole_coords)
|
|
115
|
+
>>> len(pa.exterior.coords)
|
|
116
|
+
5
|
|
117
|
+
>>> len(pa.interiors)
|
|
118
|
+
1
|
|
119
|
+
>>> len(pa.interiors[0].coords)
|
|
120
|
+
5
|
|
121
|
+
|
|
122
|
+
Test Non-operability of Null rings
|
|
123
|
+
|
|
124
|
+
>>> r_null = LinearRing()
|
|
125
|
+
>>> r_null.wkt # doctest: +ELLIPSIS
|
|
126
|
+
'GEOMETRYCOLLECTION EMPTY'
|
|
127
|
+
|
|
128
|
+
>>> r_null.length
|
|
129
|
+
0.0
|
|
130
|
+
|
|
131
|
+
Check that we can set coordinates of a null geometry
|
|
132
|
+
|
|
133
|
+
>>> r_null.coords = [(0, 0), (1, 1), (1, 0)]
|
|
134
|
+
>>> print r_null.length # doctest: +ELLIPSIS
|
|
135
|
+
3.414...
|
|
136
|
+
|
|
137
|
+
Error handling
|
|
138
|
+
--------------
|
|
139
|
+
|
|
140
|
+
>>> p = Polygon([[1,2], [2, 3]])
|
|
141
|
+
Traceback (most recent call last):
|
|
142
|
+
...
|
|
143
|
+
ValueError: A LinearRing must have at least 3 coordinate tuples
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
Test GEOS predicates
|
|
2
|
+
====================
|
|
3
|
+
|
|
4
|
+
>>> from shapely.geometry import Point
|
|
5
|
+
>>> point = Point(0.0, 0.0)
|
|
6
|
+
|
|
7
|
+
Binary Predicates
|
|
8
|
+
-----------------
|
|
9
|
+
|
|
10
|
+
>>> point.disjoint(Point(-1.0, -1.0))
|
|
11
|
+
True
|
|
12
|
+
|
|
13
|
+
>>> point.touches(Point(-1.0, -1.0))
|
|
14
|
+
False
|
|
15
|
+
|
|
16
|
+
>>> point.crosses(Point(-1.0, -1.0))
|
|
17
|
+
False
|
|
18
|
+
|
|
19
|
+
>>> point.within(Point(-1.0, -1.0))
|
|
20
|
+
False
|
|
21
|
+
|
|
22
|
+
>>> point.contains(Point(-1.0, -1.0))
|
|
23
|
+
False
|
|
24
|
+
|
|
25
|
+
>>> point.overlaps(Point(-1.0, -1.0))
|
|
26
|
+
False
|
|
27
|
+
|
|
28
|
+
>>> point.equals(Point(-1.0, -1.0))
|
|
29
|
+
False
|
|
30
|
+
|
|
31
|
+
>>> point.equals(Point(0.0, 0.0))
|
|
32
|
+
True
|
|
33
|
+
|
|
34
|
+
Unary Predicates
|
|
35
|
+
----------------
|
|
36
|
+
|
|
37
|
+
>>> point.is_empty
|
|
38
|
+
False
|
|
39
|
+
|
|
40
|
+
>>> point.is_valid
|
|
41
|
+
True
|
|
42
|
+
|
|
43
|
+
>>> point.is_simple
|
|
44
|
+
True
|
|
45
|
+
|
|
46
|
+
>>> point.is_ring
|
|
47
|
+
False
|
|
48
|
+
|
|
49
|
+
>>> point.has_z
|
|
50
|
+
False
|
|
51
|
+
|
shapely/tests/__init__.py
CHANGED
|
@@ -4,6 +4,8 @@ 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
6
|
import test_products_z, test_box, test_speedups, test_cga, test_getitem
|
|
7
|
+
import test_ndarrays, test_unary_union, test_pickle, test_affinity
|
|
8
|
+
import test_transform, test_styles
|
|
7
9
|
|
|
8
10
|
def test_suite():
|
|
9
11
|
suite = TestSuite()
|
|
@@ -25,5 +27,11 @@ def test_suite():
|
|
|
25
27
|
suite.addTest(test_speedups.test_suite())
|
|
26
28
|
suite.addTest(test_cga.test_suite())
|
|
27
29
|
suite.addTest(test_getitem.test_suite())
|
|
30
|
+
suite.addTest(test_ndarrays.test_suite())
|
|
31
|
+
suite.addTest(test_unary_union.test_suite())
|
|
32
|
+
suite.addTest(test_pickle.test_suite())
|
|
33
|
+
suite.addTest(test_affinity.test_suite())
|
|
34
|
+
suite.addTest(test_transform.test_suite())
|
|
35
|
+
suite.addTest(test_styles.test_suite())
|
|
28
36
|
return suite
|
|
29
37
|
|
shapely/tests/__init__.pyc
CHANGED
|
Binary file
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
Attribute Chaining
|
|
2
|
+
==================
|
|
3
|
+
|
|
4
|
+
See also ticket #151.
|
|
5
|
+
|
|
6
|
+
>>> from shapely.geometry import Polygon
|
|
7
|
+
>>> p = Polygon(((0.0, 0.0), (0.0, 1.0), (-1.0, 1.0), (-1.0, 0.0)))
|
|
8
|
+
>>> list(p.boundary.coords)
|
|
9
|
+
[(0.0, 0.0), (0.0, 1.0), (-1.0, 1.0), (-1.0, 0.0), (0.0, 0.0)]
|
|
10
|
+
|
|
11
|
+
>>> from shapely.geometry import Point
|
|
12
|
+
>>> print list(Point(0.0, 0.0).buffer(1.0, 1).exterior.coords)
|
|
13
|
+
[(1.0, 0.0), ..., (1.0, 0.0)]
|
|
14
|
+
|
|
15
|
+
Test chained access to interiors
|
|
16
|
+
|
|
17
|
+
>>> p = Polygon(
|
|
18
|
+
... ((0.0, 0.0), (0.0, 1.0), (-1.0, 1.0), (-1.0, 0.0)),
|
|
19
|
+
... [((-0.25, 0.25), (-0.25, 0.75), (-0.75, 0.75), (-0.75, 0.25))]
|
|
20
|
+
... )
|
|
21
|
+
>>> p.area
|
|
22
|
+
0.75
|
|
23
|
+
|
|
24
|
+
Not so much testing the exact values here, which are the responsibility of the
|
|
25
|
+
geometry engine (GEOS), but that we can get chain functions and properties using
|
|
26
|
+
anonymous references.
|
|
27
|
+
|
|
28
|
+
>>> print list(p.interiors[0].coords)
|
|
29
|
+
[(-0.25, 0.25), (-0.25, 0.75), (-0.75, 0.75), (-0.75, 0.25), (-0.25, 0.25)]
|
|
30
|
+
>>> xy = list(p.interiors[0].buffer(1).exterior.coords)[0]
|
|
31
|
+
>>> len(xy)
|
|
32
|
+
2
|
|
33
|
+
|
|
34
|
+
Test multiple operators, boundary of a buffer
|
|
35
|
+
|
|
36
|
+
>>> print list(p.buffer(1).boundary.coords)
|
|
37
|
+
[(0.0, -1.0), (-1.0, -1.0), ...
|
|
38
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
Round-tripping geometries through hex-encoded binary
|
|
2
|
+
====================================================
|
|
3
|
+
|
|
4
|
+
Hex-encoded binary is the PostGIS geometry representation, and so this is a
|
|
5
|
+
test of the ability to store Shapely geometries in PostGIS.
|
|
6
|
+
|
|
7
|
+
Point
|
|
8
|
+
-----
|
|
9
|
+
|
|
10
|
+
>>> from shapely.geometry import Point
|
|
11
|
+
>>> point = Point(0.0, 0.0)
|
|
12
|
+
>>> import binascii
|
|
13
|
+
>>> x = binascii.b2a_hex(point.wkb)
|
|
14
|
+
>>> from shapely import wkb
|
|
15
|
+
>>> shape = wkb.loads(binascii.a2b_hex(x))
|
|
16
|
+
>>> shape # doctest: +ELLIPSIS
|
|
17
|
+
<shapely.geometry.point.Point object at ...>
|
|
18
|
+
|
|
19
|
+
LineString
|
|
20
|
+
----------
|
|
21
|
+
|
|
22
|
+
>>> from shapely.geometry import LineString
|
|
23
|
+
>>> line = LineString(((0.0, 0.0), (1.0, 1.0)))
|
|
24
|
+
>>> x = binascii.b2a_hex(line.wkb)
|
|
25
|
+
>>> shape = wkb.loads(binascii.a2b_hex(x))
|
|
26
|
+
>>> shape # doctest: +ELLIPSIS
|
|
27
|
+
<shapely.geometry.linestring.LineString object at ...>
|
|
28
|
+
|
|
29
|
+
Polygon
|
|
30
|
+
----------
|
|
31
|
+
|
|
32
|
+
>>> from shapely.geometry import Polygon
|
|
33
|
+
>>> polygon = Polygon(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)))
|
|
34
|
+
>>> x = binascii.b2a_hex(polygon.wkb)
|
|
35
|
+
>>> shape = wkb.loads(binascii.a2b_hex(x))
|
|
36
|
+
>>> shape # doctest: +ELLIPSIS
|
|
37
|
+
<shapely.geometry.polygon.Polygon object at ...>
|
|
38
|
+
|
|
39
|
+
Polygon with hole
|
|
40
|
+
-----------------
|
|
41
|
+
|
|
42
|
+
>>> polygon = Polygon(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)), [((0.1,0.1), (0.1,0.2), (0.2,0.2), (0.2,0.1))])
|
|
43
|
+
>>> x = binascii.b2a_hex(polygon.wkb)
|
|
44
|
+
>>> shape = wkb.loads(binascii.a2b_hex(x))
|
|
45
|
+
>>> shape # doctest: +ELLIPSIS
|
|
46
|
+
<shapely.geometry.polygon.Polygon object at ...>
|
|
47
|
+
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
Cascaded Union
|
|
2
|
+
==============
|
|
3
|
+
|
|
4
|
+
>>> from shapely.ftools import partial
|
|
5
|
+
>>> import random
|
|
6
|
+
>>> from shapely.geometry import Point
|
|
7
|
+
>>> from shapely.ops import cascaded_union
|
|
8
|
+
|
|
9
|
+
Use a partial function to make 100 points uniformly distributed in a 40x40
|
|
10
|
+
box centered on 0,0.
|
|
11
|
+
|
|
12
|
+
>>> r = partial(random.uniform, -20.0, 20.0)
|
|
13
|
+
>>> points = [Point(r(), r()) for i in range(100)]
|
|
14
|
+
|
|
15
|
+
Buffer the points, producing 100 polygon spots
|
|
16
|
+
|
|
17
|
+
>>> spots = [p.buffer(2.5) for p in points]
|
|
18
|
+
|
|
19
|
+
Perform a cascaded union of the polygon spots, dissolving them into a
|
|
20
|
+
collection of polygon patches
|
|
21
|
+
|
|
22
|
+
>>> u = cascaded_union(spots)
|
|
23
|
+
>>> u.geom_type in ('Polygon', 'MultiPolygon')
|
|
24
|
+
True
|
|
25
|
+
|
|
26
|
+
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
Background: see http://trac.gispython.org/lab/ticket/168
|
|
2
|
+
|
|
3
|
+
>>> from shapely.geometry import Polygon
|
|
4
|
+
>>> coords = ((0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (1.0, 1.0, 0.0), (1.0, 0.0, 0.0))
|
|
5
|
+
>>> polygon = Polygon(coords)
|
|
6
|
+
>>> polygon._ndim
|
|
7
|
+
3
|
|
8
|
+
>>> gi = polygon.__geo_interface__
|
|
9
|
+
>>> gi['coordinates']
|
|
10
|
+
(((0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (1.0, 1.0, 0.0), (1.0, 0.0, 0.0), (0.0, 0.0, 0.0)),)
|
|
11
|
+
|
|
12
|
+
>>> e = polygon.exterior
|
|
13
|
+
>>> e._ndim
|
|
14
|
+
3
|
|
15
|
+
>>> gi = e.__geo_interface__
|
|
16
|
+
>>> gi['coordinates']
|
|
17
|
+
((0.0, 0.0, 0.0), (0.0, 1.0, 0.0), (1.0, 1.0, 0.0), (1.0, 0.0, 0.0), (0.0, 0.0, 0.0))
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
Test recovery from operation on invalid geometries
|
|
2
|
+
==================================================
|
|
3
|
+
|
|
4
|
+
Make a self-intersecting polygon
|
|
5
|
+
|
|
6
|
+
>>> from shapely.geometry import Polygon
|
|
7
|
+
>>> polygon_invalid = Polygon(((0, 0), (1, 1), (1, -1), (0, 1), (0, 0)))
|
|
8
|
+
>>> print polygon_invalid.is_valid # doctest: +ELLIPSIS
|
|
9
|
+
False
|
|
10
|
+
|
|
11
|
+
Intersect with a valid polygon
|
|
12
|
+
|
|
13
|
+
>>> polygon = Polygon(((-.5, -.5), (-.5, .5), (.5, .5), (.5, -5)))
|
|
14
|
+
>>> polygon.is_valid
|
|
15
|
+
True
|
|
16
|
+
>>> polygon_invalid.intersects(polygon)
|
|
17
|
+
True
|
|
18
|
+
>>> result = polygon_invalid.intersection(polygon) # doctest: +ELLIPSIS
|
|
19
|
+
Traceback (most recent call last):
|
|
20
|
+
...
|
|
21
|
+
TopologicalError: The operation 'GEOSIntersection_r' produced a null geometry. Likely cause is invalidity of the geometry <shapely.geometry.polygon.Polygon object at ...>
|
|
22
|
+
|
|
23
|
+
Check exception symmetry
|
|
24
|
+
|
|
25
|
+
>>> result = polygon.intersection(polygon_invalid) # doctest: +ELLIPSIS
|
|
26
|
+
Traceback (most recent call last):
|
|
27
|
+
...
|
|
28
|
+
TopologicalError: The operation 'GEOSIntersection_r' produced a null geometry. Likely cause is invalidity of the 'other' geometry <shapely.geometry.polygon.Polygon object at ...>
|
|
29
|
+
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
Linemerge
|
|
2
|
+
=========
|
|
3
|
+
|
|
4
|
+
>>> from shapely.geometry import LineString, MultiLineString, Polygon
|
|
5
|
+
>>> from shapely.ops import linemerge
|
|
6
|
+
|
|
7
|
+
>>> lines = MultiLineString([
|
|
8
|
+
... ((0, 0), (1, 1)),
|
|
9
|
+
... ((2, 0), (2, 1), (1, 1))
|
|
10
|
+
... ])
|
|
11
|
+
>>> result = linemerge(lines)
|
|
12
|
+
>>> result # docstring: +ELLIPSIS
|
|
13
|
+
<shapely.geometry.linestring.LineString object at 0x...>
|
|
14
|
+
>>> result.is_ring
|
|
15
|
+
False
|
|
16
|
+
>>> len(result.coords)
|
|
17
|
+
4
|
|
18
|
+
>>> result.coords[0]
|
|
19
|
+
(0.0, 0.0)
|
|
20
|
+
>>> result.coords[3]
|
|
21
|
+
(2.0, 0.0)
|
|
22
|
+
|
|
23
|
+
>>> lines2 = MultiLineString([
|
|
24
|
+
... ((0, 0), (1, 1)),
|
|
25
|
+
... ((0, 0), (2, 0), (2, 1), (1, 1))
|
|
26
|
+
... ])
|
|
27
|
+
>>> result = linemerge(lines2)
|
|
28
|
+
>>> result.is_ring
|
|
29
|
+
True
|
|
30
|
+
>>> len(result.coords)
|
|
31
|
+
5
|
|
32
|
+
|
|
33
|
+
>>> lines3 = [
|
|
34
|
+
... LineString(((0, 0), (1, 1))),
|
|
35
|
+
... LineString(((0, 0), (0, 1))),
|
|
36
|
+
... ]
|
|
37
|
+
>>> result = linemerge(lines3)
|
|
38
|
+
>>> result.is_ring
|
|
39
|
+
False
|
|
40
|
+
>>> len(result.coords)
|
|
41
|
+
3
|
|
42
|
+
>>> result.coords[0]
|
|
43
|
+
(0.0, 1.0)
|
|
44
|
+
>>> result.coords[2]
|
|
45
|
+
(1.0, 1.0)
|
|
46
|
+
|
|
47
|
+
>>> lines4 = [
|
|
48
|
+
... ((0, 0), (1, 1)),
|
|
49
|
+
... ((0, 0), (0, 1)),
|
|
50
|
+
... ]
|
|
51
|
+
>>> result.equals(linemerge(lines4))
|
|
52
|
+
True
|
|
53
|
+
|
|
54
|
+
>>> lines5 = [
|
|
55
|
+
... ((0, 0), (1, 1)),
|
|
56
|
+
... ((1, 0), (0, 1)),
|
|
57
|
+
... ]
|
|
58
|
+
>>> result = linemerge(lines5)
|
|
59
|
+
>>> result.type == 'MultiLineString'
|
|
60
|
+
True
|
|
61
|
+
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
Polygonizing
|
|
2
|
+
============
|
|
3
|
+
|
|
4
|
+
>>> from shapely.geometry import LineString, Point
|
|
5
|
+
>>> from shapely.ops import polygonize, polygonize_full
|
|
6
|
+
>>> lines = [
|
|
7
|
+
... LineString(((0, 0), (1, 1))),
|
|
8
|
+
... LineString(((0, 0), (0, 1))),
|
|
9
|
+
... LineString(((0, 1), (1, 1))),
|
|
10
|
+
... LineString(((1, 1), (1, 0))),
|
|
11
|
+
... LineString(((1, 0), (0, 0))),
|
|
12
|
+
... LineString(((5, 5), (6, 6))),
|
|
13
|
+
... Point(0, 0),
|
|
14
|
+
... ]
|
|
15
|
+
>>> result = polygonize(lines)
|
|
16
|
+
>>> list(result)
|
|
17
|
+
[<shapely.geometry.polygon.Polygon object at ...>, <shapely.geometry.polygon.Polygon object at ...>]
|
|
18
|
+
|
|
19
|
+
>>> lines2 = [
|
|
20
|
+
... ((0, 0), (1, 1)),
|
|
21
|
+
... ((0, 0), (0, 1)),
|
|
22
|
+
... ((0, 1), (1, 1)),
|
|
23
|
+
... ((1, 1), (1, 0)),
|
|
24
|
+
... ((1, 0), (0, 0)),
|
|
25
|
+
... ((5, 5), (6, 6)),
|
|
26
|
+
... ((1, 1), (100, 100)),
|
|
27
|
+
... ]
|
|
28
|
+
>>> result2, dangles, cuts, invalids = polygonize_full(lines2)
|
|
29
|
+
>>> len(result2)
|
|
30
|
+
2
|
|
31
|
+
>>> list(result2.geoms)
|
|
32
|
+
[<shapely.geometry.polygon.Polygon object at ...>, <shapely.geometry.polygon.Polygon object at ...>]
|
|
33
|
+
>>> list(dangles.geoms)
|
|
34
|
+
[]
|
|
35
|
+
>>> list(cuts.geoms)
|
|
36
|
+
[<shapely.geometry.linestring.LineString object at ...>, <shapely.geometry.linestring.LineString object at ...>]
|
|
37
|
+
>>> print cuts.wkt
|
|
38
|
+
GEOMETRYCOLLECTION (LINESTRING (1.0000000000000000 1.0000000000000000, 100.0000000000000000 100.0000000000000000), LINESTRING (5.0000000000000000 5.0000000000000000, 6.0000000000000000 6.0000000000000000))
|
|
39
|
+
>>> list(invalids.geoms)
|
|
40
|
+
[]
|