shapely 1.3.3__cp34-none-win_amd64.whl
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.
- Shapely-1.3.3.data/data/shapely/_geos.pxi +52 -0
- Shapely-1.3.3.dist-info/DESCRIPTION.rst +505 -0
- Shapely-1.3.3.dist-info/METADATA +527 -0
- Shapely-1.3.3.dist-info/RECORD +95 -0
- Shapely-1.3.3.dist-info/WHEEL +5 -0
- Shapely-1.3.3.dist-info/metadata.json +1 -0
- Shapely-1.3.3.dist-info/top_level.txt +1 -0
- shapely/DLLs/geos.dll +0 -0
- shapely/DLLs/geos_c.dll +0 -0
- shapely/__init__.py +1 -0
- shapely/_geos.pxi +52 -0
- shapely/affinity.py +255 -0
- shapely/algorithms/__init__.py +0 -0
- shapely/algorithms/cga.py +16 -0
- shapely/coords.py +206 -0
- shapely/ctypes_declarations.py +455 -0
- shapely/examples/__init__.py +1 -0
- shapely/examples/dissolve.py +53 -0
- shapely/examples/geoms.py +51 -0
- shapely/examples/intersect.py +81 -0
- shapely/examples/world.py +21 -0
- shapely/ftools.py +78 -0
- shapely/geometry/__init__.py +20 -0
- shapely/geometry/base.py +797 -0
- shapely/geometry/collection.py +43 -0
- shapely/geometry/geo.py +75 -0
- shapely/geometry/linestring.py +298 -0
- shapely/geometry/multilinestring.py +156 -0
- shapely/geometry/multipoint.py +213 -0
- shapely/geometry/multipolygon.py +186 -0
- shapely/geometry/point.py +269 -0
- shapely/geometry/polygon.py +504 -0
- shapely/geometry/proxy.py +51 -0
- shapely/geos.py +732 -0
- shapely/impl.py +126 -0
- shapely/iterops.py +55 -0
- shapely/linref.py +26 -0
- shapely/ops.py +234 -0
- shapely/predicates.py +23 -0
- shapely/prepared.py +61 -0
- shapely/speedups/__init__.py +43 -0
- shapely/speedups/_speedups.c +5674 -0
- shapely/speedups/_speedups.pyd +0 -0
- shapely/tests/__init__.py +81 -0
- shapely/tests/binascii_hex.txt +47 -0
- shapely/tests/test_affinity.py +255 -0
- shapely/tests/test_box.py +24 -0
- shapely/tests/test_cga.py +37 -0
- shapely/tests/test_collection.py +29 -0
- shapely/tests/test_delegated.py +34 -0
- shapely/tests/test_dlls.py +20 -0
- shapely/tests/test_doctests.py +36 -0
- shapely/tests/test_emptiness.py +53 -0
- shapely/tests/test_equality.py +29 -0
- shapely/tests/test_geointerface.py +74 -0
- shapely/tests/test_geomseq.py +13 -0
- shapely/tests/test_getitem.py +125 -0
- shapely/tests/test_invalid_geometries.py +30 -0
- shapely/tests/test_iterops.py +47 -0
- shapely/tests/test_linear_referencing.py +72 -0
- shapely/tests/test_linemerge.py +52 -0
- shapely/tests/test_linestring.py +111 -0
- shapely/tests/test_locale.py +56 -0
- shapely/tests/test_mapping.py +13 -0
- shapely/tests/test_multilinestring.py +61 -0
- shapely/tests/test_multipoint.py +73 -0
- shapely/tests/test_multipolygon.py +72 -0
- shapely/tests/test_ndarrays.py +54 -0
- shapely/tests/test_operations.py +70 -0
- shapely/tests/test_operators.py +18 -0
- shapely/tests/test_persist.py +34 -0
- shapely/tests/test_pickle.py +22 -0
- shapely/tests/test_point.py +139 -0
- shapely/tests/test_polygon.py +186 -0
- shapely/tests/test_polygonize.py +49 -0
- shapely/tests/test_predicates.py +34 -0
- shapely/tests/test_prepared.py +31 -0
- shapely/tests/test_products_z.py +17 -0
- shapely/tests/test_singularity.py +19 -0
- shapely/tests/test_speedups.py +39 -0
- shapely/tests/test_styles.py +20 -0
- shapely/tests/test_transform.py +84 -0
- shapely/tests/test_union.py +72 -0
- shapely/tests/test_validation.py +12 -0
- shapely/tests/test_vectorized.py +107 -0
- shapely/tests/test_xy.py +17 -0
- shapely/tests/threading_test.py +40 -0
- shapely/topology.py +60 -0
- shapely/validation.py +8 -0
- shapely/vectorized/__init__.py +3 -0
- shapely/vectorized/_vectorized.c +20816 -0
- shapely/vectorized/_vectorized.pyd +0 -0
- shapely/vectorized/_vectorized.pyx +120 -0
- shapely/wkb.py +37 -0
- shapely/wkt.py +26 -0
|
@@ -0,0 +1,455 @@
|
|
|
1
|
+
'''Prototyping of the GEOS C API
|
|
2
|
+
|
|
3
|
+
See header file: geos-x.y.z/capi/geos_c.h
|
|
4
|
+
'''
|
|
5
|
+
|
|
6
|
+
from ctypes import CFUNCTYPE, POINTER, c_void_p, c_char_p, \
|
|
7
|
+
c_size_t, c_byte, c_char, c_uint, c_int, c_double
|
|
8
|
+
|
|
9
|
+
# Derived pointer types
|
|
10
|
+
c_size_t_p = POINTER(c_size_t)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class allocated_c_char_p(c_char_p):
|
|
14
|
+
'''char pointer return type'''
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
EXCEPTION_HANDLER_FUNCTYPE = CFUNCTYPE(None, c_char_p, c_char_p)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def prototype(lgeos, geos_version):
|
|
21
|
+
'''Protype functions in geos_c.h for different version of GEOS
|
|
22
|
+
|
|
23
|
+
Use the GEOS version, not the C API version.
|
|
24
|
+
'''
|
|
25
|
+
|
|
26
|
+
'''
|
|
27
|
+
Initialization, cleanup, version
|
|
28
|
+
'''
|
|
29
|
+
|
|
30
|
+
lgeos.initGEOS.restype = None
|
|
31
|
+
lgeos.initGEOS.argtypes = [EXCEPTION_HANDLER_FUNCTYPE, EXCEPTION_HANDLER_FUNCTYPE]
|
|
32
|
+
|
|
33
|
+
lgeos.finishGEOS.restype = None
|
|
34
|
+
lgeos.finishGEOS.argtypes = []
|
|
35
|
+
|
|
36
|
+
lgeos.GEOSversion.restype = c_char_p
|
|
37
|
+
lgeos.GEOSversion.argtypes = []
|
|
38
|
+
|
|
39
|
+
'''
|
|
40
|
+
NOTE - These functions are DEPRECATED. Please use the new Reader and
|
|
41
|
+
writer APIS!
|
|
42
|
+
'''
|
|
43
|
+
|
|
44
|
+
lgeos.GEOSGeomFromWKT.restype = c_void_p
|
|
45
|
+
lgeos.GEOSGeomFromWKT.argtypes = [c_char_p]
|
|
46
|
+
|
|
47
|
+
lgeos.GEOSGeomToWKT.restype = allocated_c_char_p
|
|
48
|
+
lgeos.GEOSGeomToWKT.argtypes = [c_void_p]
|
|
49
|
+
|
|
50
|
+
lgeos.GEOS_setWKBOutputDims.restype = c_int
|
|
51
|
+
lgeos.GEOS_setWKBOutputDims.argtypes = [c_int]
|
|
52
|
+
|
|
53
|
+
lgeos.GEOSGeomFromWKB_buf.restype = c_void_p
|
|
54
|
+
lgeos.GEOSGeomFromWKB_buf.argtypes = [c_void_p, c_size_t]
|
|
55
|
+
|
|
56
|
+
lgeos.GEOSGeomToWKB_buf.restype = allocated_c_char_p
|
|
57
|
+
lgeos.GEOSGeomToWKB_buf.argtypes = [c_void_p, c_size_t_p]
|
|
58
|
+
|
|
59
|
+
'''
|
|
60
|
+
Coordinate sequence
|
|
61
|
+
'''
|
|
62
|
+
|
|
63
|
+
lgeos.GEOSCoordSeq_create.restype = c_void_p
|
|
64
|
+
lgeos.GEOSCoordSeq_create.argtypes = [c_uint, c_uint]
|
|
65
|
+
|
|
66
|
+
lgeos.GEOSCoordSeq_clone.restype = c_void_p
|
|
67
|
+
lgeos.GEOSCoordSeq_clone.argtypes = [c_void_p]
|
|
68
|
+
|
|
69
|
+
lgeos.GEOSCoordSeq_destroy.restype = None
|
|
70
|
+
lgeos.GEOSCoordSeq_destroy.argtypes = [c_void_p]
|
|
71
|
+
|
|
72
|
+
lgeos.GEOSCoordSeq_setX.restype = c_int
|
|
73
|
+
lgeos.GEOSCoordSeq_setX.argtypes = [c_void_p, c_uint, c_double]
|
|
74
|
+
|
|
75
|
+
lgeos.GEOSCoordSeq_setY.restype = c_int
|
|
76
|
+
lgeos.GEOSCoordSeq_setY.argtypes = [c_void_p, c_uint, c_double]
|
|
77
|
+
|
|
78
|
+
lgeos.GEOSCoordSeq_setZ.restype = c_int
|
|
79
|
+
lgeos.GEOSCoordSeq_setZ.argtypes = [c_void_p, c_uint, c_double]
|
|
80
|
+
|
|
81
|
+
lgeos.GEOSCoordSeq_setOrdinate.restype = c_int
|
|
82
|
+
lgeos.GEOSCoordSeq_setOrdinate.argtypes = [c_void_p, c_uint, c_uint, c_double]
|
|
83
|
+
|
|
84
|
+
lgeos.GEOSCoordSeq_getX.restype = c_int
|
|
85
|
+
lgeos.GEOSCoordSeq_getX.argtypes = [c_void_p, c_uint, c_void_p]
|
|
86
|
+
|
|
87
|
+
lgeos.GEOSCoordSeq_getY.restype = c_int
|
|
88
|
+
lgeos.GEOSCoordSeq_getY.argtypes = [c_void_p, c_uint, c_void_p]
|
|
89
|
+
|
|
90
|
+
lgeos.GEOSCoordSeq_getZ.restype = c_int
|
|
91
|
+
lgeos.GEOSCoordSeq_getZ.argtypes = [c_void_p, c_uint, c_void_p]
|
|
92
|
+
|
|
93
|
+
lgeos.GEOSCoordSeq_getSize.restype = c_int
|
|
94
|
+
lgeos.GEOSCoordSeq_getSize.argtypes = [c_void_p, c_void_p]
|
|
95
|
+
|
|
96
|
+
lgeos.GEOSCoordSeq_getDimensions.restype = c_int
|
|
97
|
+
lgeos.GEOSCoordSeq_getDimensions.argtypes = [c_void_p, c_void_p]
|
|
98
|
+
|
|
99
|
+
'''
|
|
100
|
+
Linear refeferencing
|
|
101
|
+
'''
|
|
102
|
+
|
|
103
|
+
if geos_version >= (3, 2, 0):
|
|
104
|
+
|
|
105
|
+
lgeos.GEOSProject.restype = c_double
|
|
106
|
+
lgeos.GEOSProject.argtypes = [c_void_p, c_void_p]
|
|
107
|
+
|
|
108
|
+
lgeos.GEOSInterpolate.restype = c_void_p
|
|
109
|
+
lgeos.GEOSInterpolate.argtypes = [c_void_p, c_double]
|
|
110
|
+
|
|
111
|
+
lgeos.GEOSProjectNormalized.restype = c_double
|
|
112
|
+
lgeos.GEOSProjectNormalized.argtypes = [c_void_p, c_void_p]
|
|
113
|
+
|
|
114
|
+
lgeos.GEOSInterpolateNormalized.restype = c_void_p
|
|
115
|
+
lgeos.GEOSInterpolateNormalized.argtypes = [c_void_p, c_double]
|
|
116
|
+
|
|
117
|
+
'''
|
|
118
|
+
Buffer related
|
|
119
|
+
'''
|
|
120
|
+
|
|
121
|
+
lgeos.GEOSBuffer.restype = c_void_p
|
|
122
|
+
lgeos.GEOSBuffer.argtypes = [c_void_p, c_double, c_int]
|
|
123
|
+
|
|
124
|
+
if geos_version >= (3, 2, 0):
|
|
125
|
+
|
|
126
|
+
lgeos.GEOSBufferWithStyle.restype = c_void_p
|
|
127
|
+
lgeos.GEOSBufferWithStyle.argtypes = [c_void_p, c_double, c_int, c_int, c_int, c_double]
|
|
128
|
+
|
|
129
|
+
lgeos.GEOSSingleSidedBuffer.restype = c_void_p
|
|
130
|
+
lgeos.GEOSSingleSidedBuffer.argtypes = [c_void_p, c_double, c_int, c_int, c_double, c_int]
|
|
131
|
+
|
|
132
|
+
'''
|
|
133
|
+
Geometry constructors
|
|
134
|
+
'''
|
|
135
|
+
|
|
136
|
+
lgeos.GEOSGeom_createPoint.restype = c_void_p
|
|
137
|
+
lgeos.GEOSGeom_createPoint.argtypes = [c_void_p]
|
|
138
|
+
|
|
139
|
+
lgeos.GEOSGeom_createLinearRing.restype = c_void_p
|
|
140
|
+
lgeos.GEOSGeom_createLinearRing.argtypes = [c_void_p]
|
|
141
|
+
|
|
142
|
+
lgeos.GEOSGeom_createLineString.restype = c_void_p
|
|
143
|
+
lgeos.GEOSGeom_createLineString.argtypes = [c_void_p]
|
|
144
|
+
|
|
145
|
+
lgeos.GEOSGeom_createPolygon.restype = c_void_p
|
|
146
|
+
lgeos.GEOSGeom_createPolygon.argtypes = [c_void_p, c_void_p, c_uint]
|
|
147
|
+
|
|
148
|
+
lgeos.GEOSGeom_createCollection.restype = c_void_p
|
|
149
|
+
lgeos.GEOSGeom_createCollection.argtypes = [c_int, c_void_p, c_uint]
|
|
150
|
+
|
|
151
|
+
lgeos.GEOSGeom_clone.restype = c_void_p
|
|
152
|
+
lgeos.GEOSGeom_clone.argtypes = [c_void_p]
|
|
153
|
+
|
|
154
|
+
'''
|
|
155
|
+
Memory management
|
|
156
|
+
'''
|
|
157
|
+
|
|
158
|
+
lgeos.GEOSGeom_destroy.restype = None
|
|
159
|
+
lgeos.GEOSGeom_destroy.argtypes = [c_void_p]
|
|
160
|
+
|
|
161
|
+
'''
|
|
162
|
+
Topology operations
|
|
163
|
+
Return NULL on exception
|
|
164
|
+
'''
|
|
165
|
+
|
|
166
|
+
lgeos.GEOSEnvelope.restype = c_void_p
|
|
167
|
+
lgeos.GEOSEnvelope.argtypes = [c_void_p]
|
|
168
|
+
|
|
169
|
+
lgeos.GEOSIntersection.restype = c_void_p
|
|
170
|
+
lgeos.GEOSIntersection.argtypes = [c_void_p, c_void_p]
|
|
171
|
+
|
|
172
|
+
lgeos.GEOSConvexHull.restype = c_void_p
|
|
173
|
+
lgeos.GEOSConvexHull.argtypes = [c_void_p]
|
|
174
|
+
|
|
175
|
+
lgeos.GEOSDifference.restype = c_void_p
|
|
176
|
+
lgeos.GEOSDifference.argtypes = [c_void_p, c_void_p]
|
|
177
|
+
|
|
178
|
+
lgeos.GEOSSymDifference.restype = c_void_p
|
|
179
|
+
lgeos.GEOSSymDifference.argtypes = [c_void_p, c_void_p]
|
|
180
|
+
|
|
181
|
+
lgeos.GEOSBoundary.restype = c_void_p
|
|
182
|
+
lgeos.GEOSBoundary.argtypes = [c_void_p]
|
|
183
|
+
|
|
184
|
+
lgeos.GEOSUnion.restype = c_void_p
|
|
185
|
+
lgeos.GEOSUnion.argtypes = [c_void_p, c_void_p]
|
|
186
|
+
|
|
187
|
+
if geos_version >= (3, 3, 0):
|
|
188
|
+
lgeos.GEOSUnaryUnion.restype = c_void_p
|
|
189
|
+
lgeos.GEOSUnaryUnion.argtypes = [c_void_p]
|
|
190
|
+
|
|
191
|
+
if geos_version >= (3, 1, 0):
|
|
192
|
+
'''deprecated in 3.3.0: use GEOSUnaryUnion instead'''
|
|
193
|
+
lgeos.GEOSUnionCascaded.restype = c_void_p
|
|
194
|
+
lgeos.GEOSUnionCascaded.argtypes = [c_void_p]
|
|
195
|
+
|
|
196
|
+
lgeos.GEOSPointOnSurface.restype = c_void_p
|
|
197
|
+
lgeos.GEOSPointOnSurface.argtypes = [c_void_p]
|
|
198
|
+
|
|
199
|
+
lgeos.GEOSGetCentroid.restype = c_void_p
|
|
200
|
+
lgeos.GEOSGetCentroid.argtypes = [c_void_p]
|
|
201
|
+
|
|
202
|
+
lgeos.GEOSPolygonize.restype = c_void_p
|
|
203
|
+
lgeos.GEOSPolygonize.argtypes = [c_void_p, c_uint]
|
|
204
|
+
|
|
205
|
+
if geos_version >= (3, 3, 0):
|
|
206
|
+
lgeos.GEOSPolygonize_full.restype = c_void_p
|
|
207
|
+
lgeos.GEOSPolygonize_full.argtypes = [c_void_p, c_void_p, c_void_p, c_void_p]
|
|
208
|
+
|
|
209
|
+
lgeos.GEOSLineMerge.restype = c_void_p
|
|
210
|
+
lgeos.GEOSLineMerge.argtypes = [c_void_p]
|
|
211
|
+
|
|
212
|
+
lgeos.GEOSSimplify.restype = c_void_p
|
|
213
|
+
lgeos.GEOSSimplify.argtypes = [c_void_p, c_double]
|
|
214
|
+
|
|
215
|
+
lgeos.GEOSTopologyPreserveSimplify.restype = c_void_p
|
|
216
|
+
lgeos.GEOSTopologyPreserveSimplify.argtypes = [c_void_p, c_double]
|
|
217
|
+
|
|
218
|
+
'''
|
|
219
|
+
Binary predicates
|
|
220
|
+
Return 2 on exception, 1 on true, 0 on false
|
|
221
|
+
'''
|
|
222
|
+
|
|
223
|
+
lgeos.GEOSDisjoint.restype = c_byte
|
|
224
|
+
lgeos.GEOSDisjoint.argtypes = [c_void_p, c_void_p]
|
|
225
|
+
|
|
226
|
+
lgeos.GEOSTouches.restype = c_byte
|
|
227
|
+
lgeos.GEOSTouches.argtypes = [c_void_p, c_void_p]
|
|
228
|
+
|
|
229
|
+
lgeos.GEOSIntersects.restype = c_byte
|
|
230
|
+
lgeos.GEOSIntersects.argtypes = [c_void_p, c_void_p]
|
|
231
|
+
|
|
232
|
+
lgeos.GEOSCrosses.restype = c_byte
|
|
233
|
+
lgeos.GEOSCrosses.argtypes = [c_void_p, c_void_p]
|
|
234
|
+
|
|
235
|
+
lgeos.GEOSWithin.restype = c_byte
|
|
236
|
+
lgeos.GEOSWithin.argtypes = [c_void_p, c_void_p]
|
|
237
|
+
|
|
238
|
+
lgeos.GEOSContains.restype = c_byte
|
|
239
|
+
lgeos.GEOSContains.argtypes = [c_void_p, c_void_p]
|
|
240
|
+
|
|
241
|
+
lgeos.GEOSOverlaps.restype = c_byte
|
|
242
|
+
lgeos.GEOSOverlaps.argtypes = [c_void_p, c_void_p]
|
|
243
|
+
|
|
244
|
+
lgeos.GEOSEquals.restype = c_byte
|
|
245
|
+
lgeos.GEOSEquals.argtypes = [c_void_p, c_void_p]
|
|
246
|
+
|
|
247
|
+
lgeos.GEOSEqualsExact.restype = c_byte
|
|
248
|
+
lgeos.GEOSEqualsExact.argtypes = [c_void_p, c_void_p, c_double]
|
|
249
|
+
|
|
250
|
+
'''
|
|
251
|
+
Unary predicate
|
|
252
|
+
Return 2 on exception, 1 on true, 0 on false
|
|
253
|
+
'''
|
|
254
|
+
|
|
255
|
+
lgeos.GEOSisEmpty.restype = c_byte
|
|
256
|
+
lgeos.GEOSisEmpty.argtypes = [c_void_p]
|
|
257
|
+
|
|
258
|
+
lgeos.GEOSisValid.restype = c_byte
|
|
259
|
+
lgeos.GEOSisValid.argtypes = [c_void_p]
|
|
260
|
+
|
|
261
|
+
if geos_version >= (3, 1, 0):
|
|
262
|
+
lgeos.GEOSisValidReason.restype = allocated_c_char_p
|
|
263
|
+
lgeos.GEOSisValidReason.argtypes = [c_void_p]
|
|
264
|
+
|
|
265
|
+
lgeos.GEOSisSimple.restype = c_byte
|
|
266
|
+
lgeos.GEOSisSimple.argtypes = [c_void_p]
|
|
267
|
+
|
|
268
|
+
lgeos.GEOSisRing.restype = c_byte
|
|
269
|
+
lgeos.GEOSisRing.argtypes = [c_void_p]
|
|
270
|
+
|
|
271
|
+
lgeos.GEOSHasZ.restype = c_byte
|
|
272
|
+
lgeos.GEOSHasZ.argtypes = [c_void_p]
|
|
273
|
+
|
|
274
|
+
'''
|
|
275
|
+
Dimensionally Extended 9 Intersection Model related
|
|
276
|
+
'''
|
|
277
|
+
|
|
278
|
+
lgeos.GEOSRelatePattern.restype = c_char
|
|
279
|
+
lgeos.GEOSRelatePattern.argtypes = [c_void_p, c_void_p, c_char_p]
|
|
280
|
+
|
|
281
|
+
lgeos.GEOSRelate.restype = allocated_c_char_p
|
|
282
|
+
lgeos.GEOSRelate.argtypes = [c_void_p, c_void_p]
|
|
283
|
+
|
|
284
|
+
'''
|
|
285
|
+
Prepared Geometry Binary predicates
|
|
286
|
+
Return 2 on exception, 1 on true, 0 on false
|
|
287
|
+
'''
|
|
288
|
+
|
|
289
|
+
if geos_version >= (3, 1, 0):
|
|
290
|
+
|
|
291
|
+
lgeos.GEOSPrepare.restype = c_void_p
|
|
292
|
+
lgeos.GEOSPrepare.argtypes = [c_void_p]
|
|
293
|
+
|
|
294
|
+
lgeos.GEOSPreparedGeom_destroy.restype = None
|
|
295
|
+
lgeos.GEOSPreparedGeom_destroy.argtypes = [c_void_p]
|
|
296
|
+
|
|
297
|
+
lgeos.GEOSPreparedContains.restype = c_int
|
|
298
|
+
lgeos.GEOSPreparedContains.argtypes = [c_void_p, c_void_p]
|
|
299
|
+
|
|
300
|
+
lgeos.GEOSPreparedContainsProperly.restype = c_int
|
|
301
|
+
lgeos.GEOSPreparedContainsProperly.argtypes = [c_void_p, c_void_p]
|
|
302
|
+
|
|
303
|
+
lgeos.GEOSPreparedCovers.restype = c_int
|
|
304
|
+
lgeos.GEOSPreparedCovers.argtypes = [c_void_p, c_void_p]
|
|
305
|
+
|
|
306
|
+
lgeos.GEOSPreparedIntersects.restype = c_int
|
|
307
|
+
lgeos.GEOSPreparedIntersects.argtypes = [c_void_p, c_void_p]
|
|
308
|
+
|
|
309
|
+
'''
|
|
310
|
+
Geometry info
|
|
311
|
+
'''
|
|
312
|
+
|
|
313
|
+
lgeos.GEOSGeomType.restype = c_char_p
|
|
314
|
+
lgeos.GEOSGeomType.argtypes = [c_void_p]
|
|
315
|
+
|
|
316
|
+
lgeos.GEOSGeomTypeId.restype = c_int
|
|
317
|
+
lgeos.GEOSGeomTypeId.argtypes = [c_void_p]
|
|
318
|
+
|
|
319
|
+
lgeos.GEOSGetSRID.restype = c_int
|
|
320
|
+
lgeos.GEOSGetSRID.argtypes = [c_void_p]
|
|
321
|
+
|
|
322
|
+
lgeos.GEOSSetSRID.restype = None
|
|
323
|
+
lgeos.GEOSSetSRID.argtypes = [c_void_p, c_int]
|
|
324
|
+
|
|
325
|
+
lgeos.GEOSGetNumGeometries.restype = c_int
|
|
326
|
+
lgeos.GEOSGetNumGeometries.argtypes = [c_void_p]
|
|
327
|
+
|
|
328
|
+
lgeos.GEOSGetGeometryN.restype = c_void_p
|
|
329
|
+
lgeos.GEOSGetGeometryN.argtypes = [c_void_p, c_int]
|
|
330
|
+
|
|
331
|
+
lgeos.GEOSGetNumInteriorRings.restype = c_int
|
|
332
|
+
lgeos.GEOSGetNumInteriorRings.argtypes = [c_void_p]
|
|
333
|
+
|
|
334
|
+
lgeos.GEOSGetInteriorRingN.restype = c_void_p
|
|
335
|
+
lgeos.GEOSGetInteriorRingN.argtypes = [c_void_p, c_int]
|
|
336
|
+
|
|
337
|
+
lgeos.GEOSGetExteriorRing.restype = c_void_p
|
|
338
|
+
lgeos.GEOSGetExteriorRing.argtypes = [c_void_p]
|
|
339
|
+
|
|
340
|
+
lgeos.GEOSGetNumCoordinates.restype = c_int
|
|
341
|
+
lgeos.GEOSGetNumCoordinates.argtypes = [c_void_p]
|
|
342
|
+
|
|
343
|
+
lgeos.GEOSGeom_getCoordSeq.restype = c_void_p
|
|
344
|
+
lgeos.GEOSGeom_getCoordSeq.argtypes = [c_void_p]
|
|
345
|
+
|
|
346
|
+
lgeos.GEOSGeom_getDimensions.restype = c_int
|
|
347
|
+
lgeos.GEOSGeom_getDimensions.argtypes = [c_void_p]
|
|
348
|
+
|
|
349
|
+
'''
|
|
350
|
+
Misc functions
|
|
351
|
+
'''
|
|
352
|
+
|
|
353
|
+
lgeos.GEOSArea.restype = c_double
|
|
354
|
+
lgeos.GEOSArea.argtypes = [c_void_p, c_void_p]
|
|
355
|
+
|
|
356
|
+
lgeos.GEOSLength.restype = c_int
|
|
357
|
+
lgeos.GEOSLength.argtypes = [c_void_p, c_void_p]
|
|
358
|
+
|
|
359
|
+
lgeos.GEOSDistance.restype = c_int
|
|
360
|
+
lgeos.GEOSDistance.argtypes = [c_void_p, c_void_p, c_void_p]
|
|
361
|
+
|
|
362
|
+
'''
|
|
363
|
+
Reader and Writer APIs
|
|
364
|
+
'''
|
|
365
|
+
|
|
366
|
+
'''WKT Reader'''
|
|
367
|
+
lgeos.GEOSWKTReader_create.restype = c_void_p
|
|
368
|
+
lgeos.GEOSWKTReader_create.argtypes = []
|
|
369
|
+
|
|
370
|
+
lgeos.GEOSWKTReader_destroy.restype = None
|
|
371
|
+
lgeos.GEOSWKTReader_destroy.argtypes = [c_void_p]
|
|
372
|
+
|
|
373
|
+
lgeos.GEOSWKTReader_read.restype = c_void_p
|
|
374
|
+
lgeos.GEOSWKTReader_read.argtypes = [c_void_p, c_char_p]
|
|
375
|
+
|
|
376
|
+
'''WKT Writer'''
|
|
377
|
+
lgeos.GEOSWKTWriter_create.restype = c_void_p
|
|
378
|
+
lgeos.GEOSWKTWriter_create.argtypes = []
|
|
379
|
+
|
|
380
|
+
lgeos.GEOSWKTWriter_destroy.restype = None
|
|
381
|
+
lgeos.GEOSWKTWriter_destroy.argtypes = [c_void_p]
|
|
382
|
+
|
|
383
|
+
lgeos.GEOSWKTWriter_write.restype = allocated_c_char_p
|
|
384
|
+
lgeos.GEOSWKTWriter_write.argtypes = [c_void_p, c_void_p]
|
|
385
|
+
|
|
386
|
+
if geos_version >= (3, 3, 0):
|
|
387
|
+
|
|
388
|
+
lgeos.GEOSWKTWriter_setTrim.restype = None
|
|
389
|
+
lgeos.GEOSWKTWriter_setTrim.argtypes = [c_void_p, c_int]
|
|
390
|
+
|
|
391
|
+
lgeos.GEOSWKTWriter_setRoundingPrecision.restype = None
|
|
392
|
+
lgeos.GEOSWKTWriter_setRoundingPrecision.argtypes = [c_void_p, c_int]
|
|
393
|
+
|
|
394
|
+
lgeos.GEOSWKTWriter_setOutputDimension.restype = None
|
|
395
|
+
lgeos.GEOSWKTWriter_setOutputDimension.argtypes = [c_void_p, c_int]
|
|
396
|
+
|
|
397
|
+
lgeos.GEOSWKTWriter_getOutputDimension.restype = c_int
|
|
398
|
+
lgeos.GEOSWKTWriter_getOutputDimension.argtypes = [c_void_p]
|
|
399
|
+
|
|
400
|
+
lgeos.GEOSWKTWriter_setOld3D.restype = None
|
|
401
|
+
lgeos.GEOSWKTWriter_setOld3D.argtypes = [c_void_p, c_int]
|
|
402
|
+
|
|
403
|
+
'''WKB Reader'''
|
|
404
|
+
lgeos.GEOSWKBReader_create.restype = c_void_p
|
|
405
|
+
lgeos.GEOSWKBReader_create.argtypes = []
|
|
406
|
+
|
|
407
|
+
lgeos.GEOSWKBReader_destroy.restype = None
|
|
408
|
+
lgeos.GEOSWKBReader_destroy.argtypes = [c_void_p]
|
|
409
|
+
|
|
410
|
+
lgeos.GEOSWKBReader_read.restype = c_void_p
|
|
411
|
+
lgeos.GEOSWKBReader_read.argtypes = [c_void_p, c_char_p, c_size_t]
|
|
412
|
+
|
|
413
|
+
lgeos.GEOSWKBReader_readHEX.restype = c_void_p
|
|
414
|
+
lgeos.GEOSWKBReader_readHEX.argtypes = [c_void_p, c_char_p, c_size_t]
|
|
415
|
+
|
|
416
|
+
'''WKB Writer'''
|
|
417
|
+
lgeos.GEOSWKBWriter_create.restype = c_void_p
|
|
418
|
+
lgeos.GEOSWKBWriter_create.argtypes = []
|
|
419
|
+
|
|
420
|
+
lgeos.GEOSWKBWriter_destroy.restype = None
|
|
421
|
+
lgeos.GEOSWKBWriter_destroy.argtypes = [c_void_p]
|
|
422
|
+
|
|
423
|
+
lgeos.GEOSWKBWriter_write.restype = allocated_c_char_p
|
|
424
|
+
lgeos.GEOSWKBWriter_write.argtypes = [c_void_p, c_void_p, c_size_t_p]
|
|
425
|
+
|
|
426
|
+
lgeos.GEOSWKBWriter_writeHEX.restype = allocated_c_char_p
|
|
427
|
+
lgeos.GEOSWKBWriter_writeHEX.argtypes = [c_void_p, c_void_p, c_size_t_p]
|
|
428
|
+
|
|
429
|
+
lgeos.GEOSWKBWriter_getOutputDimension.restype = c_int
|
|
430
|
+
lgeos.GEOSWKBWriter_getOutputDimension.argtypes = [c_void_p]
|
|
431
|
+
|
|
432
|
+
lgeos.GEOSWKBWriter_setOutputDimension.restype = None
|
|
433
|
+
lgeos.GEOSWKBWriter_setOutputDimension.argtypes = [c_void_p, c_int]
|
|
434
|
+
|
|
435
|
+
lgeos.GEOSWKBWriter_getByteOrder.restype = c_int
|
|
436
|
+
lgeos.GEOSWKBWriter_getByteOrder.argtypes = [c_void_p]
|
|
437
|
+
|
|
438
|
+
lgeos.GEOSWKBWriter_setByteOrder.restype = None
|
|
439
|
+
lgeos.GEOSWKBWriter_setByteOrder.argtypes = [c_void_p, c_int]
|
|
440
|
+
|
|
441
|
+
lgeos.GEOSWKBWriter_getIncludeSRID.restype = c_int
|
|
442
|
+
lgeos.GEOSWKBWriter_getIncludeSRID.argtypes = [c_void_p]
|
|
443
|
+
|
|
444
|
+
lgeos.GEOSWKBWriter_setIncludeSRID.restype = None
|
|
445
|
+
lgeos.GEOSWKBWriter_setIncludeSRID.argtypes = [c_void_p, c_int]
|
|
446
|
+
|
|
447
|
+
if geos_version >= (3, 1, 1):
|
|
448
|
+
|
|
449
|
+
'''
|
|
450
|
+
Free buffers returned by stuff like GEOSWKBWriter_write(),
|
|
451
|
+
GEOSWKBWriter_writeHEX() and GEOSWKTWriter_write()
|
|
452
|
+
'''
|
|
453
|
+
|
|
454
|
+
lgeos.GEOSFree.restype = None
|
|
455
|
+
lgeos.GEOSFree.argtypes = [c_void_p]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Examples module
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# dissolve.py
|
|
2
|
+
#
|
|
3
|
+
# Demonstrate how Shapely can be used to build up a collection of patches by
|
|
4
|
+
# dissolving circular regions and how Shapely supports plotting of the results.
|
|
5
|
+
|
|
6
|
+
from functools import partial
|
|
7
|
+
import random
|
|
8
|
+
|
|
9
|
+
import pylab
|
|
10
|
+
|
|
11
|
+
from shapely.geometry import Point
|
|
12
|
+
from shapely.ops import cascaded_union
|
|
13
|
+
|
|
14
|
+
# Use a partial function to make 100 points uniformly distributed in a 40x40
|
|
15
|
+
# box centered on 0,0.
|
|
16
|
+
r = partial(random.uniform, -20.0, 20.0)
|
|
17
|
+
points = [Point(r(), r()) for i in range(100)]
|
|
18
|
+
|
|
19
|
+
# Buffer the points, producing 100 polygon spots
|
|
20
|
+
spots = [p.buffer(2.5) for p in points]
|
|
21
|
+
|
|
22
|
+
# Perform a cascaded union of the polygon spots, dissolving them into a
|
|
23
|
+
# collection of polygon patches
|
|
24
|
+
patches = cascaded_union(spots)
|
|
25
|
+
|
|
26
|
+
if __name__ == "__main__":
|
|
27
|
+
# Illustrate the results using matplotlib's pylab interface
|
|
28
|
+
pylab.figure(num=None, figsize=(4, 4), dpi=180)
|
|
29
|
+
|
|
30
|
+
for patch in patches.geoms:
|
|
31
|
+
assert patch.geom_type in ['Polygon']
|
|
32
|
+
assert patch.is_valid
|
|
33
|
+
|
|
34
|
+
# Fill and outline each patch
|
|
35
|
+
x, y = patch.exterior.xy
|
|
36
|
+
pylab.fill(x, y, color='#cccccc', aa=True)
|
|
37
|
+
pylab.plot(x, y, color='#666666', aa=True, lw=1.0)
|
|
38
|
+
|
|
39
|
+
# Do the same for the holes of the patch
|
|
40
|
+
for hole in patch.interiors:
|
|
41
|
+
x, y = hole.xy
|
|
42
|
+
pylab.fill(x, y, color='#ffffff', aa=True)
|
|
43
|
+
pylab.plot(x, y, color='#999999', aa=True, lw=1.0)
|
|
44
|
+
|
|
45
|
+
# Plot the original points
|
|
46
|
+
pylab.plot([p.x for p in points], [p.y for p in points], 'b,', alpha=0.75)
|
|
47
|
+
|
|
48
|
+
# Write the number of patches and the total patch area to the figure
|
|
49
|
+
pylab.text(-25, 25,
|
|
50
|
+
"Patches: %d, total area: %.2f" % (len(patches.geoms), patches.area))
|
|
51
|
+
|
|
52
|
+
pylab.savefig('dissolve.png')
|
|
53
|
+
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
from numpy import asarray
|
|
2
|
+
import pylab
|
|
3
|
+
from shapely.geometry import Point, LineString, Polygon
|
|
4
|
+
|
|
5
|
+
polygon = Polygon(((-1.0, -1.0), (-1.0, 1.0), (1.0, 1.0), (1.0, -1.0)))
|
|
6
|
+
|
|
7
|
+
point_r = Point(-1.5, 1.2)
|
|
8
|
+
point_g = Point(-1.0, 1.0)
|
|
9
|
+
point_b = Point(-0.5, 0.5)
|
|
10
|
+
|
|
11
|
+
line_r = LineString(((-0.5, 0.5), (0.5, 0.5)))
|
|
12
|
+
line_g = LineString(((1.0, -1.0), (1.8, 0.5)))
|
|
13
|
+
line_b = LineString(((-1.8, -1.2), (1.8, 0.5)))
|
|
14
|
+
|
|
15
|
+
def plot_point(g, o, l):
|
|
16
|
+
pylab.plot([g.x], [g.y], o, label=l)
|
|
17
|
+
|
|
18
|
+
def plot_line(g, o):
|
|
19
|
+
a = asarray(g)
|
|
20
|
+
pylab.plot(a[:,0], a[:,1], o)
|
|
21
|
+
|
|
22
|
+
def fill_polygon(g, o):
|
|
23
|
+
a = asarray(g.exterior)
|
|
24
|
+
pylab.fill(a[:,0], a[:,1], o, alpha=0.5)
|
|
25
|
+
|
|
26
|
+
def fill_multipolygon(g, o):
|
|
27
|
+
for g in g.geoms:
|
|
28
|
+
fill_polygon(g, o)
|
|
29
|
+
|
|
30
|
+
if __name__ == "__main__":
|
|
31
|
+
from numpy import asarray
|
|
32
|
+
import pylab
|
|
33
|
+
|
|
34
|
+
fig = pylab.figure(1, figsize=(4, 3), dpi=150)
|
|
35
|
+
#pylab.axis([-2.0, 2.0, -1.5, 1.5])
|
|
36
|
+
pylab.axis('tight')
|
|
37
|
+
|
|
38
|
+
a = asarray(polygon.exterior)
|
|
39
|
+
pylab.fill(a[:,0], a[:,1], 'c')
|
|
40
|
+
|
|
41
|
+
plot_point(point_r, 'ro', 'b')
|
|
42
|
+
plot_point(point_g, 'go', 'c')
|
|
43
|
+
plot_point(point_b, 'bo', 'd')
|
|
44
|
+
|
|
45
|
+
plot_line(line_r, 'r')
|
|
46
|
+
plot_line(line_g, 'g')
|
|
47
|
+
plot_line(line_b, 'b')
|
|
48
|
+
|
|
49
|
+
pylab.show()
|
|
50
|
+
|
|
51
|
+
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
# intersect.py
|
|
2
|
+
#
|
|
3
|
+
# Demonstrate how Shapely can be used to analyze and plot the intersection of
|
|
4
|
+
# a trajectory and regions in space.
|
|
5
|
+
|
|
6
|
+
from functools import partial
|
|
7
|
+
import random
|
|
8
|
+
|
|
9
|
+
import pylab
|
|
10
|
+
|
|
11
|
+
from shapely.geometry import LineString, Point
|
|
12
|
+
from shapely.ops import cascaded_union
|
|
13
|
+
|
|
14
|
+
# Build patches as in dissolved.py
|
|
15
|
+
r = partial(random.uniform, -20.0, 20.0)
|
|
16
|
+
points = [Point(r(), r()) for i in range(100)]
|
|
17
|
+
spots = [p.buffer(2.5) for p in points]
|
|
18
|
+
patches = cascaded_union(spots)
|
|
19
|
+
|
|
20
|
+
# Represent the following geolocation parameters
|
|
21
|
+
#
|
|
22
|
+
# initial position: -25, -25
|
|
23
|
+
# heading: 45.0
|
|
24
|
+
# speed: 50*sqrt(2)
|
|
25
|
+
#
|
|
26
|
+
# as a line
|
|
27
|
+
vector = LineString(((-25.0, -25.0), (25.0, 25.0)))
|
|
28
|
+
|
|
29
|
+
# Find intercepted and missed patches. List the former so we can count them
|
|
30
|
+
# later
|
|
31
|
+
intercepts = [patch for patch in patches.geoms if vector.intersects(patch)]
|
|
32
|
+
misses = (patch for patch in patches.geoms if not vector.intersects(patch))
|
|
33
|
+
|
|
34
|
+
# Plot the intersection
|
|
35
|
+
intersection = vector.intersection(patches)
|
|
36
|
+
assert intersection.geom_type in ['MultiLineString']
|
|
37
|
+
|
|
38
|
+
if __name__ == "__main__":
|
|
39
|
+
# Illustrate the results using matplotlib's pylab interface
|
|
40
|
+
pylab.figure(num=None, figsize=(4, 4), dpi=180)
|
|
41
|
+
|
|
42
|
+
# Plot the misses
|
|
43
|
+
for spot in misses:
|
|
44
|
+
x, y = spot.exterior.xy
|
|
45
|
+
pylab.fill(x, y, color='#cccccc', aa=True)
|
|
46
|
+
pylab.plot(x, y, color='#999999', aa=True, lw=1.0)
|
|
47
|
+
|
|
48
|
+
# Do the same for the holes of the patch
|
|
49
|
+
for hole in spot.interiors:
|
|
50
|
+
x, y = hole.xy
|
|
51
|
+
pylab.fill(x, y, color='#ffffff', aa=True)
|
|
52
|
+
pylab.plot(x, y, color='#999999', aa=True, lw=1.0)
|
|
53
|
+
|
|
54
|
+
# Plot the intercepts
|
|
55
|
+
for spot in intercepts:
|
|
56
|
+
x, y = spot.exterior.xy
|
|
57
|
+
pylab.fill(x, y, color='red', alpha=0.25, aa=True)
|
|
58
|
+
pylab.plot(x, y, color='red', alpha=0.5, aa=True, lw=1.0)
|
|
59
|
+
|
|
60
|
+
# Do the same for the holes of the patch
|
|
61
|
+
for hole in spot.interiors:
|
|
62
|
+
x, y = hole.xy
|
|
63
|
+
pylab.fill(x, y, color='#ffffff', aa=True)
|
|
64
|
+
pylab.plot(x, y, color='red', alpha=0.5, aa=True, lw=1.0)
|
|
65
|
+
|
|
66
|
+
# Draw the projected trajectory
|
|
67
|
+
pylab.arrow(-25, -25, 50, 50, color='#999999', aa=True,
|
|
68
|
+
head_width=1.0, head_length=1.0)
|
|
69
|
+
|
|
70
|
+
for segment in intersection.geoms:
|
|
71
|
+
x, y = segment.xy
|
|
72
|
+
pylab.plot(x, y, color='red', aa=True, lw=1.5)
|
|
73
|
+
|
|
74
|
+
# Write the number of patches and the total patch area to the figure
|
|
75
|
+
pylab.text(-28, 25,
|
|
76
|
+
"Patches: %d/%d (%d), total length: %.1f" \
|
|
77
|
+
% (len(intercepts), len(patches.geoms),
|
|
78
|
+
len(intersection.geoms), intersection.length))
|
|
79
|
+
|
|
80
|
+
pylab.savefig('intersect.png')
|
|
81
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import ogr
|
|
2
|
+
import pylab
|
|
3
|
+
from numpy import asarray
|
|
4
|
+
|
|
5
|
+
from shapely.wkb import loads
|
|
6
|
+
|
|
7
|
+
source = ogr.Open("/var/gis/data/world/world_borders.shp")
|
|
8
|
+
borders = source.GetLayerByName("world_borders")
|
|
9
|
+
|
|
10
|
+
fig = pylab.figure(1, figsize=(4,2), dpi=300)
|
|
11
|
+
|
|
12
|
+
while 1:
|
|
13
|
+
feature = borders.GetNextFeature()
|
|
14
|
+
if not feature:
|
|
15
|
+
break
|
|
16
|
+
|
|
17
|
+
geom = loads(feature.GetGeometryRef().ExportToWkb())
|
|
18
|
+
a = asarray(geom)
|
|
19
|
+
pylab.plot(a[:,0], a[:,1])
|
|
20
|
+
|
|
21
|
+
pylab.show()
|