shapely 1.0a7__py2.4.egg → 1.0b1__py2.4.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 CHANGED
@@ -1,11 +1,11 @@
1
1
  Metadata-Version: 1.0
2
2
  Name: Shapely
3
- Version: 1.0a7
3
+ Version: 1.0b1
4
4
  Summary: Geospatial geometries, predicates, and operations
5
- Home-page: http://trac.gispython.org/projects/PCL/wiki/ShapeLy
5
+ Home-page: http://trac.gispython.org/projects/PCL/wiki/Shapely
6
6
  Author: Sean Gillies
7
7
  Author-email: sgillies@frii.com
8
- License: LGPL
8
+ License: BSD
9
9
  Description: Shapely
10
10
  =======
11
11
 
@@ -20,9 +20,6 @@ Description: Shapely
20
20
  Shapely requires Python 2.4+. (I've also begun to port it to Python 3.0:
21
21
  http://zcologia.com/news/564/shapely-for-python-3-0/.)
22
22
 
23
- .. _wiki: http://trac.gispython.org/projects/PCL/wiki/Shapely
24
- .. _manual: http://trac.gispython.org/projects/PCL/wiki/ShapelyManual
25
-
26
23
  Dependencies
27
24
  ------------
28
25
 
@@ -121,13 +118,25 @@ Description: Shapely
121
118
  There are also two test runners under tests/. test_doctests.py requires
122
119
  zope.testing. runalldoctests.py does not.
123
120
 
121
+ Support
122
+ -------
123
+
124
+ For current information about this project, see the wiki_.
125
+
126
+ .. _wiki: http://trac.gispython.org/projects/PCL/wiki/Shapely
127
+ .. _manual: http://trac.gispython.org/projects/PCL/wiki/ShapelyManual
128
+
129
+ If you have questions, please consider joining our community list:
130
+
131
+ http://trac.gispython.org/projects/PCL/wiki/CommunityList
132
+
124
133
 
125
134
  Keywords: geometry topology
126
135
  Platform: UNKNOWN
127
- Classifier: Development Status :: 3 - Alpha
136
+ Classifier: Development Status :: 4 - Beta
128
137
  Classifier: Intended Audience :: Developers
129
138
  Classifier: Intended Audience :: Science/Research
130
- Classifier: License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)
139
+ Classifier: License :: OSI Approved :: BSD License
131
140
  Classifier: Operating System :: OS Independent
132
141
  Classifier: Programming Language :: Python
133
142
  Classifier: Topic :: Scientific/Engineering :: GIS
EGG-INFO/SOURCES.txt CHANGED
@@ -1,4 +1,7 @@
1
+ CHANGES.txt
1
2
  CREDITS.txt
3
+ HISTORY.txt
4
+ LICENSE.txt
2
5
  README.txt
3
6
  setup.py
4
7
  Shapely.egg-info/PKG-INFO
@@ -39,7 +42,8 @@ tests/Point.txt
39
42
  tests/Polygon.txt
40
43
  tests/Predicates.txt
41
44
  tests/__init__.py
42
- tests/runalldoctests.py
45
+ tests/binascii_hex.txt
46
+ tests/invalid_intersection.txt
43
47
  tests/rungrind.dist
44
- tests/runtests.dist
45
48
  tests/test_doctests.py
49
+ tests/valgrind-python.supp
shapely/topology.py CHANGED
@@ -26,7 +26,17 @@ class BinaryTopologicalOp(object):
26
26
  return self
27
27
 
28
28
  def __call__(self, other):
29
- return self.factory(self.fn(self.context._geom, other._geom))
29
+ product = self.fn(self.context._geom, other._geom)
30
+ if not product:
31
+ # Check validity of geometries
32
+ if not self.context.is_valid:
33
+ raise TopologicalError, \
34
+ "The operation '%s' produced a null geometry. Likely cause is invalidity of the geometry %s" % (self.fn.__name__, repr(self.context))
35
+ elif not other.is_valid:
36
+ raise TopologicalError, \
37
+ "The operation '%s' produced a null geometry. Likely cause is invalidity of the 'other' geometry %s" % (self.fn.__name__, repr(other))
38
+
39
+ return self.factory(product)
30
40
 
31
41
 
32
42
  class UnaryTopologicalOp(object):
