shapely 1.2.8__py2.7-win-amd64.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.
- DLLs/geos.dll +0 -0
- DLLs/geos_c.dll +0 -0
- EGG-INFO/PKG-INFO +173 -0
- EGG-INFO/not-zip-safe +1 -0
- EGG-INFO/scripts/dissolve.py +53 -0
- EGG-INFO/scripts/intersect.py +81 -0
- shapely/__init__.py +1 -0
- shapely/__init__.pyc +0 -0
- shapely/coords.py +167 -0
- shapely/coords.pyc +0 -0
- shapely/ctypes_declarations.py +279 -0
- shapely/ctypes_declarations.pyc +0 -0
- shapely/ftools.py +78 -0
- shapely/ftools.pyc +0 -0
- shapely/geometry/__init__.py +20 -0
- shapely/geometry/__init__.pyc +0 -0
- shapely/geometry/base.py +595 -0
- shapely/geometry/base.pyc +0 -0
- shapely/geometry/collection.py +43 -0
- shapely/geometry/collection.pyc +0 -0
- shapely/geometry/geo.py +68 -0
- shapely/geometry/geo.pyc +0 -0
- shapely/geometry/linestring.py +259 -0
- shapely/geometry/linestring.pyc +0 -0
- shapely/geometry/multilinestring.py +133 -0
- shapely/geometry/multilinestring.pyc +0 -0
- shapely/geometry/multipoint.py +180 -0
- shapely/geometry/multipoint.pyc +0 -0
- shapely/geometry/multipolygon.py +154 -0
- shapely/geometry/multipolygon.pyc +0 -0
- shapely/geometry/point.py +241 -0
- shapely/geometry/point.pyc +0 -0
- shapely/geometry/polygon.py +449 -0
- shapely/geometry/polygon.pyc +0 -0
- shapely/geometry/proxy.py +54 -0
- shapely/geometry/proxy.pyc +0 -0
- shapely/geos.py +373 -0
- shapely/geos.pyc +0 -0
- shapely/impl.py +119 -0
- shapely/impl.pyc +0 -0
- shapely/iterops.py +53 -0
- shapely/iterops.pyc +0 -0
- shapely/linref.py +26 -0
- shapely/linref.pyc +0 -0
- shapely/ops.py +87 -0
- shapely/ops.pyc +0 -0
- shapely/predicates.py +24 -0
- shapely/predicates.pyc +0 -0
- shapely/prepared.py +58 -0
- shapely/prepared.pyc +0 -0
- shapely/topology.py +62 -0
- shapely/topology.pyc +0 -0
- shapely/validation.py +7 -0
- shapely/validation.pyc +0 -0
- shapely/wkb.py +39 -0
- shapely/wkb.pyc +0 -0
- shapely/wkt.py +34 -0
- shapely/wkt.pyc +0 -0
DLLs/geos.dll
ADDED
|
Binary file
|
DLLs/geos_c.dll
ADDED
|
Binary file
|
EGG-INFO/PKG-INFO
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
Metadata-Version: 1.0
|
|
2
|
+
Name: Shapely
|
|
3
|
+
Version: 1.2.8
|
|
4
|
+
Summary: Geometric objects, predicates, and operations
|
|
5
|
+
Home-page: http://trac.gispython.org/lab/wiki/Shapely
|
|
6
|
+
Author: Sean Gillies
|
|
7
|
+
Author-email: sean.gillies@gmail.com
|
|
8
|
+
License: BSD
|
|
9
|
+
Description: =======
|
|
10
|
+
Shapely
|
|
11
|
+
=======
|
|
12
|
+
|
|
13
|
+
.. image:: http://farm3.static.flickr.com/2738/4511827859_b5822043b7_o_d.png
|
|
14
|
+
:width: 800
|
|
15
|
+
:height: 400
|
|
16
|
+
|
|
17
|
+
Shapely is a BSD-licensed Python package for manipulation and analysis of
|
|
18
|
+
planar geometric objects. It is not concerned with data formats or coordinate
|
|
19
|
+
systems. It is based on the widely deployed GEOS_ (the engine of PostGIS_) and
|
|
20
|
+
JTS_ (from which GEOS is ported) libraries. This C dependency is traded for the
|
|
21
|
+
ability to execute with blazing speed.
|
|
22
|
+
|
|
23
|
+
In a nutshell: Shapely lets you do PostGIS-ish stuff outside the context of a
|
|
24
|
+
database using idiomatic Python. For more details, see:
|
|
25
|
+
|
|
26
|
+
* Shapely wiki_
|
|
27
|
+
* Shapely manual_
|
|
28
|
+
* Shapely `example apps`_
|
|
29
|
+
|
|
30
|
+
Dependencies
|
|
31
|
+
------------
|
|
32
|
+
|
|
33
|
+
Shapely 1.2 depends on:
|
|
34
|
+
|
|
35
|
+
* Python >=2.5,<3
|
|
36
|
+
* libgeos_c >=3.1 (3.0 and below have not been tested, YMMV)
|
|
37
|
+
|
|
38
|
+
Installation
|
|
39
|
+
------------
|
|
40
|
+
|
|
41
|
+
Windows users should use the executable installer, which contains the required
|
|
42
|
+
GEOS DLL. Other users should acquire libgeos_c by any means, make sure that it
|
|
43
|
+
is on the system library path, and install from the Python package index::
|
|
44
|
+
|
|
45
|
+
$ pip install Shapely
|
|
46
|
+
|
|
47
|
+
or from a source distribution with the setup script::
|
|
48
|
+
|
|
49
|
+
$ python setup.py install
|
|
50
|
+
|
|
51
|
+
Usage
|
|
52
|
+
-----
|
|
53
|
+
|
|
54
|
+
Here is the canonical example of building an approximately circular patch by
|
|
55
|
+
buffering a point::
|
|
56
|
+
|
|
57
|
+
>>> from shapely.geometry import Point
|
|
58
|
+
>>> patch = Point(0.0, 0.0).buffer(10.0)
|
|
59
|
+
>>> patch
|
|
60
|
+
<shapely.geometry.polygon.Polygon object at 0x...>
|
|
61
|
+
>>> patch.area
|
|
62
|
+
313.65484905459385
|
|
63
|
+
|
|
64
|
+
See the manual_ for comprehensive usage snippets and the dissolve.py and
|
|
65
|
+
intersect.py `example apps`_.
|
|
66
|
+
|
|
67
|
+
Integration
|
|
68
|
+
-----------
|
|
69
|
+
|
|
70
|
+
Shapely does not read or write data files, but it can serialize and deserialize
|
|
71
|
+
using several well known formats and protocols. The shapely.wkb and shapely.wkt
|
|
72
|
+
modules provide dumpers and loaders inspired by Python's pickle module.::
|
|
73
|
+
|
|
74
|
+
>>> from shapely.wkt import dumps, loads
|
|
75
|
+
>>> dumps(loads('POINT (0 0)'))
|
|
76
|
+
'POINT (0.0000000000000000 0.0000000000000000)'
|
|
77
|
+
|
|
78
|
+
All linear objects, such as the rings of a polygon (like ``patch`` above),
|
|
79
|
+
provide the Numpy array interface.::
|
|
80
|
+
|
|
81
|
+
>>> from numpy import asarray
|
|
82
|
+
>>> ag = asarray(patch.exterior)
|
|
83
|
+
>>> ag
|
|
84
|
+
array([[ 1.00000000e+01, 0.00000000e+00],
|
|
85
|
+
[ 9.95184727e+00, -9.80171403e-01],
|
|
86
|
+
[ 9.80785280e+00, -1.95090322e+00],
|
|
87
|
+
...
|
|
88
|
+
[ 1.00000000e+01, 0.00000000e+00]])
|
|
89
|
+
|
|
90
|
+
That yields a numpy array of [x, y] arrays. This is not always exactly what one
|
|
91
|
+
wants for plotting shapes with Matplotlib, so Shapely 1.2 adds a `xy` property
|
|
92
|
+
for getting separate arrays of coordinate x and y values.::
|
|
93
|
+
|
|
94
|
+
>>> x, y = patch.exterior.xy
|
|
95
|
+
>>> ax = asarray(x)
|
|
96
|
+
>>> ax
|
|
97
|
+
array([ 1.00000000e+01, 9.95184727e+00, 9.80785280e+00, ...])
|
|
98
|
+
|
|
99
|
+
Numpy arrays can also be adapted to Shapely linestrings::
|
|
100
|
+
|
|
101
|
+
>>> from shapely.geometry import asLineString
|
|
102
|
+
>>> asLineString(ag).length
|
|
103
|
+
62.806623139095073
|
|
104
|
+
>>> asLineString(ag).wkt
|
|
105
|
+
'LINESTRING (10.0000000000000000 0.0000000000000000, ...)'
|
|
106
|
+
|
|
107
|
+
Testing
|
|
108
|
+
-------
|
|
109
|
+
|
|
110
|
+
Shapely uses a Zope-stye suite of unittests and doctests, excercised via
|
|
111
|
+
setup.py.::
|
|
112
|
+
|
|
113
|
+
$ python setup.py test
|
|
114
|
+
|
|
115
|
+
Nosetests won't run the tests properly; Zope doctest suites are not currently
|
|
116
|
+
supported well by nose.
|
|
117
|
+
|
|
118
|
+
Support
|
|
119
|
+
-------
|
|
120
|
+
|
|
121
|
+
For current information about this project, see the wiki_.
|
|
122
|
+
|
|
123
|
+
If you have questions, please consider joining our community list:
|
|
124
|
+
|
|
125
|
+
http://trac.gispython.org/projects/PCL/wiki/CommunityList
|
|
126
|
+
|
|
127
|
+
Credits
|
|
128
|
+
-------
|
|
129
|
+
|
|
130
|
+
Shapely is written by:
|
|
131
|
+
|
|
132
|
+
* Sean Gillies
|
|
133
|
+
* Aron Bierbaum
|
|
134
|
+
* Kai Lautaportti
|
|
135
|
+
|
|
136
|
+
Patches contributed by:
|
|
137
|
+
|
|
138
|
+
* Howard Butler
|
|
139
|
+
* Fr |eaigue| d |eaigue| ric Junod
|
|
140
|
+
* Eric Lemoine
|
|
141
|
+
* Jonathan Tartley
|
|
142
|
+
* Kristian Thy
|
|
143
|
+
* Oliver Tonnhofer
|
|
144
|
+
|
|
145
|
+
Additional help from:
|
|
146
|
+
|
|
147
|
+
* Justin Bronn (GeoDjango) for ctypes inspiration
|
|
148
|
+
* Martin Davis (JTS)
|
|
149
|
+
* Jaakko Salli for the Windows distributions
|
|
150
|
+
* Sandro Santilli, Mateusz Loskot, Paul Ramsey, et al (GEOS Project)
|
|
151
|
+
|
|
152
|
+
Major portions of this work were supported by a grant (for Pleiades_) from the
|
|
153
|
+
U.S. National Endowment for the Humanities (http://www.neh.gov).
|
|
154
|
+
|
|
155
|
+
.. _JTS: http://www.vividsolutions.com/jts/jtshome.htm
|
|
156
|
+
.. _PostGIS: http://postgis.org
|
|
157
|
+
.. _GEOS: http://trac.osgeo.org/geos/
|
|
158
|
+
.. _example apps: http://trac.gispython.org/lab/wiki/Examples
|
|
159
|
+
.. _wiki: http://trac.gispython.org/lab/wiki/Shapely
|
|
160
|
+
.. _manual: http://gispython.org/shapely/docs/1.2
|
|
161
|
+
.. |eaigue| unicode:: U+00E9
|
|
162
|
+
:trim:
|
|
163
|
+
.. _Pleiades: http://pleiades.stoa.org
|
|
164
|
+
|
|
165
|
+
Keywords: geometry topology gis
|
|
166
|
+
Platform: UNKNOWN
|
|
167
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
168
|
+
Classifier: Intended Audience :: Developers
|
|
169
|
+
Classifier: Intended Audience :: Science/Research
|
|
170
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
171
|
+
Classifier: Operating System :: OS Independent
|
|
172
|
+
Classifier: Programming Language :: Python
|
|
173
|
+
Classifier: Topic :: Scientific/Engineering :: GIS
|
EGG-INFO/not-zip-safe
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -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,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
|
+
|
shapely/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# package
|
shapely/__init__.pyc
ADDED
|
Binary file
|
shapely/coords.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""Coordinate sequence utilities
|
|
2
|
+
"""
|
|
3
|
+
|
|
4
|
+
from array import array
|
|
5
|
+
from ctypes import string_at, byref, c_char_p, c_double, c_void_p
|
|
6
|
+
from ctypes import c_int, c_size_t, c_uint
|
|
7
|
+
import sys
|
|
8
|
+
|
|
9
|
+
from shapely.geos import lgeos
|
|
10
|
+
from shapely.topology import Validating
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CoordinateSequence(object):
|
|
14
|
+
"""
|
|
15
|
+
Iterative access to coordinate tuples from the parent geometry's coordinate
|
|
16
|
+
sequence.
|
|
17
|
+
|
|
18
|
+
Example:
|
|
19
|
+
|
|
20
|
+
>>> from shapely.wkt import loads
|
|
21
|
+
>>> g = loads('POINT (0.0 0.0)')
|
|
22
|
+
>>> list(g.coords)
|
|
23
|
+
[(0.0, 0.0)]
|
|
24
|
+
|
|
25
|
+
"""
|
|
26
|
+
|
|
27
|
+
# Attributes
|
|
28
|
+
# ----------
|
|
29
|
+
# _cseq : c_void_p
|
|
30
|
+
# Ctypes pointer to GEOS coordinate sequence
|
|
31
|
+
# _ndim : int
|
|
32
|
+
# Number of dimensions (2 or 3, generally)
|
|
33
|
+
# __p__ : object
|
|
34
|
+
# Parent (Shapely) geometry
|
|
35
|
+
_cseq = None
|
|
36
|
+
_ndim = None
|
|
37
|
+
__p__ = None
|
|
38
|
+
|
|
39
|
+
def __init__(self, parent):
|
|
40
|
+
self.__p__ = parent
|
|
41
|
+
|
|
42
|
+
def _update(self):
|
|
43
|
+
self._ndim = self.__p__._ndim
|
|
44
|
+
self._cseq = lgeos.GEOSGeom_getCoordSeq(self.__p__._geom)
|
|
45
|
+
|
|
46
|
+
def __len__(self):
|
|
47
|
+
self._update()
|
|
48
|
+
cs_len = c_uint(0)
|
|
49
|
+
lgeos.GEOSCoordSeq_getSize(self._cseq, byref(cs_len))
|
|
50
|
+
return cs_len.value
|
|
51
|
+
|
|
52
|
+
def __iter__(self):
|
|
53
|
+
self._update()
|
|
54
|
+
dx = c_double()
|
|
55
|
+
dy = c_double()
|
|
56
|
+
dz = c_double()
|
|
57
|
+
for i in range(self.__len__()):
|
|
58
|
+
lgeos.GEOSCoordSeq_getX(self._cseq, i, byref(dx))
|
|
59
|
+
lgeos.GEOSCoordSeq_getY(self._cseq, i, byref(dy))
|
|
60
|
+
if self._ndim == 3: # TODO: use hasz
|
|
61
|
+
lgeos.GEOSCoordSeq_getZ(self._cseq, i, byref(dz))
|
|
62
|
+
yield (dx.value, dy.value, dz.value)
|
|
63
|
+
else:
|
|
64
|
+
yield (dx.value, dy.value)
|
|
65
|
+
|
|
66
|
+
def __getitem__(self, i):
|
|
67
|
+
self._update()
|
|
68
|
+
M = self.__len__()
|
|
69
|
+
if i + M < 0 or i >= M:
|
|
70
|
+
raise IndexError("index out of range")
|
|
71
|
+
if i < 0:
|
|
72
|
+
ii = M + i
|
|
73
|
+
else:
|
|
74
|
+
ii = i
|
|
75
|
+
dx = c_double()
|
|
76
|
+
dy = c_double()
|
|
77
|
+
dz = c_double()
|
|
78
|
+
lgeos.GEOSCoordSeq_getX(self._cseq, ii, byref(dx))
|
|
79
|
+
lgeos.GEOSCoordSeq_getY(self._cseq, ii, byref(dy))
|
|
80
|
+
if self._ndim == 3: # TODO: use hasz
|
|
81
|
+
lgeos.GEOSCoordSeq_getZ(self._cseq, ii, byref(dz))
|
|
82
|
+
return (dx.value, dy.value, dz.value)
|
|
83
|
+
else:
|
|
84
|
+
return (dx.value, dy.value)
|
|
85
|
+
|
|
86
|
+
@property
|
|
87
|
+
def ctypes(self):
|
|
88
|
+
self._update()
|
|
89
|
+
n = self._ndim
|
|
90
|
+
m = self.__len__()
|
|
91
|
+
array_type = c_double * (m * n)
|
|
92
|
+
data = array_type()
|
|
93
|
+
temp = c_double()
|
|
94
|
+
for i in xrange(m):
|
|
95
|
+
lgeos.GEOSCoordSeq_getX(self._cseq, i, byref(temp))
|
|
96
|
+
data[n*i] = temp.value
|
|
97
|
+
lgeos.GEOSCoordSeq_getY(self._cseq, i, byref(temp))
|
|
98
|
+
data[n*i+1] = temp.value
|
|
99
|
+
if n == 3: # TODO: use hasz
|
|
100
|
+
lgeos.GEOSCoordSeq_getZ(self._cseq, i, byref(temp))
|
|
101
|
+
data[n*i+2] = temp.value
|
|
102
|
+
return data
|
|
103
|
+
|
|
104
|
+
def array_interface(self):
|
|
105
|
+
"""Provide the Numpy array protocol."""
|
|
106
|
+
if sys.byteorder == 'little':
|
|
107
|
+
typestr = '<f8'
|
|
108
|
+
elif sys.byteorder == 'big':
|
|
109
|
+
typestr = '>f8'
|
|
110
|
+
else:
|
|
111
|
+
raise ValueError(
|
|
112
|
+
"Unsupported byteorder: neither little nor big-endian")
|
|
113
|
+
ai = {
|
|
114
|
+
'version': 3,
|
|
115
|
+
'typestr': typestr,
|
|
116
|
+
'data': self.ctypes,
|
|
117
|
+
}
|
|
118
|
+
ai.update({'shape': (len(self), self._ndim)})
|
|
119
|
+
return ai
|
|
120
|
+
|
|
121
|
+
__array_interface__ = property(array_interface)
|
|
122
|
+
|
|
123
|
+
@property
|
|
124
|
+
def xy(self):
|
|
125
|
+
"""X and Y arrays"""
|
|
126
|
+
self._update()
|
|
127
|
+
m = self.__len__()
|
|
128
|
+
x = array('d')
|
|
129
|
+
y = array('d')
|
|
130
|
+
temp = c_double()
|
|
131
|
+
for i in xrange(m):
|
|
132
|
+
lgeos.GEOSCoordSeq_getX(self._cseq, i, byref(temp))
|
|
133
|
+
x.append(temp.value)
|
|
134
|
+
lgeos.GEOSCoordSeq_getY(self._cseq, i, byref(temp))
|
|
135
|
+
y.append(temp.value)
|
|
136
|
+
return x, y
|
|
137
|
+
|
|
138
|
+
|
|
139
|
+
class BoundsOp(Validating):
|
|
140
|
+
|
|
141
|
+
def __init__(self, *args):
|
|
142
|
+
pass
|
|
143
|
+
|
|
144
|
+
def __call__(self, this):
|
|
145
|
+
self._validate(this)
|
|
146
|
+
env = this.envelope
|
|
147
|
+
if env.geom_type == 'Point':
|
|
148
|
+
return env.bounds
|
|
149
|
+
cs = lgeos.GEOSGeom_getCoordSeq(env.exterior._geom)
|
|
150
|
+
cs_len = c_uint(0)
|
|
151
|
+
lgeos.GEOSCoordSeq_getSize(cs, byref(cs_len))
|
|
152
|
+
minx = 1.e+20
|
|
153
|
+
maxx = -1e+20
|
|
154
|
+
miny = 1.e+20
|
|
155
|
+
maxy = -1e+20
|
|
156
|
+
temp = c_double()
|
|
157
|
+
for i in xrange(cs_len.value):
|
|
158
|
+
lgeos.GEOSCoordSeq_getX(cs, i, byref(temp))
|
|
159
|
+
x = temp.value
|
|
160
|
+
if x < minx: minx = x
|
|
161
|
+
if x > maxx: maxx = x
|
|
162
|
+
lgeos.GEOSCoordSeq_getY(cs, i, byref(temp))
|
|
163
|
+
y = temp.value
|
|
164
|
+
if y < miny: miny = y
|
|
165
|
+
if y > maxy: maxy = y
|
|
166
|
+
return (minx, miny, maxx, maxy)
|
|
167
|
+
|
shapely/coords.pyc
ADDED
|
Binary file
|