4
4
5
5
Manipulation and analysis of geometric objects in the Cartesian plane.
6
6
7
+ .. image :: https://travis-ci.org/Toblerity/Shapely.png?branch=master
8
+ :target: https://travis-ci.org/Toblerity/Shapely
9
+
7
10
.. image :: http://farm3.staticflickr.com/2738/4511827859_b5822043b7_o_d.png
8
11
:width: 800
9
12
:height: 400
@@ -20,7 +23,7 @@ integrated with packages that are. For more details, see:
20
23
Requirements
21
24
============
22
25
23
- Shapely 1.3 requires
26
+ Shapely 1.4 requires
24
27
25
28
* Python >=2.6 (including Python 3.x)
26
29
* libgeos_c >=3.1 (3.0 and below have not been tested, YMMV)
@@ -30,13 +33,14 @@ Installation
30
33
31
34
Windows users should use the executable installer, which contains the required
32
35
GEOS DLL. Other users should acquire libgeos_c by any means, make sure that it
33
- is on the system library path, and install from the Python package index::
36
+ is on the system library path, and install from the Python package index.
34
37
35
- $ pip install Shapely
38
+ .. code-block :: console
36
39
37
- or from a source distribution with the setup script::
40
+ $ pip install shapely
38
41
39
- $ python setup.py install
42
+ Shapely is also provided by popular Python distributions like Enthought Canopy
43
+ and Continuum Analytics Anaconda.
40
44
41
45
.. warning :: Windows users:
42
46
do not under any circumstances use pip (or easy_install) to uninstall
48
52
=====
49
53
50
54
Here is the canonical example of building an approximately circular patch by
51
- buffering a point::
55
+ buffering a point.
56
+
57
+ .. code-block :: pycon
52
58
53
59
>>> from shapely.geometry import Point
54
60
>>> patch = Point(0.0, 0.0).buffer(10.0)
@@ -65,40 +71,51 @@ Integration
65
71
66
72
Shapely does not read or write data files, but it can serialize and deserialize
67
73
using several well known formats and protocols. The shapely.wkb and shapely.wkt
68
- modules provide dumpers and loaders inspired by Python's pickle module.::
74
+ modules provide dumpers and loaders inspired by Python's pickle module.
75
+
76
+ .. code-block :: pycon
69
77
70
78
>>> from shapely.wkt import dumps, loads
71
79
>>> dumps(loads('POINT (0 0)'))
72
80
'POINT (0.0000000000000000 0.0000000000000000)'
73
81
74
82
All linear objects, such as the rings of a polygon (like ``patch `` above),
75
- provide the Numpy array interface.::
83
+ provide the Numpy array interface.
84
+
85
+ .. code-block :: pycon
76
86
77
- >>> from numpy import asarray
78
- >>> ag = asarray(patch.exterior)
79
- >>> ag
87
+ >>> import numpy as np
88
+ >>> np.array(patch.exterior)
80
89
array([[ 1.00000000e+01, 0.00000000e+00],
81
90
[ 9.95184727e+00, -9.80171403e-01],
82
91
[ 9.80785280e+00, -1.95090322e+00],
83
92
...
84
93
[ 1.00000000e+01, 0.00000000e+00]])
85
94
86
- That yields a Numpy array of [x, y] arrays. This is not always exactly what one
87
- wants for plotting shapes with Matplotlib (for example), so Shapely 1.2 adds
88
- a `xy ` property for obtaining separate arrays of coordinate x and y values.::
95
+ That yields a Numpy array of `[x, y] ` arrays. This is not always exactly what one
96
+ wants for plotting shapes with Matplotlib (for example), so Shapely adds
97
+ a `xy ` property for obtaining separate arrays of coordinate x and y values.
98
+
99
+ .. code-block :: pycon
89
100
90
101
>>> x, y = patch.exterior.xy
91
- >>> ax = asarray(x)
92
- >>> ax
102
+ >>> np.array(x)
93
103
array([ 1.00000000e+01, 9.95184727e+00, 9.80785280e+00, ...])
94
104
95
- Numpy arrays can also be adapted to Shapely linestrings::
105
+ Numpy arrays of `[x, y] ` arrays can also be adapted to Shapely linestrings.
106
+
107
+ .. code-block :: pycon
96
108
97
- >>> from shapely.geometry import asLineString
98
- >>> asLineString(ag ).length
109
+ >>> from shapely.geometry import LineString
110
+ >>> LineString(np.array(patch.exterior) ).length
99
111
62.806623139095073
100
- >>> asLineString(ag).wkt
101
- 'LINESTRING (10.0000000000000000 0.0000000000000000, ...)'
112
+
113
+ Numpy arrays of x and y must be transposed.
114
+
115
+ .. code-block ::
116
+
117
+ >>> LineString(np.transpose(np.array(patch.exterior.xy))).length
118
+ 62.80662313909507
102
119
103
120
Shapely can also integrate with other Python GIS packages using data modeled
104
121
after GeoJSON.
@@ -116,22 +133,36 @@ after GeoJSON.
116
133
Development and Testing
117
134
=======================
118
135
119
- Dependecies for developing Shapely are listed in requirements-dev.txt. Cython
136
+ Dependencies for developing Shapely are listed in requirements-dev.txt. Cython
120
137
and Numpy are not required for production installations, only for development.
121
- Use of a virtual environment is strongly recommended.::
138
+ Use of a virtual environment is strongly recommended.
139
+
140
+ .. code-block :: console
122
141
123
142
$ virtualenv .
124
143
$ source bin/activate
125
144
(env)$ pip install -r requirements-dev.txt
126
- (env)$ python setup.py develop
145
+ (env)$ pip install -e .
146
+
147
+ We use py.test to run Shapely's suite of unittests and doctests.
148
+
149
+ .. code-block :: console
150
+
151
+ (env)$ py.test tests
152
+
153
+ Roadmap and Maintenance
154
+ =======================
127
155
128
- Shapely uses a Zope-stye suite of unittests and doctests, exercised via
129
- setup.py.::
156
+ Shapely 1.2.x is a maintenance-only branch which supports Python 2.4-2.6, but
157
+ not Python 3+. There will be no new features in Shapely 1.2.x and only fixes
158
+ for major bugs.
130
159
131
- (env)$ python setup.py test
160
+ Shapely 1.3.x is a maintenance-only branch supporting Pythons 2.7 and 3+.
132
161
133
- Nosetests won't run the tests properly; Zope doctest suites are not currently
134
- supported well by nose.
162
+ "Shapely 3000" is the name of the next milestone. New features will include
163
+ vectorized operations, better integration with IPython Notebook, support for
164
+ fixed precision models, and more. Less ctypes and more Cython is another theme
165
+ in this branch. A 1.4 release should come out of this by Summer, 2014.
135
166
136
167
Support
137
168
=======
@@ -141,12 +172,12 @@ http://lists.gispython.org/mailman/listinfo/community.
141
172
142
173
Bugs may be reported at https://github.com/Toblerity/Shapely.
143
174
144
- .. include :: ../ CREDITS.txt
175
+ .. include :: CREDITS.txt
145
176
146
177
.. _JTS : http://www.vividsolutions.com/jts/jtshome.htm
147
178
.. _PostGIS : http://postgis.org
148
179
.. _GEOS : http://trac.osgeo.org/geos/
149
- .. _example apps : https://github.com/sgillies /shapely/tree/master/shapely/examples
180
+ .. _example apps : https://github.com/Toblerity /shapely/tree/master/shapely/examples
150
181
.. _manual : http://toblerity.github.com/shapely/manual.html
151
182
.. _Pleiades : http://pleiades.stoa.org
152
183
0 commit comments