shapely 1.0__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.
Binary file
@@ -1,157 +0,0 @@
1
- """
2
- Multi-part collection of linestrings.
3
- """
4
-
5
- from ctypes import byref, c_double, c_int, c_void_p, cast, POINTER, pointer
6
-
7
- from shapely.geos import lgeos
8
- from shapely.geometry.base import BaseGeometry, GeometrySequence, exceptNull
9
- from shapely.geometry.linestring import LineString, geos_linestring_from_py
10
-
11
-
12
- def geos_multilinestring_from_py(ob):
13
- """ob must be either a sequence or array of sequences or arrays."""
14
- try:
15
- # From array protocol
16
- array = ob.__array_interface__
17
- assert len(array['shape']) == 1
18
- L = array['shape'][0]
19
- assert L >= 1
20
-
21
- # Make pointer to the coordinate array
22
- cp = cast(array['data'][0], POINTER(c_double))
23
-
24
- # Array of pointers to sub-geometries
25
- subs = (c_void_p * L)()
26
-
27
- for l in xrange(L):
28
- geom, ndims = geos_linestring_from_py(array['data'][l])
29
- subs[i] = cast(geom, c_void_p)
30
- N = lgeos.GEOSGeom_getDimensions(subs[0])
31
-
32
- except AttributeError:
33
- # Fall back on list
34
- L = len(ob)
35
- N = len(ob[0][0])
36
- assert L >= 1
37
- assert N == 2 or N == 3
38
-
39
- # Array of pointers to point geometries
40
- subs = (c_void_p * L)()
41
-
42
- # add to coordinate sequence
43
- for l in xrange(L):
44
- geom, ndims = geos_linestring_from_py(ob[l])
45
- subs[l] = cast(geom, c_void_p)
46
-
47
- return (lgeos.GEOSGeom_createCollection(5, subs, L), N)
48
-
49
-
50
- class MultiLineString(BaseGeometry):
51
-
52
- """a multiple linestring geometry.
53
- """
54
-
55
- def __init__(self, coordinates=None):
56
- """Initialize.
57
-
58
- Parameters
59
- ----------
60
-
61
- coordinates : sequence
62
- Contains coordinate sequences or objects that provide the numpy
63
- array protocol, providing an M x 2 or M x 3 (with z) array.
64
-
65
- Example
66
- -------
67
-
68
- >>> geom = MultiLineString( [[[0.0, 0.0], [1.0, 2.0]]] )
69
- >>> geom = MultiLineString( [ array([[0.0, 0.0], [1.0, 2.0]]) ] )
70
-
71
- Each result in a collection containing one line string.
72
- """
73
- BaseGeometry.__init__(self)
74
-
75
- if coordinates is None:
76
- # allow creation of null lines, to support unpickling
77
- pass
78
- else:
79
- self._geom, self._ndim = geos_multilinestring_from_py(coordinates)
80
-
81
- @property
82
- def __geo_interface__(self):
83
- return {
84
- 'type': 'MultiLineString',
85
- 'coordinates': tuple(tuple(c for c in g.coords) for g in self.geoms)
86
- }
87
-
88
- @property
89
- def ctypes(self):
90
- raise NotImplementedError, \
91
- "Multi-part geometries have no ctypes representations"
92
-
93
- @property
94
- def __array_interface__(self):
95
- """Provide the Numpy array protocol."""
96
- raise NotImplementedError, \
97
- "Multi-part geometries do not themselves provide the array interface"
98
-
99
- @property
100
- def coords(self):
101
- raise NotImplementedError, \
102
- "Multi-part geometries do not provide a coordinate sequence"
103
-
104
- @property
105
- @exceptNull
106
- def geoms(self):
107
- return GeometrySequence(self, LineString)
108
-
109
-
110
- class MultiLineStringAdapter(MultiLineString):
111
-
112
- """Adapts sequences of sequences or numpy arrays to the multilinestring
113
- interface.
114
- """
115
-
116
- context = None
117
- __geom = None
118
- _owned = False
119
-
120
- def __init__(self, context):
121
- self.context = context
122
-
123
- @property
124
- def _ndim(self):
125
- try:
126
- # From array protocol
127
- array = self.context[0].__array_interface__
128
- n = array['shape'][1]
129
- assert n == 2 or n == 3
130
- return n
131
- except AttributeError:
132
- # Fall back on list
133
- return len(self.context[0][0])
134
-
135
- @property
136
- def _geom(self):
137
- """Keeps the GEOS geometry in synch with the context."""
138
- if self.__geom is not None:
139
- lgeos.GEOSGeom_destroy(self.__geom)
140
- self.__geom = geos_multilinestring_from_py(self.context)[0]
141
- return self.__geom
142
-
143
-
144
- def asMultiLineString(context):
145
- """Factory for MultiLineStringAdapter instances."""
146
- return MultiLineStringAdapter(context)
147
-
148
-
149
- # Test runner
150
- def _test():
151
- import doctest
152
- doctest.testmod()
153
-
154
-
155
- if __name__ == "__main__":
156
- _test()
157
-
Binary file
@@ -1,187 +0,0 @@
1
- """
2
- Multiple points.
3
- """
4
-
5
- from ctypes import byref, c_double, c_int, c_void_p, cast, POINTER, pointer
6
-
7
- from shapely.geos import lgeos
8
- from shapely.geometry.base import BaseGeometry, GeometrySequence, exceptNull
9
- from shapely.geometry.point import Point, geos_point_from_py
10
-
11
-
12
- def geos_multipoint_from_py(ob):
13
- try:
14
- # From array protocol
15
- array = ob.__array_interface__
16
- assert len(array['shape']) == 2
17
- m = array['shape'][0]
18
- n = array['shape'][1]
19
- assert m >= 1
20
- assert n == 2 or n == 3
21
-
22
- # Make pointer to the coordinate array
23
- cp = cast(array['data'][0], POINTER(c_double))
24
-
25
- # Array of pointers to sub-geometries
26
- subs = (c_void_p * m)()
27
-
28
- for i in xrange(m):
29
- geom, ndims = geos_point_from_py(cp[n*i:n*i+2])
30
- subs[i] = cast(geom, c_void_p)
31
-
32
- except AttributeError:
33
- # Fall back on list
34
- m = len(ob)
35
- n = len(ob[0])
36
- assert n == 2 or n == 3
37
-
38
- # Array of pointers to point geometries
39
- subs = (c_void_p * m)()
40
-
41
- # add to coordinate sequence
42
- for i in xrange(m):
43
- coords = ob[i]
44
- geom, ndims = geos_point_from_py(coords)
45
- subs[i] = cast(geom, c_void_p)
46
-
47
- return lgeos.GEOSGeom_createCollection(4, subs, m), n
48
-
49
-
50
- class MultiPoint(BaseGeometry):
51
-
52
- """A multiple point geometry.
53
- """
54
-
55
- def __init__(self, coordinates=None):
56
- """Initialize.
57
-
58
- Parameters
59
- ----------
60
-
61
- coordinates : sequence or array
62
- This may be an object that satisfies the numpy array protocol,
63
- providing an M x 2 or M x 3 (with z) array, or it may be a sequence
64
- of x, y (,z) coordinate sequences.
65
-
66
- Example
67
- -------
68
-
69
- >>> geom = MultiPoint([[0.0, 0.0], [1.0, 2.0]])
70
- >>> geom = MultiPoint(array([[0.0, 0.0], [1.0, 2.0]]))
71
-
72
- Each result in a line string from (0.0, 0.0) to (1.0, 2.0).
73
- """
74
- BaseGeometry.__init__(self)
75
-
76
- if coordinates is None:
77
- # allow creation of null lines, to support unpickling
78
- pass
79
- else:
80
- self._geom, self._ndim = geos_multipoint_from_py(coordinates)
81
-
82
-
83
- @property
84
- @exceptNull
85
- def __geo_interface__(self):
86
- return {
87
- 'type': 'MultiPoint',
88
- 'coordinates': tuple([g.coords[0] for g in self.geoms])
89
- }
90
-
91
- @property
92
- @exceptNull
93
- def ctypes(self):
94
- if not self._ctypes_data:
95
- temp = c_double()
96
- n = self._ndim
97
- m = len(self.geoms)
98
- array_type = c_double * (m * n)
99
- data = array_type()
100
- for i in xrange(m):
101
- g = self.geoms[i]._geom
102
- cs = lgeos.GEOSGeom_getCoordSeq(g)
103
- lgeos.GEOSCoordSeq_getX(cs, 0, byref(temp))
104
- data[n*i] = temp.value
105
- lgeos.GEOSCoordSeq_getY(cs, 0, byref(temp))
106
- data[n*i+1] = temp.value
107
- if n == 3: # TODO: use hasz
108
- lgeos.GEOSCoordSeq_getZ(cs, 0, byref(temp))
109
- data[n*i+2] = temp.value
110
- self._ctypes_data = data
111
- return self._ctypes_data
112
-
113
- @exceptNull
114
- def array_interface(self):
115
- """Provide the Numpy array protocol."""
116
- ai = self.array_interface_base
117
- ai.update({'shape': (len(self.geoms), self._ndim)})
118
- return ai
119
- __array_interface__ = property(array_interface)
120
-
121
- @property
122
- def coords(self):
123
- raise NotImplementedError, \
124
- "Multipart geometries do not themselves provide coordinate sequences"
125
-
126
- @property
127
- @exceptNull
128
- def geoms(self):
129
- return GeometrySequence(self, Point)
130
-
131
-
132
- class MultiPointAdapter(MultiPoint):
133
-
134
- """Adapts a Python coordinate pair or a numpy array to the multipoint
135
- interface.
136
- """
137
-
138
- context = None
139
- __geom = None
140
- _owned = False
141
-
142
- def __init__(self, context):
143
- self.context = context
144
-
145
- @property
146
- def _ndim(self):
147
- try:
148
- # From array protocol
149
- array = self.context.__array_interface__
150
- n = array['shape'][1]
151
- assert n == 2 or n == 3
152
- return n
153
- except AttributeError:
154
- # Fall back on list
155
- return len(self.context[0])
156
-
157
- @property
158
- def _geom(self):
159
- """Keeps the GEOS geometry in synch with the context."""
160
- if self.__geom is not None:
161
- lgeos.GEOSGeom_destroy(self.__geom)
162
- self.__geom, n = geos_multipoint_from_py(self.context)
163
- return self.__geom
164
-
165
- @property
166
- def __array_interface__(self):
167
- """Provide the Numpy array protocol."""
168
- try:
169
- return self.context.__array_interface__
170
- except AttributeError:
171
- return self.array_interface()
172
-
173
-
174
- def asMultiPoint(context):
175
- """Factory for MultiPointAdapter instances."""
176
- return MultiPointAdapter(context)
177
-
178
-
179
- # Test runner
180
- def _test():
181
- import doctest
182
- doctest.testmod()
183
-
184
-
185
- if __name__ == "__main__":
186
- _test()
187
-
Binary file
@@ -1,143 +0,0 @@
1
- """
2
- Multi-part collection of polygons.
3
- """
4
-
5
- from ctypes import byref, c_double, c_int, c_void_p, cast, POINTER, pointer
6
-
7
- from shapely.geos import lgeos
8
- from shapely.geometry.base import BaseGeometry, GeometrySequence, exceptNull
9
- from shapely.geometry.polygon import Polygon, geos_polygon_from_py
10
-
11
-
12
- def geos_multipolygon_from_py(ob):
13
- """ob must be either a sequence or array of sequences or arrays."""
14
- L = len(ob)
15
- N = len(ob[0][0][0])
16
- assert L >= 1
17
- assert N == 2 or N == 3
18
-
19
- subs = (c_void_p * L)()
20
- for l in xrange(L):
21
- geom, ndims = geos_polygon_from_py(ob[l][0], ob[l][1])
22
- subs[l] = cast(geom, c_void_p)
23
-
24
- return (lgeos.GEOSGeom_createCollection(6, subs, L), N)
25
-
26
-
27
- class MultiPolygon(BaseGeometry):
28
-
29
- """a multiple polygon geometry.
30
- """
31
-
32
- def __init__(self, polygons=None):
33
- """Initialize.
34
-
35
- Parameters
36
- ----------
37
-
38
- polygons : sequence
39
- A sequence of (shell, holes) tuples where shell is the sequence
40
- representation of a linear ring (see linearring.py) and holes is
41
- a sequence of such linear rings.
42
-
43
- Example
44
- -------
45
- >>> geom = MultiPolygon( [
46
- ... (
47
- ... ((0.0, 0.0), (0.0, 1.0), (1.0, 1.0), (1.0, 0.0)),
48
- ... [((0.1,0.1), (0.1,0.2), (0.2,0.2), (0.2,0.1))]
49
- ... )
50
- ... ] )
51
- """
52
- BaseGeometry.__init__(self)
53
-
54
- if polygons is None:
55
- # allow creation of null collections, to support unpickling
56
- pass
57
- else:
58
- self._geom, self._ndim = geos_multipolygon_from_py(polygons)
59
-
60
- @property
61
- def __geo_interface__(self):
62
- allcoords = []
63
- for geom in self.geoms:
64
- coords = []
65
- coords.append(tuple(geom.exterior.coords))
66
- for hole in geom.interiors:
67
- coords.append(tuple(hole.coords))
68
- allcoords.append(coords)
69
- return {
70
- 'type': 'MultiPolygon',
71
- 'coordinates': allcoords
72
- }
73
-
74
- @property
75
- def ctypes(self):
76
- raise NotImplementedError, \
77
- "Multi-part geometries have no ctypes representations"
78
-
79
- @property
80
- def __array_interface__(self):
81
- """Provide the Numpy array protocol."""
82
- raise NotImplementedError, \
83
- "Multi-part geometries do not themselves provide the array interface"
84
-
85
- @property
86
- def coords(self):
87
- raise NotImplementedError, \
88
- "Multi-part geometries do not provide a coordinate sequence"
89
-
90
- @property
91
- @exceptNull
92
- def geoms(self):
93
- return GeometrySequence(self, Polygon)
94
-
95
-
96
- class MultiPolygonAdapter(MultiPolygon):
97
-
98
- """Adapts sequences of sequences or numpy arrays to the multipolygon
99
- interface.
100
- """
101
-
102
- context = None
103
- __geom = None
104
- _owned = False
105
-
106
- def __init__(self, context):
107
- self.context = context
108
-
109
- @property
110
- def _ndim(self):
111
- try:
112
- # From array protocol
113
- array = self.context[0][0].__array_interface__
114
- n = array['shape'][1]
115
- assert n == 2 or n == 3
116
- return n
117
- except AttributeError:
118
- # Fall back on list
119
- return len(self.context[0][0][0])
120
-
121
- @property
122
- def _geom(self):
123
- """Keeps the GEOS geometry in synch with the context."""
124
- if self.__geom is not None:
125
- lgeos.GEOSGeom_destroy(self.__geom)
126
- self.__geom = geos_multipolygon_from_py(self.context)[0]
127
- return self.__geom
128
-
129
-
130
- def asMultiPolygon(context):
131
- """Factory for MultiLineStringAdapter instances."""
132
- return MultiPolygonAdapter(context)
133
-
134
-
135
- # Test runner
136
- def _test():
137
- import doctest
138
- doctest.testmod()
139
-
140
-
141
- if __name__ == "__main__":
142
- _test()
143
-
Binary file