shapely 1.2.7__py2.7-win32.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/libgeos-3-2-2.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 +276 -0
- shapely/ctypes_declarations.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 +230 -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 +370 -0
- shapely/geos.pyc +0 -0
- shapely/impl.py +118 -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
shapely/ops.py
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Support for various GEOS geometry operations
|
|
2
|
+
"""
|
|
3
|
+
|
|
4
|
+
from ctypes import byref, c_void_p
|
|
5
|
+
|
|
6
|
+
from shapely.geos import lgeos
|
|
7
|
+
from shapely.geometry.base import geom_factory, BaseGeometry
|
|
8
|
+
from shapely.geometry import asShape, asLineString, asMultiLineString
|
|
9
|
+
|
|
10
|
+
__all__= ['operator', 'polygonize', 'linemerge', 'cascaded_union']
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class CollectionOperator(object):
|
|
14
|
+
|
|
15
|
+
def shapeup(self, ob):
|
|
16
|
+
if isinstance(ob, BaseGeometry):
|
|
17
|
+
return ob
|
|
18
|
+
else:
|
|
19
|
+
try:
|
|
20
|
+
return asShape(ob)
|
|
21
|
+
except ValueError:
|
|
22
|
+
return asLineString(ob)
|
|
23
|
+
|
|
24
|
+
def polygonize(self, lines):
|
|
25
|
+
"""Creates polygons from a source of lines
|
|
26
|
+
|
|
27
|
+
The source may be a MultiLineString, a sequence of LineString objects,
|
|
28
|
+
or a sequence of objects than can be adapted to LineStrings.
|
|
29
|
+
"""
|
|
30
|
+
source = getattr(lines, 'geoms', None) or lines
|
|
31
|
+
obs = [self.shapeup(l) for l in source]
|
|
32
|
+
geom_array_type = c_void_p * len(obs)
|
|
33
|
+
geom_array = geom_array_type()
|
|
34
|
+
for i, line in enumerate(obs):
|
|
35
|
+
geom_array[i] = line._geom
|
|
36
|
+
product = lgeos.GEOSPolygonize(byref(geom_array), len(obs))
|
|
37
|
+
collection = geom_factory(product)
|
|
38
|
+
for g in collection.geoms:
|
|
39
|
+
clone = lgeos.GEOSGeom_clone(g._geom)
|
|
40
|
+
g = geom_factory(clone)
|
|
41
|
+
g._owned = False
|
|
42
|
+
yield g
|
|
43
|
+
|
|
44
|
+
def linemerge(self, lines):
|
|
45
|
+
"""Merges all connected lines from a source
|
|
46
|
+
|
|
47
|
+
The source may be a MultiLineString, a sequence of LineString objects,
|
|
48
|
+
or a sequence of objects than can be adapted to LineStrings. Returns a
|
|
49
|
+
LineString or MultiLineString when lines are not contiguous.
|
|
50
|
+
"""
|
|
51
|
+
source = None
|
|
52
|
+
if hasattr(lines, 'type') and lines.type == 'MultiLineString':
|
|
53
|
+
source = lines
|
|
54
|
+
elif hasattr(lines, '__iter__'):
|
|
55
|
+
try:
|
|
56
|
+
source = asMultiLineString([ls.coords for ls in lines])
|
|
57
|
+
except AttributeError:
|
|
58
|
+
source = asMultiLineString(lines)
|
|
59
|
+
if source is None:
|
|
60
|
+
raise ValueError("Cannot linemerge %s" % lines)
|
|
61
|
+
result = lgeos.GEOSLineMerge(source._geom)
|
|
62
|
+
return geom_factory(result)
|
|
63
|
+
|
|
64
|
+
def cascaded_union(self, geoms):
|
|
65
|
+
"""Returns the union of a sequence of geometries
|
|
66
|
+
|
|
67
|
+
This is the most efficient method of dissolving many polygons.
|
|
68
|
+
"""
|
|
69
|
+
L = len(geoms)
|
|
70
|
+
subs = (c_void_p * L)()
|
|
71
|
+
for i, g in enumerate(geoms):
|
|
72
|
+
subs[i] = g._geom
|
|
73
|
+
collection = lgeos.GEOSGeom_createCollection(6, subs, L)
|
|
74
|
+
return geom_factory(lgeos.GEOSUnionCascaded(collection))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
operator = CollectionOperator()
|
|
78
|
+
polygonize = operator.polygonize
|
|
79
|
+
linemerge = operator.linemerge
|
|
80
|
+
cascaded_union = operator.cascaded_union
|
|
81
|
+
|
|
82
|
+
class ValidateOp(object):
|
|
83
|
+
def __call__(self, this):
|
|
84
|
+
return lgeos.GEOSisValidReason(this._geom)
|
|
85
|
+
|
|
86
|
+
validate = ValidateOp()
|
|
87
|
+
|
shapely/ops.pyc
ADDED
|
Binary file
|
shapely/predicates.py
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Support for GEOS spatial predicates
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from shapely.geos import PredicateError, lgeos
|
|
6
|
+
from shapely.topology import Delegating
|
|
7
|
+
|
|
8
|
+
class BinaryPredicate(Delegating):
|
|
9
|
+
def __call__(self, this, other, *args):
|
|
10
|
+
self._validate(this)
|
|
11
|
+
self._validate(other)
|
|
12
|
+
return self.fn(this._geom, other._geom, *args)
|
|
13
|
+
|
|
14
|
+
class RelateOp(Delegating):
|
|
15
|
+
def __call__(self, this, other):
|
|
16
|
+
self._validate(this)
|
|
17
|
+
self._validate(other)
|
|
18
|
+
return self.fn(this._geom, other._geom)
|
|
19
|
+
|
|
20
|
+
class UnaryPredicate(Delegating):
|
|
21
|
+
def __call__(self, this):
|
|
22
|
+
self._validate(this)
|
|
23
|
+
return self.fn(this._geom)
|
|
24
|
+
|
shapely/predicates.pyc
ADDED
|
Binary file
|
shapely/prepared.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Support for GEOS prepared geometry operations.
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
from shapely.geos import lgeos
|
|
6
|
+
from shapely.impl import DefaultImplementation, delegated
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PreparedGeometry(object):
|
|
10
|
+
"""
|
|
11
|
+
A geometry prepared for efficient comparison to a set of other geometries.
|
|
12
|
+
|
|
13
|
+
Example:
|
|
14
|
+
|
|
15
|
+
>>> from shapely.geometry import Point, Polygon
|
|
16
|
+
>>> triangle = Polygon(((0.0, 0.0), (1.0, 1.0), (1.0, -1.0)))
|
|
17
|
+
>>> p = prep(triangle)
|
|
18
|
+
>>> p.intersects(Point(0.5, 0.5))
|
|
19
|
+
True
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
impl = DefaultImplementation
|
|
23
|
+
|
|
24
|
+
def __init__(self, context):
|
|
25
|
+
self.context = context
|
|
26
|
+
self.__geom__ = lgeos.GEOSPrepare(self.context._geom)
|
|
27
|
+
|
|
28
|
+
def __del__(self):
|
|
29
|
+
if self.__geom__ is not None:
|
|
30
|
+
lgeos.GEOSPreparedGeom_destroy(self.__geom__)
|
|
31
|
+
self.__geom__ = None
|
|
32
|
+
self.context = None
|
|
33
|
+
|
|
34
|
+
@property
|
|
35
|
+
def _geom(self):
|
|
36
|
+
return self.__geom__
|
|
37
|
+
|
|
38
|
+
@delegated
|
|
39
|
+
def intersects(self, other):
|
|
40
|
+
return bool(self.impl['prepared_intersects'](self, other))
|
|
41
|
+
|
|
42
|
+
@delegated
|
|
43
|
+
def contains(self, other):
|
|
44
|
+
return bool(self.impl['prepared_contains'](self, other))
|
|
45
|
+
|
|
46
|
+
@delegated
|
|
47
|
+
def contains_properly(self, other):
|
|
48
|
+
return bool(self.impl['prepared_contains_properly'](self, other))
|
|
49
|
+
|
|
50
|
+
@delegated
|
|
51
|
+
def covers(self, other):
|
|
52
|
+
return bool(self.impl['prepared_covers'](self, other))
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def prep(ob):
|
|
56
|
+
"""Creates and returns a prepared geometric object."""
|
|
57
|
+
return PreparedGeometry(ob)
|
|
58
|
+
|
shapely/prepared.pyc
ADDED
|
Binary file
|
shapely/topology.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Intermediaries supporting GEOS topological operations
|
|
3
|
+
|
|
4
|
+
These methods all take Shapely geometries and other Python objects and delegate
|
|
5
|
+
to GEOS functions via ctypes.
|
|
6
|
+
|
|
7
|
+
These methods return ctypes objects that should be recast by the caller.
|
|
8
|
+
"""
|
|
9
|
+
|
|
10
|
+
from ctypes import byref, c_double
|
|
11
|
+
from shapely.geos import TopologicalError, lgeos
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class Validating(object):
|
|
15
|
+
def _validate(self, ob):
|
|
16
|
+
try:
|
|
17
|
+
assert ob is not None
|
|
18
|
+
assert ob._geom is not None
|
|
19
|
+
except AssertionError:
|
|
20
|
+
raise ValueError("Null geometry supports no operations")
|
|
21
|
+
|
|
22
|
+
class Delegating(Validating):
|
|
23
|
+
def __init__(self, name):
|
|
24
|
+
self.fn = lgeos.methods[name]
|
|
25
|
+
|
|
26
|
+
class BinaryRealProperty(Delegating):
|
|
27
|
+
def __call__(self, this, other):
|
|
28
|
+
self._validate(this)
|
|
29
|
+
self._validate(other)
|
|
30
|
+
d = c_double()
|
|
31
|
+
retval = self.fn(this._geom, other._geom, byref(d))
|
|
32
|
+
return d.value
|
|
33
|
+
|
|
34
|
+
class UnaryRealProperty(Delegating):
|
|
35
|
+
def __call__(self, this):
|
|
36
|
+
self._validate(this)
|
|
37
|
+
d = c_double()
|
|
38
|
+
retval = self.fn(this._geom, byref(d))
|
|
39
|
+
return d.value
|
|
40
|
+
|
|
41
|
+
class BinaryTopologicalOp(Delegating):
|
|
42
|
+
def __call__(self, this, other, *args):
|
|
43
|
+
self._validate(this)
|
|
44
|
+
self._validate(other)
|
|
45
|
+
product = self.fn(this._geom, other._geom, *args)
|
|
46
|
+
if product is None:
|
|
47
|
+
if not this.is_valid:
|
|
48
|
+
raise TopologicalError(
|
|
49
|
+
"The operation '%s' produced a null geometry. Likely cause is invalidity of the geometry %s" % (self.fn.__name__, repr(this)))
|
|
50
|
+
elif not other.is_valid:
|
|
51
|
+
raise TopologicalError(
|
|
52
|
+
"The operation '%s' produced a null geometry. Likely cause is invalidity of the 'other' geometry %s" % (self.fn.__name__, repr(other)))
|
|
53
|
+
else:
|
|
54
|
+
raise TopologicalError(
|
|
55
|
+
"This operation produced a null geometry. Reason: unknown")
|
|
56
|
+
return product
|
|
57
|
+
|
|
58
|
+
class UnaryTopologicalOp(Delegating):
|
|
59
|
+
def __call__(self, this, *args):
|
|
60
|
+
self._validate(this)
|
|
61
|
+
return self.fn(this._geom, *args)
|
|
62
|
+
|
shapely/topology.pyc
ADDED
|
Binary file
|
shapely/validation.py
ADDED
shapely/validation.pyc
ADDED
|
Binary file
|
shapely/wkb.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"""Load/dump geometries using the well-known binary (WKB) format
|
|
2
|
+
"""
|
|
3
|
+
|
|
4
|
+
from ctypes import byref, c_size_t, c_char_p, string_at
|
|
5
|
+
from ctypes import c_void_p, c_size_t
|
|
6
|
+
|
|
7
|
+
from shapely.geos import lgeos, ReadingError
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
# Pickle-like convenience functions
|
|
11
|
+
|
|
12
|
+
def deserialize(data):
|
|
13
|
+
geom = lgeos.GEOSGeomFromWKB_buf(c_char_p(data), c_size_t(len(data)));
|
|
14
|
+
if not geom:
|
|
15
|
+
raise ReadingError(
|
|
16
|
+
"Could not create geometry because of errors while reading input.")
|
|
17
|
+
return geom
|
|
18
|
+
|
|
19
|
+
def loads(data):
|
|
20
|
+
"""Load a geometry from a WKB string."""
|
|
21
|
+
from shapely.geometry.base import geom_factory
|
|
22
|
+
return geom_factory(deserialize(data))
|
|
23
|
+
|
|
24
|
+
def load(fp):
|
|
25
|
+
"""Load a geometry from an open file."""
|
|
26
|
+
data = fp.read()
|
|
27
|
+
return loads(data)
|
|
28
|
+
|
|
29
|
+
def dumps(ob):
|
|
30
|
+
"""Dump a WKB representation of a geometry to a byte string."""
|
|
31
|
+
if ob is None or ob._geom is None:
|
|
32
|
+
raise ValueError("Null geometry supports no operations")
|
|
33
|
+
size = c_size_t()
|
|
34
|
+
return lgeos.GEOSGeomToWKB_buf(c_void_p(ob._geom), byref(size))
|
|
35
|
+
|
|
36
|
+
def dump(ob, fp):
|
|
37
|
+
"""Dump a geometry to an open file."""
|
|
38
|
+
fp.write(dumps(ob))
|
|
39
|
+
|
shapely/wkb.pyc
ADDED
|
Binary file
|
shapely/wkt.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Load/dump geometries using the well-known text (WKT) format
|
|
2
|
+
"""
|
|
3
|
+
|
|
4
|
+
from ctypes import c_char_p
|
|
5
|
+
|
|
6
|
+
from shapely.geos import lgeos, ReadingError
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
# Pickle-like convenience functions
|
|
10
|
+
|
|
11
|
+
def loads(data):
|
|
12
|
+
"""Load a geometry from a WKT string."""
|
|
13
|
+
from shapely.geometry.base import geom_factory
|
|
14
|
+
geom = lgeos.GEOSGeomFromWKT(c_char_p(data))
|
|
15
|
+
if not geom:
|
|
16
|
+
raise ReadingError, \
|
|
17
|
+
"Could not create geometry because of errors while reading input."
|
|
18
|
+
return geom_factory(geom)
|
|
19
|
+
|
|
20
|
+
def load(fp):
|
|
21
|
+
"""Load a geometry from an open file."""
|
|
22
|
+
data = fp.read()
|
|
23
|
+
return loads(data)
|
|
24
|
+
|
|
25
|
+
def dumps(ob):
|
|
26
|
+
"""Dump a WKB representation of a geometry to a byte string."""
|
|
27
|
+
if ob is None or ob._geom is None:
|
|
28
|
+
raise ValueError("Null geometry supports no operations")
|
|
29
|
+
return lgeos.GEOSGeomToWKT(ob._geom)
|
|
30
|
+
|
|
31
|
+
def dump(ob, fp):
|
|
32
|
+
"""Dump a geometry to an open file."""
|
|
33
|
+
fp.write(dumps(ob))
|
|
34
|
+
|
shapely/wkt.pyc
ADDED
|
Binary file
|