shapely/topology.pyc CHANGED
Binary file
@@ -1,9 +0,0 @@
1
- from geo import asShape
2
- from point import Point, asPoint
3
- from linestring import LineString, asLineString
4
- from polygon import Polygon, asPolygon
5
- from multipoint import MultiPoint, asMultiPoint
6
- from multilinestring import MultiLineString, asMultiLineString
7
- from multipolygon import MultiPolygon, asMultiPolygon
8
- from collection import GeometryCollection
9
-
Binary file
shapely/geometry/base.py DELETED
@@ -1,327 +0,0 @@
1
- """
2
- Base geometry class and utilities.
3
- """
4
-
5
- from ctypes import string_at, byref, c_int, c_size_t, c_char_p, c_double
6
-
7
- from shapely.geos import lgeos
8
- from shapely.predicates import BinaryPredicate, UnaryPredicate
9
- from shapely.topology import BinaryTopologicalOp, UnaryTopologicalOp
10
-
11
-
12
- # Abstract geometry factory for use with topological methods below
13
-
14
- def geom_factory(g):
15
- ob = BaseGeometry()
16
- geom_type = string_at(lgeos.GEOSGeomType(g))
17
- # TODO: check cost of dynamic import by profiling
18
- mod = __import__(
19
- 'shapely.geometry',
20
- globals(),
21
- locals(),
22
- [geom_type],
23
- )
24
- ob.__class__ = getattr(mod, geom_type)
25
- ob._geom = g
26
- ob._ndim = 2 # callers should be all from 2D worlds
27
- return ob
28
-
29
-
30
- class CoordinateSequence(object):
31
-
32
- _cseq = None
33
- _ndim = None
34
- _length = 0
35
- index = 0
36
-
37
- def __init__(self, geom):
38
- self._cseq = lgeos.GEOSGeom_getCoordSeq(geom._geom)
39
- self._ndim = geom._ndim
40
-
41
- def __iter__(self):
42
- self.index = 0
43
- self._length = self.__len__()
44
- return self
45
-
46
- def next(self):
47
- dx = c_double()
48
- dy = c_double()
49
- dz = c_double()
50
- i = self.index
51
- if i < self._length:
52
- lgeos.GEOSCoordSeq_getX(self._cseq, i, byref(dx))
53
- lgeos.GEOSCoordSeq_getY(self._cseq, i, byref(dy))
54
- if self._ndim == 3: # TODO: use hasz
55
- lgeos.GEOSCoordSeq_getZ(self._cseq, i, byref(dz))
56
- self.index += 1
57
- return (dx.value, dy.value, dz.value)
58
- else:
59
- self.index += 1
60
- return (dx.value, dy.value)
61
- else:
62
- raise StopIteration
63
-
64
- def __len__(self):
65
- cs_len = c_int(0)
66
- lgeos.GEOSCoordSeq_getSize(self._cseq, byref(cs_len))
67
- return cs_len.value
68
-
69
- def __getitem__(self, i):
70
- M = self.__len__()
71
- if i + M < 0 or i >= M:
72
- raise IndexError, "index out of range"
73
- if i < 0:
74
- ii = M + i
75
- else:
76
- ii = i
77
- dx = c_double()
78
- dy = c_double()
79
- dz = c_double()
80
- lgeos.GEOSCoordSeq_getX(self._cseq, ii, byref(dx))
81
- lgeos.GEOSCoordSeq_getY(self._cseq, ii, byref(dy))
82
- if self._ndim == 3: # TODO: use hasz
83
- lgeos.GEOSCoordSeq_getZ(self._cseq, ii, byref(dz))
84
- return (dx.value, dy.value, dz.value)
85
- else:
86
- return (dx.value, dy.value)
87
-
88
-
89
- class GeometrySequence(object):
90
-
91
- _factory = None
92
- _geom = None
93
- _ndim = None
94
- _index = 0
95
- _length = 0
96
-
97
- def __init__(self, geom, type):
98
- self._factory = type
99
- self._geom = geom._geom
100
- self._ndim = geom._ndim
101
-
102
- def __iter__(self):
103
- self._index = 0
104
- self._length = self.__len__()
105
- return self
106
-
107
- def next(self):
108
- if self._index < self.__len__():
109
- g = self._factory()
110
- g._owned = True
111
- g._geom = lgeos.GEOSGetGeometryN(self._geom, self._index)
112
- self._index += 1
113
- return g
114
- else:
115
- raise StopIteration
116
-
117
- def __len__(self):
118
- return lgeos.GEOSGetNumGeometries(self._geom)
119
-
120
- def __getitem__(self, i):
121
- M = self.__len__()
122
- if i + M < 0 or i >= M:
123
- raise IndexError, "index out of range"
124
- if i < 0:
125
- ii = M + i
126
- else:
127
- ii = i
128
- g = self._factory()
129
- g._owned = True
130
- g._geom = lgeos.GEOSGetGeometryN(self._geom, ii)
131
- return g
132
-
133
- @property
134
- def _longest(self):
135
- max = 0
136
- for g in iter(self):
137
- l = len(g.coords)
138
- if l > max:
139
- max = l
140
-
141
-
142
- class BaseGeometry(object):
143
-
144
- """Provides GEOS spatial predicates and topological operations.
145
- """
146
-
147
- _geom = None
148
- _ctypes_data = None
149
- _ndim = None
150
- _crs = None
151
- _owned = False
152
-
153
- def __init__(self):
154
- self._geom = lgeos.GEOSGeomFromWKT(c_char_p('GEOMETRYCOLLECTION EMPTY'))
155
-
156
- def __del__(self):
157
- if self._geom is not None and not self._owned:
158
- lgeos.GEOSGeom_destroy(self._geom)
159
-
160
- def __str__(self):
161
- return self.to_wkt()
162
-
163
- def __eq__(self, other):
164
- return self.equals(other)
165
-
166
- def __ne__(self, other):
167
- return not self.equals(other)
168
-
169
- # To support pickling
170
-
171
- def __reduce__(self):
172
- return (self.__class__, (), self.to_wkb())
173
-
174
- def __setstate__(self, state):
175
- self._geom = lgeos.GEOSGeomFromWKB_buf(
176
- c_char_p(state),
177
- c_size_t(len(state))
178
- )
179
-
180
- # Array and ctypes interfaces
181
-
182
- @property
183
- def ctypes(self):
184
- """Return a ctypes representation.
185
-
186
- To be overridden by extension classes."""
187
- raise NotImplementedError
188
-
189
- @property
190
- def __array_interface__(self):
191
- """Provide the Numpy array protocol."""
192
- raise NotImplementedError
193
-
194
- def get_coords(self):
195
- return CoordinateSequence(self)
196
-
197
- def set_coords(self, ob):
198
- raise NotImplementedError, \
199
- "set_coords must be provided by derived classes"
200
-
201
- coords = property(get_coords, set_coords)
202
-
203
- # Python feature protocol
204
-
205
- @property
206
- def __geo_interface__(self):
207
- raise NotImplementedError
208
-
209
- @property
210
- def type(self):
211
- return self.geometryType()
212
-
213
- # Type of geometry and its representations
214
-
215
- def geometryType(self):
216
- """Returns a string representing the geometry type, e.g. 'Polygon'."""
217
- return string_at(lgeos.GEOSGeomType(self._geom))
218
-
219
- def to_wkb(self):
220
- """Returns a WKB byte string representation of the geometry."""
221
- size = c_int()
222
- bytes = lgeos.GEOSGeomToWKB_buf(self._geom, byref(size))
223
- return string_at(bytes, size.value)
224
-
225
- def to_wkt(self):
226
- """Returns a WKT string representation of the geometry."""
227
- return string_at(lgeos.GEOSGeomToWKT(self._geom))
228
-
229
- geom_type = property(geometryType)
230
- wkt = property(to_wkt)
231
- wkb = property(to_wkb)
232
-
233
- # Basic geometry properties
234
-
235
- @property
236
- def area(self):
237
- a = c_double()
238
- retval = lgeos.GEOSArea(self._geom, byref(a))
239
- return a.value
240
-
241
- @property
242
- def length(self):
243
- len = c_double()
244
- retval = lgeos.GEOSLength(self._geom, byref(len))
245
- return len.value
246
-
247
- def distance(self, other):
248
- d = c_double()
249
- retval = lgeos.GEOSDistance(self._geom, other._geom, byref(d))
250
- return d.value
251
-
252
- # Topology operations
253
- #
254
- # These use descriptors to reduce the amount of boilerplate.
255
-
256
- envelope = UnaryTopologicalOp(lgeos.GEOSEnvelope, geom_factory)
257
- intersection = BinaryTopologicalOp(lgeos.GEOSIntersection, geom_factory)
258
- convex_hull = UnaryTopologicalOp(lgeos.GEOSConvexHull, geom_factory)
259
- difference = BinaryTopologicalOp(lgeos.GEOSDifference, geom_factory)
260
- symmetric_difference = BinaryTopologicalOp(lgeos.GEOSSymDifference,
261
- geom_factory)
262
- boundary = UnaryTopologicalOp(lgeos.GEOSBoundary, geom_factory)
263
- union = BinaryTopologicalOp(lgeos.GEOSUnion, geom_factory)
264
- centroid = UnaryTopologicalOp(lgeos.GEOSGetCentroid, geom_factory)
265
-
266
- # Buffer has a unique distance argument, so not a descriptor
267
- def buffer(self, distance, quadsegs=16):
268
- return geom_factory(
269
- lgeos.GEOSBuffer(self._geom, c_double(distance), c_int(quadsegs))
270
- )
271
-
272
- # Relate has a unique string return value
273
- def relate(self, other):
274
- func = lgeos.GEOSRelate
275
- func.restype = c_char_p
276
- return lgeos.GEOSRelate(self._geom, other._geom)
277
-
278
- # Binary predicates
279
- #
280
- # These use descriptors to reduce the amount of boilerplate.
281
-
282
- # TODO: Relate Pattern?
283
- disjoint = BinaryPredicate(lgeos.GEOSDisjoint)
284
- touches = BinaryPredicate(lgeos.GEOSTouches)
285
- intersects = BinaryPredicate(lgeos.GEOSIntersects)
286
- crosses = BinaryPredicate(lgeos.GEOSCrosses)
287
- within = BinaryPredicate(lgeos.GEOSWithin)
288
- contains = BinaryPredicate(lgeos.GEOSContains)
289
- overlaps = BinaryPredicate(lgeos.GEOSOverlaps)
290
- equals = BinaryPredicate(lgeos.GEOSEquals)
291
-
292
- # Unary predicates
293
- #
294
- # These use descriptors to reduce the amount of boilerplate.
295
-
296
- is_empty = UnaryPredicate(lgeos.GEOSisEmpty)
297
- is_valid = UnaryPredicate(lgeos.GEOSisValid)
298
- is_simple = UnaryPredicate(lgeos.GEOSisSimple)
299
- is_ring = UnaryPredicate(lgeos.GEOSisRing)
300
- has_z = UnaryPredicate(lgeos.GEOSHasZ)
301
-
302
- @property
303
- def bounds(self):
304
- env = self.envelope
305
- if env.geom_type != 'Polygon':
306
- raise ValueError, env.wkt
307
- cs = lgeos.GEOSGeom_getCoordSeq(env.exterior._geom)
308
- cs_len = c_int(0)
309
- lgeos.GEOSCoordSeq_getSize(cs, byref(cs_len))
310
-
311
- minx = 1.e+20
312
- maxx = -1e+20
313
- miny = 1.e+20
314
- maxy = -1e+20
315
- temp = c_double()
316
- for i in xrange(cs_len.value):
317
- lgeos.GEOSCoordSeq_getX(cs, i, byref(temp))
318
- x = temp.value
319
- if x < minx: minx = x
320
- if x > maxx: maxx = x
321
- lgeos.GEOSCoordSeq_getY(cs, i, byref(temp))
322
- y = temp.value
323
- if y < miny: miny = y
324
- if y > maxy: maxy = y
325
-
326
- return (minx, miny, maxx, maxy)
327
-
shapely/geometry/base.pyc DELETED
Binary file
@@ -1,24 +0,0 @@
1
- """
2
- Geometry collections.
3
- """
4
-
5
- from shapely.geometry.base import BaseGeometry
6
-
7
- class GeometryCollection(BaseGeometry):
8
-
9
- """A geometry collection.
10
- """
11
-
12
- def __init__(self):
13
- BaseGeometry.__init__(self)
14
-
15
-
16
- # Test runner
17
- def _test():
18
- import doctest
19
- doctest.testmod()
20
-
21
-
22
- if __name__ == "__main__":
23
- _test()
24
-
Binary file
shapely/geometry/geo.py DELETED
@@ -1,35 +0,0 @@
1
-
2
- from point import PointAdapter
3
- from linestring import LineStringAdapter
4
- from polygon import PolygonAdapter
5
- from multipoint import MultiPointAdapter
6
- from multilinestring import MultiLineStringAdapter
7
- from multipolygon import MultiPolygonAdapter
8
-
9
-
10
- def asShape(context):
11
- """Adapts the context to a geometry interface. The coordinates remain
12
- stored in the context.
13
- """
14
- if hasattr(context, "__geo_interface__"):
15
- ob = context.__geo_interface__
16
- else:
17
- ob = context
18
-
19
- geom_type = ob.get("type").lower()
20
-
21
- if geom_type == "point":
22
- return PointAdapter(ob["coordinates"])
23
- elif geom_type == "linestring":
24
- return LineStringAdapter(ob["coordinates"])
25
- elif geom_type == "polygon":
26
- return PolygonAdapter(ob["coordinates"][0], ob["coordinates"][1:])
27
- elif geom_type == "multipoint":
28
- return MultiPointAdapter(ob["coordinates"])
29
- elif geom_type == "multilinestring":
30
- return MultiLineStringAdapter(ob["coordinates"])
31
- elif geom_type == "multipolygon":
32
- return MultiPolygonAdapter(ob["coordinates"])
33
- else:
34
- raise ValueError, "Unknown geometry type: %s" % geom_type
35
-
shapely/geometry/geo.pyc DELETED
Binary file