shapely 1.2.13__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 -377
- 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 +53 -21
- 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 +155 -54
- 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 +2 -2
- shapely/geometry/multilinestring.pyc +0 -0
- shapely/geometry/multipoint.py +4 -0
- shapely/geometry/multipoint.pyc +0 -0
- shapely/geometry/multipolygon.py +8 -5
- shapely/geometry/multipolygon.pyc +0 -0
- shapely/geometry/point.py +7 -0
- shapely/geometry/point.pyc +0 -0
- shapely/geometry/polygon.py +28 -9
- 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 +10 -1
- 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.py +113 -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
shapely/speedups/_speedups.pyc
CHANGED
|
Binary file
|
shapely/speedups/_speedups.pyd
CHANGED
|
Binary file
|
shapely/tests/Array.txt
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
Test implementation of array interface
|
|
2
|
+
======================================
|
|
3
|
+
|
|
4
|
+
>>> from shapely.geometry import Point
|
|
5
|
+
|
|
6
|
+
>>> p = Point(0.0, 0.0, 1.0)
|
|
7
|
+
>>> coords = p.coords[0]
|
|
8
|
+
>>> coords
|
|
9
|
+
(0.0, 0.0, 1.0)
|
|
10
|
+
>>> p.ctypes #doctest: +ELLIPSIS
|
|
11
|
+
<shapely.geometry.point.c_double_Array_3 object at ...>
|
|
12
|
+
|
|
13
|
+
Convert to Numpy array, passing through Python sequence
|
|
14
|
+
|
|
15
|
+
>>> from numpy import asarray
|
|
16
|
+
>>> a = asarray(coords)
|
|
17
|
+
>>> a.ndim
|
|
18
|
+
1
|
|
19
|
+
>>> a.size
|
|
20
|
+
3
|
|
21
|
+
>>> a.shape
|
|
22
|
+
(3,)
|
|
23
|
+
|
|
24
|
+
Convert to Numpy array, passing through a ctypes array
|
|
25
|
+
|
|
26
|
+
>>> b = asarray(p)
|
|
27
|
+
>>> b.size
|
|
28
|
+
3
|
|
29
|
+
>>> b.shape
|
|
30
|
+
(3,)
|
|
31
|
+
>>> b[0]
|
|
32
|
+
0.0
|
|
33
|
+
>>> b[1]
|
|
34
|
+
0.0
|
|
35
|
+
>>> b[2]
|
|
36
|
+
1.0
|
|
37
|
+
|
|
38
|
+
Make a point from a Numpy array
|
|
39
|
+
|
|
40
|
+
>>> a = asarray([1.0, 1.0, 0.0])
|
|
41
|
+
>>> p = Point(*list(a))
|
|
42
|
+
>>> p.wkt
|
|
43
|
+
'POINT (1.0000000000000000 1.0000000000000000)'
|
|
44
|
+
|
|
45
|
+
LineString
|
|
46
|
+
----------
|
|
47
|
+
|
|
48
|
+
>>> a = asarray([[0.0, 0.0], [2.0, 2.0], [1.0, 1.0]])
|
|
49
|
+
>>> from shapely.geometry import LineString
|
|
50
|
+
>>> line = LineString(a)
|
|
51
|
+
>>> line.wkt
|
|
52
|
+
'LINESTRING (0.0000000000000000 0.0000000000000000, 2.0000000000000000 2.0000000000000000, 1.0000000000000000 1.0000000000000000)'
|
|
53
|
+
|
|
54
|
+
>>> data = line.ctypes
|
|
55
|
+
>>> data[0]
|
|
56
|
+
0.0
|
|
57
|
+
>>> data[5]
|
|
58
|
+
1.0
|
|
59
|
+
|
|
60
|
+
>>> b = asarray(line)
|
|
61
|
+
>>> b.shape
|
|
62
|
+
(3, 2)
|
|
63
|
+
>>> b
|
|
64
|
+
array([[ 0., 0.],
|
|
65
|
+
[ 2., 2.],
|
|
66
|
+
[ 1., 1.]])
|
|
67
|
+
|
|
68
|
+
Polygon
|
|
69
|
+
-------
|
|
70
|
+
|
|
71
|
+
>>> a = asarray(((0., 0.), (0., 1.), (1., 1.), (1., 0.), (0., 0.)))
|
|
72
|
+
>>> from shapely.geometry import Polygon
|
|
73
|
+
>>> polygon = Polygon(a)
|
|
74
|
+
>>> polygon.wkt
|
|
75
|
+
'POLYGON ((0.0000000000000000 0.0000000000000000, 0.0000000000000000 1.0000000000000000, 1.0000000000000000 1.0000000000000000, 1.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000))'
|
|
76
|
+
|
|
77
|
+
>>> b = asarray(polygon.exterior)
|
|
78
|
+
>>> b.shape
|
|
79
|
+
(5, 2)
|
|
80
|
+
>>> b
|
|
81
|
+
array([[ 0., 0.],
|
|
82
|
+
[ 0., 1.],
|
|
83
|
+
[ 1., 1.],
|
|
84
|
+
[ 1., 0.],
|
|
85
|
+
[ 0., 0.]])
|
|
86
|
+
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Test implementation of geo interface
|
|
2
|
+
====================================
|
|
3
|
+
|
|
4
|
+
>>> from shapely.geometry import asShape
|
|
5
|
+
|
|
6
|
+
Adapt a dictionary
|
|
7
|
+
|
|
8
|
+
>>> d = {"type": "Point", "coordinates": (0.0, 0.0)}
|
|
9
|
+
>>> shape = asShape(d)
|
|
10
|
+
>>> shape.geom_type
|
|
11
|
+
'Point'
|
|
12
|
+
>>> tuple(shape.coords)
|
|
13
|
+
((0.0, 0.0),)
|
|
14
|
+
|
|
15
|
+
Adapt an object that implements the geo protocol
|
|
16
|
+
|
|
17
|
+
>>> class GeoThing(object):
|
|
18
|
+
... def __init__(self, d):
|
|
19
|
+
... self.__geo_interface__ = d
|
|
20
|
+
|
|
21
|
+
>>> shape = None
|
|
22
|
+
>>> thing = GeoThing({"type": "Point", "coordinates": (0.0, 0.0)})
|
|
23
|
+
>>> shape = asShape(thing)
|
|
24
|
+
>>> shape.geom_type
|
|
25
|
+
'Point'
|
|
26
|
+
>>> tuple(shape.coords)
|
|
27
|
+
((0.0, 0.0),)
|
|
28
|
+
|
|
29
|
+
Check line string
|
|
30
|
+
|
|
31
|
+
>>> shape = asShape({'type': 'LineString', 'coordinates': ((-1.0, -1.0), (1.0, 1.0))})
|
|
32
|
+
>>> shape # doctest: +ELLIPSIS
|
|
33
|
+
<shapely.geometry.linestring.LineStringAdapter object at ...>
|
|
34
|
+
>>> tuple(shape.coords)
|
|
35
|
+
((-1.0, -1.0), (1.0, 1.0))
|
|
36
|
+
|
|
37
|
+
polygon
|
|
38
|
+
|
|
39
|
+
>>> shape = asShape({'type': 'Polygon', 'coordinates': (((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (2.0, -1.0), (0.0, 0.0)), ((0.10000000000000001, 0.10000000000000001), (0.10000000000000001, 0.20000000000000001), (0.20000000000000001, 0.20000000000000001), (0.20000000000000001, 0.10000000000000001), (0.10000000000000001, 0.10000000000000001)))})
|
|
40
|
+
>>> shape # doctest: +ELLIPSIS
|
|
41
|
+
<shapely.geometry.polygon.PolygonAdapter object at ...>
|
|
42
|
+
>>> tuple(shape.exterior.coords)
|
|
43
|
+
((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (2.0, -1.0), (0.0, 0.0))
|
|
44
|
+
>>> len(shape.interiors)
|
|
45
|
+
1
|
|
46
|
+
|
|
47
|
+
multi point
|
|
48
|
+
>>> shape = asShape({'type': 'MultiPoint', 'coordinates': ((1.0, 2.0), (3.0, 4.0))})
|
|
49
|
+
>>> shape # doctest: +ELLIPSIS
|
|
50
|
+
<shapely.geometry.multipoint.MultiPointAdapter object at ...>
|
|
51
|
+
>>> len(shape.geoms)
|
|
52
|
+
2
|
|
53
|
+
|
|
54
|
+
multi line string
|
|
55
|
+
|
|
56
|
+
>>> shape = asShape({'type': 'MultiLineString', 'coordinates': (((0.0, 0.0), (1.0, 2.0)),)})
|
|
57
|
+
>>> shape # doctest: +ELLIPSIS
|
|
58
|
+
<shapely.geometry.multilinestring.MultiLineStringAdapter object at ...>
|
|
59
|
+
>>> len(shape.geoms)
|
|
60
|
+
1
|
|
61
|
+
|
|
62
|
+
multi polygon
|
|
63
|
+
|
|
64
|
+
>>> shape = asShape({'type': 'MultiPolygon', 'coordinates': [(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0)), ((0.10000000000000001, 0.10000000000000001), (0.10000000000000001, 0.20000000000000001), (0.20000000000000001, 0.20000000000000001), (0.20000000000000001, 0.10000000000000001), (0.10000000000000001, 0.10000000000000001)))]})
|
|
65
|
+
>>> shape # doctest: +ELLIPSIS
|
|
66
|
+
<shapely.geometry.multipolygon.MultiPolygonAdapter object at ...>
|
|
67
|
+
>>> len(shape.geoms)
|
|
68
|
+
1
|
|
69
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
Test operator iterations
|
|
2
|
+
========================
|
|
3
|
+
|
|
4
|
+
>>> from shapely.geometry import Polygon
|
|
5
|
+
>>> from shapely.geometry import Point
|
|
6
|
+
>>> coords = ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0), (0.0, 0.0))
|
|
7
|
+
>>> polygon = Polygon(coords)
|
|
8
|
+
>>> points = [Point(0.5, 0.5), Point(2.0, 2.0)]
|
|
9
|
+
|
|
10
|
+
>>> from shapely import iterops
|
|
11
|
+
|
|
12
|
+
List of the points contained by the polygon
|
|
13
|
+
>>> list(iterops.contains(polygon, points, True)) # doctest: +ELLIPSIS
|
|
14
|
+
[<shapely.geometry.point.Point object at ...>]
|
|
15
|
+
|
|
16
|
+
'True' is the default value
|
|
17
|
+
>>> list(iterops.contains(polygon, points)) # doctest: +ELLIPSIS
|
|
18
|
+
[<shapely.geometry.point.Point object at ...>]
|
|
19
|
+
|
|
20
|
+
Test a false value
|
|
21
|
+
>>> list(iterops.contains(polygon, points, False)) # doctest: +ELLIPSIS
|
|
22
|
+
[<shapely.geometry.point.Point object at ...>]
|
|
23
|
+
|
|
24
|
+
If the provided iterator yields tuples, the second value will be yielded
|
|
25
|
+
>>> list(iterops.contains(polygon, [(p, p.wkt) for p in points], False))
|
|
26
|
+
['POINT (2.0000000000000000 2.0000000000000000)']
|
|
27
|
+
|
|
28
|
+
Just to demonstrate that the important thing is that the second parameter
|
|
29
|
+
is an iterator:
|
|
30
|
+
>>> list(iterops.contains(polygon, iter((p, p.wkt) for p in points)))
|
|
31
|
+
['POINT (0.5000000000000000 0.5000000000000000)']
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
LineStrings
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
Initialization
|
|
5
|
+
--------------
|
|
6
|
+
|
|
7
|
+
>>> from shapely.geometry import LineString
|
|
8
|
+
|
|
9
|
+
Construct from a numpy array
|
|
10
|
+
|
|
11
|
+
>>> from numpy import array
|
|
12
|
+
>>> line = LineString(array([[0.0, 0.0], [1.0, 2.0]]))
|
|
13
|
+
>>> len(line.coords)
|
|
14
|
+
2
|
|
15
|
+
>>> line.wkt
|
|
16
|
+
'LINESTRING (0.0000000000000000 0.0000000000000000, 1.0000000000000000 2.0000000000000000)'
|
|
17
|
+
|
|
18
|
+
From coordinate tuples
|
|
19
|
+
|
|
20
|
+
>>> line = LineString(((1.0, 2.0), (3.0, 4.0)))
|
|
21
|
+
>>> len(line.coords)
|
|
22
|
+
2
|
|
23
|
+
>>> line.wkt
|
|
24
|
+
'LINESTRING (1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000)'
|
|
25
|
+
|
|
26
|
+
From lines
|
|
27
|
+
|
|
28
|
+
>>> copy = LineString(line)
|
|
29
|
+
>>> len(copy.coords)
|
|
30
|
+
2
|
|
31
|
+
>>> print copy.wkt
|
|
32
|
+
LINESTRING (1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
Numpy Support
|
|
36
|
+
-------------
|
|
37
|
+
|
|
38
|
+
>>> from numpy import asarray
|
|
39
|
+
>>> la = asarray(line)
|
|
40
|
+
>>> la
|
|
41
|
+
array([[ 1., 2.],
|
|
42
|
+
[ 3., 4.]])
|
|
43
|
+
>>> la[0]
|
|
44
|
+
array([ 1., 2.])
|
|
45
|
+
|
|
46
|
+
Coordinate sequences can be adapted as well
|
|
47
|
+
|
|
48
|
+
>>> asarray(line.coords)
|
|
49
|
+
array([[ 1., 2.],
|
|
50
|
+
[ 3., 4.]])
|
|
51
|
+
|
|
52
|
+
Bounds
|
|
53
|
+
------
|
|
54
|
+
|
|
55
|
+
>>> line.bounds
|
|
56
|
+
(1.0, 2.0, 3.0, 4.0)
|
|
57
|
+
|
|
58
|
+
Coordinate Access
|
|
59
|
+
-----------------
|
|
60
|
+
|
|
61
|
+
>>> tuple(line.coords)
|
|
62
|
+
((1.0, 2.0), (3.0, 4.0))
|
|
63
|
+
|
|
64
|
+
>>> line.coords[0]
|
|
65
|
+
(1.0, 2.0)
|
|
66
|
+
>>> line.coords[1]
|
|
67
|
+
(3.0, 4.0)
|
|
68
|
+
>>> line.coords[2]
|
|
69
|
+
Traceback (most recent call last):
|
|
70
|
+
...
|
|
71
|
+
IndexError: index out of range
|
|
72
|
+
|
|
73
|
+
Geo interface
|
|
74
|
+
-------------
|
|
75
|
+
|
|
76
|
+
>>> line.__geo_interface__
|
|
77
|
+
{'type': 'LineString', 'coordinates': ((1.0, 2.0), (3.0, 4.0))}
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
Coordinate modification
|
|
81
|
+
-----------------------
|
|
82
|
+
|
|
83
|
+
>>> line.coords = ((-1.0, -1.0), (1.0, 1.0))
|
|
84
|
+
>>> line.__geo_interface__
|
|
85
|
+
{'type': 'LineString', 'coordinates': ((-1.0, -1.0), (1.0, 1.0))}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
Adapter
|
|
89
|
+
-------
|
|
90
|
+
|
|
91
|
+
>>> from shapely.geometry import asLineString
|
|
92
|
+
|
|
93
|
+
Adapt a Numpy array to a line string
|
|
94
|
+
|
|
95
|
+
>>> a = array([[1.0, 2.0], [3.0, 4.0]])
|
|
96
|
+
>>> la = asLineString(a)
|
|
97
|
+
>>> la.context
|
|
98
|
+
array([[ 1., 2.],
|
|
99
|
+
[ 3., 4.]])
|
|
100
|
+
|
|
101
|
+
>>> la.wkt
|
|
102
|
+
'LINESTRING (1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000)'
|
|
103
|
+
|
|
104
|
+
Now, the inverse
|
|
105
|
+
|
|
106
|
+
>>> la.__array_interface__ == la.context.__array_interface__
|
|
107
|
+
True
|
|
108
|
+
>>> pas = asarray(la)
|
|
109
|
+
>>> pas
|
|
110
|
+
array([[ 1., 2.],
|
|
111
|
+
[ 3., 4.]])
|
|
112
|
+
|
|
113
|
+
Adapt a coordinate list to a line string
|
|
114
|
+
|
|
115
|
+
>>> coords = [[5.0, 6.0], [7.0, 8.0]]
|
|
116
|
+
>>> la = asLineString(coords)
|
|
117
|
+
>>> la.wkt
|
|
118
|
+
'LINESTRING (5.0000000000000000 6.0000000000000000, 7.0000000000000000 8.0000000000000000)'
|
|
119
|
+
|
|
120
|
+
Test Non-operability of Null geometry
|
|
121
|
+
|
|
122
|
+
>>> l_null = LineString()
|
|
123
|
+
>>> l_null.wkt # doctest: +ELLIPSIS
|
|
124
|
+
'GEOMETRYCOLLECTION EMPTY'
|
|
125
|
+
|
|
126
|
+
>>> l_null.length # doctest: +ELLIPSIS
|
|
127
|
+
0.0
|
|
128
|
+
|
|
129
|
+
Check that we can set coordinates of a null geometry
|
|
130
|
+
|
|
131
|
+
>>> l_null.coords = [(0, 0), (1, 1)]
|
|
132
|
+
>>> print l_null.length # doctest: +ELLIPSIS
|
|
133
|
+
1.414...
|
|
134
|
+
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
MultiLineStrings
|
|
2
|
+
================
|
|
3
|
+
|
|
4
|
+
Initialization
|
|
5
|
+
--------------
|
|
6
|
+
|
|
7
|
+
>>> from shapely.geometry import LineString, MultiLineString
|
|
8
|
+
|
|
9
|
+
From coordinate tuples
|
|
10
|
+
|
|
11
|
+
>>> geom = MultiLineString( (((1.0, 2.0), (3.0, 4.0)),) )
|
|
12
|
+
>>> geom # doctest: +ELLIPSIS
|
|
13
|
+
<shapely.geometry.multilinestring.MultiLineString object at ...>
|
|
14
|
+
>>> len(geom.geoms)
|
|
15
|
+
1
|
|
16
|
+
>>> geom.wkt
|
|
17
|
+
'MULTILINESTRING ((1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000))'
|
|
18
|
+
|
|
19
|
+
Construct from a numpy array
|
|
20
|
+
|
|
21
|
+
>>> from numpy import array
|
|
22
|
+
>>> geom = MultiLineString( [array(((0.0, 0.0), (1.0, 2.0)))] )
|
|
23
|
+
>>> geom # doctest: +ELLIPSIS
|
|
24
|
+
<shapely.geometry.multilinestring.MultiLineString object at ...>
|
|
25
|
+
>>> len(geom.geoms)
|
|
26
|
+
1
|
|
27
|
+
>>> geom.wkt
|
|
28
|
+
'MULTILINESTRING ((0.0000000000000000 0.0000000000000000, 1.0000000000000000 2.0000000000000000))'
|
|
29
|
+
|
|
30
|
+
From lines
|
|
31
|
+
|
|
32
|
+
>>> a = LineString(((1.0, 2.0), (3.0, 4.0)))
|
|
33
|
+
>>> ml = MultiLineString([a])
|
|
34
|
+
>>> len(ml.geoms)
|
|
35
|
+
1
|
|
36
|
+
>>> print ml.wkt
|
|
37
|
+
MULTILINESTRING ((1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000))
|
|
38
|
+
|
|
39
|
+
From another multi-line
|
|
40
|
+
|
|
41
|
+
>>> ml2 = MultiLineString(ml)
|
|
42
|
+
>>> len(ml2.geoms)
|
|
43
|
+
1
|
|
44
|
+
>>> print ml2.wkt
|
|
45
|
+
MULTILINESTRING ((1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
Sub-geometry Access
|
|
49
|
+
-------------------
|
|
50
|
+
|
|
51
|
+
>>> geom.geoms[0] # doctest: +ELLIPSIS
|
|
52
|
+
<shapely.geometry.linestring.LineString object at ...>
|
|
53
|
+
>>> geom.geoms[0].wkt
|
|
54
|
+
'LINESTRING (0.0000000000000000 0.0000000000000000, 1.0000000000000000 2.0000000000000000)'
|
|
55
|
+
>>> geom.geoms[1]
|
|
56
|
+
Traceback (most recent call last):
|
|
57
|
+
...
|
|
58
|
+
IndexError: index out of range
|
|
59
|
+
|
|
60
|
+
Geo interface
|
|
61
|
+
-------------
|
|
62
|
+
|
|
63
|
+
>>> geom.__geo_interface__
|
|
64
|
+
{'type': 'MultiLineString', 'coordinates': (((0.0, 0.0), (1.0, 2.0)),)}
|
|
65
|
+
|
|
66
|
+
Adapter
|
|
67
|
+
-------
|
|
68
|
+
|
|
69
|
+
>>> from shapely.geometry import asMultiLineString
|
|
70
|
+
|
|
71
|
+
Adapt a sequence of Numpy arrays to a multilinestring
|
|
72
|
+
|
|
73
|
+
>>> a = [ array(((1.0, 2.0), (3.0, 4.0))) ]
|
|
74
|
+
>>> geoma = asMultiLineString(a)
|
|
75
|
+
>>> geoma.context
|
|
76
|
+
[array([[ 1., 2.],
|
|
77
|
+
[ 3., 4.]])]
|
|
78
|
+
|
|
79
|
+
>>> geoma.wkt
|
|
80
|
+
'MULTILINESTRING ((1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000))'
|
|
81
|
+
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
MultiPoints
|
|
2
|
+
===========
|
|
3
|
+
|
|
4
|
+
Initialization
|
|
5
|
+
--------------
|
|
6
|
+
|
|
7
|
+
>>> from shapely.geometry import Point, MultiPoint
|
|
8
|
+
|
|
9
|
+
Construct from a numpy array
|
|
10
|
+
|
|
11
|
+
>>> from numpy import array
|
|
12
|
+
>>> geom = MultiPoint(array([[0.0, 0.0], [1.0, 2.0]]))
|
|
13
|
+
>>> geom # doctest: +ELLIPSIS
|
|
14
|
+
<shapely.geometry.multipoint.MultiPoint object at ...>
|
|
15
|
+
>>> len(geom.geoms)
|
|
16
|
+
2
|
|
17
|
+
>>> geom.wkt
|
|
18
|
+
'MULTIPOINT (0.0000000000000000 0.0000000000000000, 1.0000000000000000 2.0000000000000000)'
|
|
19
|
+
|
|
20
|
+
From coordinate tuples
|
|
21
|
+
|
|
22
|
+
>>> geom = MultiPoint(((1.0, 2.0), (3.0, 4.0)))
|
|
23
|
+
>>> len(geom.geoms)
|
|
24
|
+
2
|
|
25
|
+
>>> geom.wkt
|
|
26
|
+
'MULTIPOINT (1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000)'
|
|
27
|
+
|
|
28
|
+
From points
|
|
29
|
+
|
|
30
|
+
>>> geom = MultiPoint((Point(1.0, 2.0), Point(3.0, 4.0)))
|
|
31
|
+
>>> len(geom.geoms)
|
|
32
|
+
2
|
|
33
|
+
>>> print geom.wkt
|
|
34
|
+
MULTIPOINT (1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000)
|
|
35
|
+
|
|
36
|
+
From another multi-point
|
|
37
|
+
|
|
38
|
+
>>> geom2 = MultiPoint(geom)
|
|
39
|
+
>>> len(geom2.geoms)
|
|
40
|
+
2
|
|
41
|
+
>>> print geom2.wkt
|
|
42
|
+
MULTIPOINT (1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
Sub-geometry Access
|
|
46
|
+
-------------------
|
|
47
|
+
|
|
48
|
+
>>> geom.geoms[0] # doctest: +ELLIPSIS
|
|
49
|
+
<shapely.geometry.point.Point object at ...>
|
|
50
|
+
>>> geom.geoms[0].x
|
|
51
|
+
1.0
|
|
52
|
+
>>> geom.geoms[0].y
|
|
53
|
+
2.0
|
|
54
|
+
>>> geom.geoms[2]
|
|
55
|
+
Traceback (most recent call last):
|
|
56
|
+
...
|
|
57
|
+
IndexError: index out of range
|
|
58
|
+
|
|
59
|
+
Geo interface
|
|
60
|
+
-------------
|
|
61
|
+
|
|
62
|
+
>>> geom.__geo_interface__
|
|
63
|
+
{'type': 'MultiPoint', 'coordinates': ((1.0, 2.0), (3.0, 4.0))}
|
|
64
|
+
|
|
65
|
+
>>> array(geom)
|
|
66
|
+
array([[ 1., 2.],
|
|
67
|
+
[ 3., 4.]])
|
|
68
|
+
|
|
69
|
+
Adapter
|
|
70
|
+
-------
|
|
71
|
+
|
|
72
|
+
>>> from shapely.geometry import asMultiPoint
|
|
73
|
+
|
|
74
|
+
Adapt a Numpy array to a multipoint
|
|
75
|
+
|
|
76
|
+
>>> a = array([[1.0, 2.0], [3.0, 4.0]])
|
|
77
|
+
>>> geoma = asMultiPoint(a)
|
|
78
|
+
>>> geoma.context
|
|
79
|
+
array([[ 1., 2.],
|
|
80
|
+
[ 3., 4.]])
|
|
81
|
+
|
|
82
|
+
>>> geoma.wkt
|
|
83
|
+
'MULTIPOINT (1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000)'
|
|
84
|
+
|
|
85
|
+
Now, the inverse
|
|
86
|
+
|
|
87
|
+
>>> geoma.__array_interface__ == geoma.context.__array_interface__
|
|
88
|
+
True
|
|
89
|
+
>>> from numpy import asarray
|
|
90
|
+
>>> pas = asarray(geoma)
|
|
91
|
+
>>> pas
|
|
92
|
+
array([[ 1., 2.],
|
|
93
|
+
[ 3., 4.]])
|
|
94
|
+
|
|
95
|
+
Adapt a coordinate list to a line string
|
|
96
|
+
|
|
97
|
+
>>> coords = [[5.0, 6.0], [7.0, 8.0]]
|
|
98
|
+
>>> geoma = asMultiPoint(coords)
|
|
99
|
+
>>> geoma.wkt
|
|
100
|
+
'MULTIPOINT (5.0000000000000000 6.0000000000000000, 7.0000000000000000 8.0000000000000000)'
|
|
101
|
+
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
MultiPolygons
|
|
2
|
+
=============
|
|
3
|
+
|
|
4
|
+
Initialization
|
|
5
|
+
--------------
|
|
6
|
+
|
|
7
|
+
>>> from shapely.geometry import Polygon, MultiPolygon
|
|
8
|
+
|
|
9
|
+
From coordinate tuples
|
|
10
|
+
|
|
11
|
+
>>> geom = MultiPolygon( [
|
|
12
|
+
... (((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)), [((0.25,0.25), (0.25,0.5), (0.5,0.5), (0.5,0.25))])
|
|
13
|
+
... ] )
|
|
14
|
+
>>> geom # doctest: +ELLIPSIS
|
|
15
|
+
<shapely.geometry.multipolygon.MultiPolygon object at ...>
|
|
16
|
+
>>> len(geom.geoms)
|
|
17
|
+
1
|
|
18
|
+
>>> geom.wkt
|
|
19
|
+
'MULTIPOLYGON (((0.0000000000000000 0.0000000000000000, 0.0000000000000000 1.0000000000000000, 1.0000000000000000 1.0000000000000000, 1.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000), (0.2500000000000000 0.2500000000000000, 0.2500000000000000 0.5000000000000000, 0.5000000000000000 0.5000000000000000, 0.5000000000000000 0.2500000000000000, 0.2500000000000000 0.2500000000000000)))'
|
|
20
|
+
|
|
21
|
+
Or from polygons
|
|
22
|
+
|
|
23
|
+
>>> p = Polygon(((0, 0), (0, 1), (1, 1), (1, 0)), [((0.25,0.25), (0.25,0.5), (0.5,0.5), (0.5,0.25))])
|
|
24
|
+
>>> geom = MultiPolygon([p])
|
|
25
|
+
>>> len(geom.geoms)
|
|
26
|
+
1
|
|
27
|
+
>>> print geom.wkt
|
|
28
|
+
MULTIPOLYGON (((0.0000000000000000 0.0000000000000000, 0.0000000000000000 1.0000000000000000, 1.0000000000000000 1.0000000000000000, 1.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000), (0.2500000000000000 0.2500000000000000, 0.2500000000000000 0.5000000000000000, 0.5000000000000000 0.5000000000000000, 0.5000000000000000 0.2500000000000000, 0.2500000000000000 0.2500000000000000)))
|
|
29
|
+
|
|
30
|
+
Or from another multi-polygon
|
|
31
|
+
|
|
32
|
+
>>> geom2 = MultiPolygon(geom)
|
|
33
|
+
>>> len(geom2.geoms)
|
|
34
|
+
1
|
|
35
|
+
>>> print geom2.wkt
|
|
36
|
+
MULTIPOLYGON (((0.0000000000000000 0.0000000000000000, 0.0000000000000000 1.0000000000000000, 1.0000000000000000 1.0000000000000000, 1.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000), (0.2500000000000000 0.2500000000000000, 0.2500000000000000 0.5000000000000000, 0.5000000000000000 0.5000000000000000, 0.5000000000000000 0.2500000000000000, 0.2500000000000000 0.2500000000000000)))
|
|
37
|
+
|
|
38
|
+
Sub-geometry Access
|
|
39
|
+
-------------------
|
|
40
|
+
|
|
41
|
+
>>> geom.geoms[0] # doctest: +ELLIPSIS
|
|
42
|
+
<shapely.geometry.polygon.Polygon object at ...>
|
|
43
|
+
>>> geom.geoms[0].wkt
|
|
44
|
+
'POLYGON ((0.0000000000000000 0.0000000000000000, 0.0000000000000000 1.0000000000000000, 1.0000000000000000 1.0000000000000000, 1.0000000000000000 0.0000000000000000, 0.0000000000000000 0.0000000000000000), (0.2500000000000000 0.2500000000000000, 0.2500000000000000 0.5000000000000000, 0.5000000000000000 0.5000000000000000, 0.5000000000000000 0.2500000000000000, 0.2500000000000000 0.2500000000000000))'
|
|
45
|
+
>>> geom.geoms[1]
|
|
46
|
+
Traceback (most recent call last):
|
|
47
|
+
...
|
|
48
|
+
IndexError: index out of range
|
|
49
|
+
|
|
50
|
+
Geo interface
|
|
51
|
+
-------------
|
|
52
|
+
|
|
53
|
+
>>> geom.__geo_interface__
|
|
54
|
+
{'type': 'MultiPolygon', 'coordinates': [(((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.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)))]}
|
|
55
|
+
|
|
56
|
+
Adapter
|
|
57
|
+
-------
|
|
58
|
+
|
|
59
|
+
>>> from shapely.geometry import asMultiPolygon
|
|
60
|
+
>>> coords = ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0))
|
|
61
|
+
>>> holes_coords = [((0.25,0.25), (0.25,0.5), (0.5,0.5), (0.5,0.25))]
|
|
62
|
+
>>> mpa = asMultiPolygon([(coords, holes_coords)])
|
|
63
|
+
>>> len(mpa.geoms)
|
|
64
|
+
1
|
|
65
|
+
>>> len(mpa.geoms[0].exterior.coords)
|
|
66
|
+
5
|
|
67
|
+
>>> len(mpa.geoms[0].interiors)
|
|
68
|
+
1
|
|
69
|
+
>>> len(mpa.geoms[0].interiors[0].coords)
|
|
70
|
+
5
|
|
71
|
+
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
Test GEOS operations
|
|
2
|
+
====================
|
|
3
|
+
|
|
4
|
+
>>> from shapely.geometry import Point
|
|
5
|
+
>>> point = Point(0.0, 0.0)
|
|
6
|
+
|
|
7
|
+
General geometry
|
|
8
|
+
----------------
|
|
9
|
+
|
|
10
|
+
>>> point.area
|
|
11
|
+
0.0
|
|
12
|
+
|
|
13
|
+
>>> point.length
|
|
14
|
+
0.0
|
|
15
|
+
|
|
16
|
+
>>> point.distance(Point(-1.0, -1.0))
|
|
17
|
+
1.4142135623730951
|
|
18
|
+
|
|
19
|
+
Topology operations
|
|
20
|
+
-------------------
|
|
21
|
+
|
|
22
|
+
Envelope
|
|
23
|
+
|
|
24
|
+
>>> point.envelope #doctest: +ELLIPSIS
|
|
25
|
+
<shapely.geometry.point.Point object at ...>
|
|
26
|
+
|
|
27
|
+
Intersection
|
|
28
|
+
|
|
29
|
+
>>> point.intersection(Point(-1,-1)) #doctest: +ELLIPSIS
|
|
30
|
+
<shapely.geometry.collection.GeometryCollection object at ...>
|
|
31
|
+
|
|
32
|
+
Buffer
|
|
33
|
+
|
|
34
|
+
>>> point.buffer(10.0) #doctest: +ELLIPSIS
|
|
35
|
+
<shapely.geometry.polygon.Polygon object at ...>
|
|
36
|
+
|
|
37
|
+
>>> point.buffer(10.0, 32) #doctest: +ELLIPSIS
|
|
38
|
+
<shapely.geometry.polygon.Polygon object at ...>
|
|
39
|
+
|
|
40
|
+
Simplify
|
|
41
|
+
|
|
42
|
+
>>> from shapely.wkt import loads
|
|
43
|
+
>>> p = loads('POLYGON ((120 120, 121 121, 122 122, 220 120, 180 199, 160 200, 140 199, 120 120))')
|
|
44
|
+
>>> expected = loads('POLYGON ((120 120, 140 199, 160 200, 180 199, 220 120, 120 120))')
|
|
45
|
+
>>> s = p.simplify(10.0, preserve_topology = False)
|
|
46
|
+
>>> s.equals_exact(expected, 0.001)
|
|
47
|
+
True
|
|
48
|
+
|
|
49
|
+
>>> from shapely.wkt import loads
|
|
50
|
+
>>> p = loads('POLYGON ((80 200, 240 200, 240 60, 80 60, 80 200),(120 120, 220 120, 180 199, 160 200, 140 199, 120 120))')
|
|
51
|
+
>>> expected = loads('POLYGON ((80 200, 240 200, 240 60, 80 60, 80 200),(120 120, 220 120, 180 199, 160 200, 140 199, 120 120))')
|
|
52
|
+
>>> s = p.simplify(10.0, preserve_topology = True)
|
|
53
|
+
>>> s.equals_exact(expected, 0.001)
|
|
54
|
+
True
|
|
55
|
+
|
|
56
|
+
Convex Hull
|
|
57
|
+
|
|
58
|
+
>>> point.convex_hull #doctest: +ELLIPSIS
|
|
59
|
+
<shapely.geometry.point.Point object at ...>
|
|
60
|
+
|
|
61
|
+
Differences
|
|
62
|
+
|
|
63
|
+
>>> point.difference(Point(-1, 1)) #doctest: +ELLIPSIS
|
|
64
|
+
<shapely.geometry.point.Point object at ...>
|
|
65
|
+
|
|
66
|
+
>>> point.symmetric_difference(Point(-1, 1)) #doctest: +ELLIPSIS
|
|
67
|
+
<shapely.geometry.multipoint.MultiPoint object at ...>
|
|
68
|
+
|
|
69
|
+
Boundary
|
|
70
|
+
|
|
71
|
+
>>> point.boundary #doctest: +ELLIPSIS
|
|
72
|
+
<shapely.geometry.collection.GeometryCollection object at ...>
|
|
73
|
+
|
|
74
|
+
Union
|
|
75
|
+
|
|
76
|
+
>>> point.union(Point(-1, 1)) #doctest: +ELLIPSIS
|
|
77
|
+
<shapely.geometry.multipoint.MultiPoint object at ...>
|
|
78
|
+
|
|
79
|
+
>>> point.representative_point() #doctest: +ELLIPSIS
|
|
80
|
+
<shapely.geometry.point.Point object at ...>
|
|
81
|
+
|
|
82
|
+
>>> point.centroid #doctest: +ELLIPSIS
|
|
83
|
+
<shapely.geometry.point.Point object at ...>
|
|
84
|
+
|
|
85
|
+
Relate
|
|
86
|
+
|
|
87
|
+
>>> point.relate(Point(-1, -1)) #doctest: +ELLIPSIS
|
|
88
|
+
'FF0FFF0F2'
|
|
89
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
Test operators
|
|
2
|
+
==============
|
|
3
|
+
|
|
4
|
+
>>> from shapely.geometry import Point
|
|
5
|
+
>>> point = Point(0, 0)
|
|
6
|
+
>>> point2 = Point(-1, 1)
|
|
7
|
+
|
|
8
|
+
>>> point.union(point2).equals(point | point2)
|
|
9
|
+
True
|
|
10
|
+
|
|
11
|
+
>>> (point & point2).is_empty
|
|
12
|
+
True
|
|
13
|
+
|
|
14
|
+
>>> point.equals(point - point2)
|
|
15
|
+
True
|
|
16
|
+
|
|
17
|
+
>>> point.symmetric_difference(point2).equals(point ^ point2)
|
|
18
|
+
True
|