root/Shapely/trunk/README.txt

Revision 1126 (checked in by seang, 4 months ago)

Use weak reference to avoid a reference cycle with exterior ring of polygon

  • Property svn:eol-style set to native
Line 
1 Shapely
2 =======
3
4 Shapely is a Python package for manipulation and analysis of 2D geospatial
5 geometries. It is based on GEOS (http://geos.refractions.net).  Shapely 1.0 is
6 not concerned with data formats or coordinate reference systems.
7 Responsibility for reading and writing data and projecting coordinates is left
8 to other packages like WorldMill_ and pyproj_. For more information, see:
9
10 * Shapely wiki_
11 * Shapely manual_
12
13 Shapely requires Python 2.4+. (I've also begun to port it to Python 3.0:
14 http://zcologia.com/news/564/shapely-for-python-3-0/.)
15
16 .. note::
17    We've switched to Windows GEOS DLLs based on MinGW in versions >= 1.0.6.
18    Please contact us if you experience difficulties.
19
20 See also CHANGES.txt_ and HISTORY.txt_.
21
22 .. _CHANGES.txt: http://trac.gispython.org/projects/PCL/browser/Shapely/trunk/CHANGES.txt
23 .. _HISTORY.txt: http://trac.gispython.org/projects/PCL/browser/Shapely/trunk/HISTORY.txt
24 .. _WorldMill: http://pypi.python.org/pypi/WorldMill
25 .. _pyproj: http://pypi.python.org/pypi/pyproj
26
27
28 Dependencies
29 ------------
30
31 * libgeos_c (2.2.3 or 3.0.0+)
32 * Python ctypes_ (standard in Python 2.5+)
33
34 .. _ctypes: http://pypi.python.org/pypi/ctypes/
35
36
37 Installation
38 ------------
39
40 Windows users should use the executable installer, which contains the required
41 GEOS DLL. Other users should acquire libgeos_c by any means, make sure that it
42 is on the system library path, and install from the Python package index::
43
44   $ sudo easy_install Shapely
45
46 with the setup script::
47
48   $ sudo python setup.py install
49
50 or by using the development buildout on Linux, which also provides libgeos_c::
51
52   $ svn co http://svn.gispython.org/svn/gispy/buildout/shapely.buildout/trunk shapely.buildout
53   $ cd shapely.buildout
54   $ python bootstrap.py
55   $ ./bin/buildout
56
57
58 Usage
59 -----
60
61 To buffer a point::
62
63   >>> from shapely.geometry import Point
64   >>> point = Point(-106.0, 40.0) # longitude, latitude
65   >>> point.buffer(10.0)
66   <shapely.geometry.polygon.Polygon object at ...>
67
68 See the manual_ for comprehensive examples of usage. See also Operations.txt
69 and Predicates.txt under tests/ for more examples of the spatial operations and
70 predicates provided by Shapely. See also Point.txt, LineString.txt, etc for
71 examples of the geometry APIs.
72
73
74 Numpy integration
75 -----------------
76
77 All Shapely geometry instances provide the Numpy array interface::
78
79   >>> from numpy import asarray
80   >>> a = asarray(point)
81   >>> a.size
82   3
83   >>> a.shape
84   (2,)
85
86 Numpy arrays can also be adapted to Shapely points and linestrings::
87
88   >>> from shapely.geometry import asLineString
89   >>> a = array([[1.0, 2.0], [3.0, 4.0]])
90   >>> line = asLineString(a)
91   >>> line.wkt
92   'LINESTRING (1.0000000000000000 2.0000000000000000, 3.0000000000000000 4.0000000000000000)'
93
94
95 Python Geo Interface
96 --------------------
97
98 Any object that provides the Python geo interface can be adapted to a Shapely
99 geometry with the asShape factory::
100
101   >>> d = {"type": "Point", "coordinates": (0.0, 0.0)}
102   >>> from shapely.geometry import asShape
103   >>> shape = asShape(d)
104   >>> shape.geom_type
105   'Point'
106   >>> tuple(shape.coords)
107   ((0.0, 0.0),)
108
109   >>> class GeoThing(object):
110   ...     def __init__(self, d):
111   ...         self.__geo_interface__ = d
112   >>> thing = GeoThing({"type": "Point", "coordinates": (0.0, 0.0)})
113   >>> shape = asShape(thing)
114   >>> shape.geom_type
115   'Point'
116   >>> tuple(shape.coords)
117   ((0.0, 0.0),)
118
119 See http://trac.gispython.org/projects/PCL/wiki/PythonGeoInterface for more
120 details on the interface.
121
122
123 Testing
124 -------
125
126 Several of the modules have docstring doctests::
127
128   $ cd shapely
129   $ python point.py
130
131 There are also two test runners under tests/. test_doctests.py requires
132 zope.testing. runalldoctests.py does not. Perhaps the easiest way to run the
133 tests is::
134
135   $ python setup.py test
136
137
138 Support
139 -------
140
141 For current information about this project, see the wiki_.
142
143 .. _wiki: http://trac.gispython.org/projects/PCL/wiki/Shapely
144 .. _manual: http://gispython.org/shapely/manual.html
145
146 If you have questions, please consider joining our community list:
147
148 http://trac.gispython.org/projects/PCL/wiki/CommunityList
149
150
151 Credits
152 -------
153
154 * Sean Gillies (Pleiades)
155 * Howard Butler (Hobu, Inc.)
156 * Kai Lautaportti (Hexagon IT)
157 * Fr |eaigue| d |eaigue| ric Junod (Camptocamp SA)
158 * Eric Lemoine (Camptocamp SA)
159 * Justin Bronn (GeoDjango) for ctypes inspiration
160
161 .. |eaigue| unicode:: U+00E9
162    :trim:
163
164 Major portions of this work were supported by a grant (to Pleiades) from the
165 U.S.  National Endowment for the Humanities (http://www.neh.gov).
Note: See TracBrowser for help on using the browser.