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 +17 -8
- EGG-INFO/SOURCES.txt +6 -2
- shapely/topology.py +11 -1
- shapely/topology.pyc +0 -0
- shapely/geometry/__init__.py +0 -9
- shapely/geometry/__init__.pyc +0 -0
- shapely/geometry/base.py +0 -327
- shapely/geometry/base.pyc +0 -0
- shapely/geometry/collection.py +0 -24
- shapely/geometry/collection.pyc +0 -0
- shapely/geometry/geo.py +0 -35
- shapely/geometry/geo.pyc +0 -0
- shapely/geometry/linestring.py +0 -236
- shapely/geometry/linestring.pyc +0 -0
- shapely/geometry/multilinestring.py +0 -155
- shapely/geometry/multilinestring.pyc +0 -0
- shapely/geometry/multipoint.py +0 -190
- shapely/geometry/multipoint.pyc +0 -0
- shapely/geometry/multipolygon.py +0 -141
- shapely/geometry/multipolygon.pyc +0 -0
- shapely/geometry/point.py +0 -249
- shapely/geometry/point.pyc +0 -0
- shapely/geometry/polygon.py +0 -414
- shapely/geometry/polygon.pyc +0 -0
- shapely/json.py +0 -47
- shapely/json.pyc +0 -0
shapely/geometry/linestring.py
DELETED
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
"""
|
|
2
|
-
Line strings.
|
|
3
|
-
"""
|
|
4
|
-
|
|
5
|
-
from ctypes import byref, c_double, c_int, cast, POINTER, pointer
|
|
6
|
-
from ctypes import ArgumentError
|
|
7
|
-
|
|
8
|
-
from shapely.geos import lgeos
|
|
9
|
-
from shapely.geometry.base import BaseGeometry
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
def geos_linestring_from_py(ob, update_geom=None, update_ndim=0):
|
|
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 >= 2
|
|
20
|
-
assert n == 2 or n == 3
|
|
21
|
-
|
|
22
|
-
# Make pointer to the coordinate array
|
|
23
|
-
try:
|
|
24
|
-
cp = cast(array['data'][0], POINTER(c_double))
|
|
25
|
-
except ArgumentError:
|
|
26
|
-
cp = array['data']
|
|
27
|
-
|
|
28
|
-
# Create a coordinate sequence
|
|
29
|
-
if update_geom is not None:
|
|
30
|
-
cs = lgeos.GEOSGeom_getCoordSeq(update_geom)
|
|
31
|
-
if n != update_ndim:
|
|
32
|
-
raise ValueError, \
|
|
33
|
-
"Wrong coordinate dimensions; this geometry has dimensions: %d" \
|
|
34
|
-
% update_ndim
|
|
35
|
-
else:
|
|
36
|
-
cs = lgeos.GEOSCoordSeq_create(m, n)
|
|
37
|
-
|
|
38
|
-
# add to coordinate sequence
|
|
39
|
-
for i in xrange(m):
|
|
40
|
-
dx = c_double(cp[n*i])
|
|
41
|
-
dy = c_double(cp[n*i+1])
|
|
42
|
-
dz = None
|
|
43
|
-
if n == 3:
|
|
44
|
-
dz = c_double(cp[n*i+2])
|
|
45
|
-
|
|
46
|
-
# Because of a bug in the GEOS C API,
|
|
47
|
-
# always set X before Y
|
|
48
|
-
lgeos.GEOSCoordSeq_setX(cs, i, dx)
|
|
49
|
-
lgeos.GEOSCoordSeq_setY(cs, i, dy)
|
|
50
|
-
if n == 3:
|
|
51
|
-
lgeos.GEOSCoordSeq_setZ(cs, i, dz)
|
|
52
|
-
|
|
53
|
-
except AttributeError:
|
|
54
|
-
# Fall back on list
|
|
55
|
-
m = len(ob)
|
|
56
|
-
n = len(ob[0])
|
|
57
|
-
assert m >= 2
|
|
58
|
-
assert n == 2 or n == 3
|
|
59
|
-
|
|
60
|
-
# Create a coordinate sequence
|
|
61
|
-
if update_geom is not None:
|
|
62
|
-
cs = lgeos.GEOSGeom_getCoordSeq(update_geom)
|
|
63
|
-
if n != update_ndim:
|
|
64
|
-
raise ValueError, \
|
|
65
|
-
"Wrong coordinate dimensions; this geometry has dimensions: %d" \
|
|
66
|
-
% update_ndim
|
|
67
|
-
else:
|
|
68
|
-
cs = lgeos.GEOSCoordSeq_create(m, n)
|
|
69
|
-
|
|
70
|
-
# add to coordinate sequence
|
|
71
|
-
for i in xrange(m):
|
|
72
|
-
coords = ob[i]
|
|
73
|
-
dx = c_double(coords[0])
|
|
74
|
-
dy = c_double(coords[1])
|
|
75
|
-
dz = None
|
|
76
|
-
if n == 3:
|
|
77
|
-
dz = c_double(coords[2])
|
|
78
|
-
|
|
79
|
-
# Because of a bug in the GEOS C API,
|
|
80
|
-
# always set X before Y
|
|
81
|
-
lgeos.GEOSCoordSeq_setX(cs, i, dx)
|
|
82
|
-
lgeos.GEOSCoordSeq_setY(cs, i, dy)
|
|
83
|
-
if n == 3:
|
|
84
|
-
lgeos.GEOSCoordSeq_setZ(cs, i, dz)
|
|
85
|
-
|
|
86
|
-
if update_geom is not None:
|
|
87
|
-
return None
|
|
88
|
-
else:
|
|
89
|
-
return (lgeos.GEOSGeom_createLineString(cs), n)
|
|
90
|
-
|
|
91
|
-
def update_linestring_from_py(geom, ob):
|
|
92
|
-
geos_linestring_from_py(ob, geom._geom, geom._ndim)
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
class LineString(BaseGeometry):
|
|
96
|
-
|
|
97
|
-
"""A line string, also known as a polyline.
|
|
98
|
-
|
|
99
|
-
"""
|
|
100
|
-
|
|
101
|
-
def __init__(self, coordinates=None):
|
|
102
|
-
"""Initialize.
|
|
103
|
-
|
|
104
|
-
Parameters
|
|
105
|
-
----------
|
|
106
|
-
|
|
107
|
-
coordinates : sequence or array
|
|
108
|
-
This may be an object that satisfies the numpy array protocol,
|
|
109
|
-
providing an M x 2 or M x 3 (with z) array, or it may be a sequence
|
|
110
|
-
of x, y (,z) coordinate sequences.
|
|
111
|
-
|
|
112
|
-
Example
|
|
113
|
-
-------
|
|
114
|
-
|
|
115
|
-
>>> line = LineString([[0.0, 0.0], [1.0, 2.0]])
|
|
116
|
-
>>> line = LineString(array([[0.0, 0.0], [1.0, 2.0]]))
|
|
117
|
-
|
|
118
|
-
Each result in a line string from (0.0, 0.0) to (1.0, 2.0).
|
|
119
|
-
"""
|
|
120
|
-
BaseGeometry.__init__(self)
|
|
121
|
-
|
|
122
|
-
if coordinates is None:
|
|
123
|
-
# allow creation of null lines, to support unpickling
|
|
124
|
-
pass
|
|
125
|
-
else:
|
|
126
|
-
self._geom, self._ndim = geos_linestring_from_py(coordinates)
|
|
127
|
-
|
|
128
|
-
@property
|
|
129
|
-
def __geo_interface__(self):
|
|
130
|
-
return {
|
|
131
|
-
'type': 'LineString',
|
|
132
|
-
'coordinates': tuple(self.coords)
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
@property
|
|
136
|
-
def ctypes(self):
|
|
137
|
-
if not self._ctypes_data:
|
|
138
|
-
cs = lgeos.GEOSGeom_getCoordSeq(self._geom)
|
|
139
|
-
cs_len = c_int(0)
|
|
140
|
-
lgeos.GEOSCoordSeq_getSize(cs, byref(cs_len))
|
|
141
|
-
temp = c_double()
|
|
142
|
-
n = self._ndim
|
|
143
|
-
m = cs_len.value
|
|
144
|
-
array_type = c_double * (m * n)
|
|
145
|
-
data = array_type()
|
|
146
|
-
for i in xrange(m):
|
|
147
|
-
lgeos.GEOSCoordSeq_getX(cs, i, byref(temp))
|
|
148
|
-
data[n*i] = temp.value
|
|
149
|
-
lgeos.GEOSCoordSeq_getY(cs, i, byref(temp))
|
|
150
|
-
data[n*i+1] = temp.value
|
|
151
|
-
if n == 3: # TODO: use hasz
|
|
152
|
-
lgeos.GEOSCoordSeq_getZ(cs, i, byref(temp))
|
|
153
|
-
data[n*i+2] = temp.value
|
|
154
|
-
self._ctypes_data = data
|
|
155
|
-
return self._ctypes_data
|
|
156
|
-
|
|
157
|
-
@property
|
|
158
|
-
def __array_interface__(self):
|
|
159
|
-
"""Provide the Numpy array protocol."""
|
|
160
|
-
return {
|
|
161
|
-
'version': 3,
|
|
162
|
-
'shape': (len(self.coords), self._ndim),
|
|
163
|
-
'typestr': '<f8',
|
|
164
|
-
'data': self.ctypes,
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
# Coordinate access
|
|
168
|
-
|
|
169
|
-
def set_coords(self, coordinates):
|
|
170
|
-
update_linestring_from_py(self, coordinates)
|
|
171
|
-
|
|
172
|
-
coords = property(BaseGeometry.get_coords, set_coords)
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
class LineStringAdapter(LineString):
|
|
176
|
-
|
|
177
|
-
"""Adapts a Python coordinate pair or a numpy array to the line string
|
|
178
|
-
interface.
|
|
179
|
-
"""
|
|
180
|
-
|
|
181
|
-
context = None
|
|
182
|
-
|
|
183
|
-
def __init__(self, context):
|
|
184
|
-
self.context = context
|
|
185
|
-
|
|
186
|
-
# Override base class __del__
|
|
187
|
-
def __del__(self):
|
|
188
|
-
pass
|
|
189
|
-
|
|
190
|
-
@property
|
|
191
|
-
def _ndim(self):
|
|
192
|
-
try:
|
|
193
|
-
# From array protocol
|
|
194
|
-
array = self.context.__array_interface__
|
|
195
|
-
n = array['shape'][1]
|
|
196
|
-
assert n == 2 or n == 3
|
|
197
|
-
return n
|
|
198
|
-
except AttributeError:
|
|
199
|
-
# Fall back on list
|
|
200
|
-
return len(self.context[0])
|
|
201
|
-
|
|
202
|
-
@property
|
|
203
|
-
def _geom(self):
|
|
204
|
-
"""Keeps the GEOS geometry in synch with the context."""
|
|
205
|
-
return geos_linestring_from_py(self.context)[0]
|
|
206
|
-
|
|
207
|
-
@property
|
|
208
|
-
def __array_interface__(self):
|
|
209
|
-
"""Provide the Numpy array protocol."""
|
|
210
|
-
try:
|
|
211
|
-
return self.context.__array_interface__
|
|
212
|
-
except AttributeError:
|
|
213
|
-
return {
|
|
214
|
-
'version': 3,
|
|
215
|
-
'shape': (self._ndim,),
|
|
216
|
-
'typestr': '<f8',
|
|
217
|
-
'data': self.ctypes,
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
coords = property(BaseGeometry.get_coords)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
def asLineString(context):
|
|
224
|
-
"""Factory for PointAdapter instances."""
|
|
225
|
-
return LineStringAdapter(context)
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
# Test runner
|
|
229
|
-
def _test():
|
|
230
|
-
import doctest
|
|
231
|
-
doctest.testmod()
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
if __name__ == "__main__":
|
|
235
|
-
_test()
|
|
236
|
-
|
shapely/geometry/linestring.pyc
DELETED
|
Binary file
|
|
@@ -1,155 +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
|
|
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
|
-
def geoms(self):
|
|
106
|
-
return GeometrySequence(self, LineString)
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
class MultiLineStringAdapter(MultiLineString):
|
|
110
|
-
|
|
111
|
-
"""Adapts sequences of sequences or numpy arrays to the multilinestring
|
|
112
|
-
interface.
|
|
113
|
-
"""
|
|
114
|
-
|
|
115
|
-
context = None
|
|
116
|
-
|
|
117
|
-
def __init__(self, context):
|
|
118
|
-
self.context = context
|
|
119
|
-
|
|
120
|
-
# Override base class __del__
|
|
121
|
-
def __del__(self):
|
|
122
|
-
pass
|
|
123
|
-
|
|
124
|
-
@property
|
|
125
|
-
def _ndim(self):
|
|
126
|
-
try:
|
|
127
|
-
# From array protocol
|
|
128
|
-
array = self.context[0].__array_interface__
|
|
129
|
-
n = array['shape'][1]
|
|
130
|
-
assert n == 2 or n == 3
|
|
131
|
-
return n
|
|
132
|
-
except AttributeError:
|
|
133
|
-
# Fall back on list
|
|
134
|
-
return len(self.context[0][0])
|
|
135
|
-
|
|
136
|
-
@property
|
|
137
|
-
def _geom(self):
|
|
138
|
-
"""Keeps the GEOS geometry in synch with the context."""
|
|
139
|
-
return geos_multilinestring_from_py(self.context)[0]
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
def asMultiLineString(context):
|
|
143
|
-
"""Factory for MultiLineStringAdapter instances."""
|
|
144
|
-
return MultiLineStringAdapter(context)
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
# Test runner
|
|
148
|
-
def _test():
|
|
149
|
-
import doctest
|
|
150
|
-
doctest.testmod()
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if __name__ == "__main__":
|
|
154
|
-
_test()
|
|
155
|
-
|
|
Binary file
|
shapely/geometry/multipoint.py
DELETED
|
@@ -1,190 +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
|
|
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
|
-
def __geo_interface__(self):
|
|
85
|
-
return {
|
|
86
|
-
'type': 'MultiPoint',
|
|
87
|
-
'coordinates': tuple([g.coords[0] for g in self.geoms])
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
@property
|
|
91
|
-
def ctypes(self):
|
|
92
|
-
if not self._ctypes_data:
|
|
93
|
-
temp = c_double()
|
|
94
|
-
n = self._ndim
|
|
95
|
-
m = len(self.geoms)
|
|
96
|
-
array_type = c_double * (m * n)
|
|
97
|
-
data = array_type()
|
|
98
|
-
for i in xrange(m):
|
|
99
|
-
g = self.geoms[i]._geom
|
|
100
|
-
cs = lgeos.GEOSGeom_getCoordSeq(g)
|
|
101
|
-
lgeos.GEOSCoordSeq_getX(cs, 0, byref(temp))
|
|
102
|
-
data[n*i] = temp.value
|
|
103
|
-
lgeos.GEOSCoordSeq_getY(cs, 0, byref(temp))
|
|
104
|
-
data[n*i+1] = temp.value
|
|
105
|
-
if n == 3: # TODO: use hasz
|
|
106
|
-
lgeos.GEOSCoordSeq_getZ(cs, 0, byref(temp))
|
|
107
|
-
data[n*i+2] = temp.value
|
|
108
|
-
self._ctypes_data = data
|
|
109
|
-
return self._ctypes_data
|
|
110
|
-
|
|
111
|
-
@property
|
|
112
|
-
def __array_interface__(self):
|
|
113
|
-
"""Provide the Numpy array protocol."""
|
|
114
|
-
return {
|
|
115
|
-
'version': 3,
|
|
116
|
-
'shape': (len(self.geoms), self._ndim),
|
|
117
|
-
'typestr': '<f8',
|
|
118
|
-
'data': self.ctypes,
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
@property
|
|
122
|
-
def coords(self):
|
|
123
|
-
raise NotImplementedError, \
|
|
124
|
-
"Multipart geometries do not themselves provide coordinate sequences"
|
|
125
|
-
|
|
126
|
-
@property
|
|
127
|
-
def geoms(self):
|
|
128
|
-
return GeometrySequence(self, Point)
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
class MultiPointAdapter(MultiPoint):
|
|
132
|
-
|
|
133
|
-
"""Adapts a Python coordinate pair or a numpy array to the multipoint
|
|
134
|
-
interface.
|
|
135
|
-
"""
|
|
136
|
-
|
|
137
|
-
context = None
|
|
138
|
-
|
|
139
|
-
def __init__(self, context):
|
|
140
|
-
self.context = context
|
|
141
|
-
|
|
142
|
-
# Override base class __del__
|
|
143
|
-
def __del__(self):
|
|
144
|
-
pass
|
|
145
|
-
|
|
146
|
-
@property
|
|
147
|
-
def _ndim(self):
|
|
148
|
-
try:
|
|
149
|
-
# From array protocol
|
|
150
|
-
array = self.context.__array_interface__
|
|
151
|
-
n = array['shape'][1]
|
|
152
|
-
assert n == 2 or n == 3
|
|
153
|
-
return n
|
|
154
|
-
except AttributeError:
|
|
155
|
-
# Fall back on list
|
|
156
|
-
return len(self.context[0])
|
|
157
|
-
|
|
158
|
-
@property
|
|
159
|
-
def _geom(self):
|
|
160
|
-
"""Keeps the GEOS geometry in synch with the context."""
|
|
161
|
-
return geos_multipoint_from_py(self.context)[0]
|
|
162
|
-
|
|
163
|
-
@property
|
|
164
|
-
def __array_interface__(self):
|
|
165
|
-
"""Provide the Numpy array protocol."""
|
|
166
|
-
try:
|
|
167
|
-
return self.context.__array_interface__
|
|
168
|
-
except AttributeError:
|
|
169
|
-
return {
|
|
170
|
-
'version': 3,
|
|
171
|
-
'shape': (self._ndim,),
|
|
172
|
-
'typestr': '<f8',
|
|
173
|
-
'data': self.ctypes,
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
def asMultiPoint(context):
|
|
178
|
-
"""Factory for MultiPointAdapter instances."""
|
|
179
|
-
return MultiPointAdapter(context)
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
# Test runner
|
|
183
|
-
def _test():
|
|
184
|
-
import doctest
|
|
185
|
-
doctest.testmod()
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
if __name__ == "__main__":
|
|
189
|
-
_test()
|
|
190
|
-
|
shapely/geometry/multipoint.pyc
DELETED
|
Binary file
|