shapely 1.2.10__py2.7-win-amd64.egg → 1.2.12__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.
- EGG-INFO/PKG-INFO +16 -1
- EGG-INFO/native_libs.txt +1 -0
- shapely/ctypes_declarations.py +5 -0
- shapely/ctypes_declarations.pyc +0 -0
- shapely/examples/__init__.py +1 -0
- shapely/examples/__init__.pyc +0 -0
- shapely/examples/dissolve.py +53 -0
- shapely/examples/dissolve.pyc +0 -0
- shapely/examples/geoms.py +51 -0
- shapely/examples/geoms.pyc +0 -0
- shapely/examples/intersect.py +81 -0
- shapely/examples/intersect.pyc +0 -0
- shapely/examples/world.py +21 -0
- shapely/examples/world.pyc +0 -0
- shapely/geometry/base.py +4 -1
- shapely/geometry/base.pyc +0 -0
- shapely/geometry/linestring.py +8 -13
- shapely/geometry/linestring.pyc +0 -0
- shapely/geometry/multilinestring.py +0 -3
- shapely/geometry/multilinestring.pyc +0 -0
- shapely/geometry/multipoint.py +3 -2
- shapely/geometry/multipoint.pyc +0 -0
- shapely/geometry/polygon.py +19 -39
- shapely/geometry/polygon.pyc +0 -0
- shapely/geos.py +8 -7
- shapely/geos.pyc +0 -0
- shapely/predicates.py +2 -2
- shapely/predicates.pyc +0 -0
- shapely/prepared.py +4 -1
- shapely/prepared.pyc +0 -0
- shapely/speedups/__init__.py +42 -0
- shapely/speedups/__init__.pyc +0 -0
- shapely/speedups/_speedups.py +7 -0
- shapely/speedups/_speedups.pyc +0 -0
- shapely/speedups/_speedups.pyd +0 -0
- shapely/tests/__init__.py +28 -0
- shapely/tests/__init__.pyc +0 -0
- shapely/tests/test_box.py +19 -0
- shapely/tests/test_box.pyc +0 -0
- shapely/tests/test_cga.py +33 -0
- shapely/tests/test_cga.pyc +0 -0
- shapely/tests/test_collection.py +11 -0
- shapely/tests/test_collection.pyc +0 -0
- shapely/tests/test_delegated.py +26 -0
- shapely/tests/test_delegated.pyc +0 -0
- shapely/tests/test_dlls.py +16 -0
- shapely/tests/test_dlls.pyc +0 -0
- shapely/tests/test_doctests.py +35 -0
- shapely/tests/test_doctests.pyc +0 -0
- shapely/tests/test_emptiness.py +19 -0
- shapely/tests/test_emptiness.pyc +0 -0
- shapely/tests/test_equality.py +30 -0
- shapely/tests/test_equality.pyc +0 -0
- shapely/tests/test_geomseq.py +11 -0
- shapely/tests/test_geomseq.pyc +0 -0
- shapely/tests/test_linear_referencing.py +67 -0
- shapely/tests/test_linear_referencing.pyc +0 -0
- shapely/tests/test_mapping.py +11 -0
- shapely/tests/test_mapping.pyc +0 -0
- shapely/tests/test_prepared.py +28 -0
- shapely/tests/test_prepared.pyc +0 -0
- shapely/tests/test_products_z.py +14 -0
- shapely/tests/test_products_z.pyc +0 -0
- shapely/tests/test_singularity.py +15 -0
- shapely/tests/test_singularity.pyc +0 -0
- shapely/tests/test_speedups.py +38 -0
- shapely/tests/test_speedups.pyc +0 -0
- shapely/tests/test_validation.py +10 -0
- shapely/tests/test_validation.pyc +0 -0
- shapely/tests/test_xy.py +14 -0
- shapely/tests/test_xy.pyc +0 -0
- shapely/tests/threading_test.py +37 -0
- shapely/tests/threading_test.pyc +0 -0
- shapely/topology.py +6 -8
- shapely/topology.pyc +0 -0
- shapely/wkb.py +2 -2
- shapely/wkb.pyc +0 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely import geometry
|
|
3
|
+
|
|
4
|
+
class BoxTestCase(unittest.TestCase):
|
|
5
|
+
def test_ccw(self):
|
|
6
|
+
b = geometry.box(0, 0, 1, 1, ccw=True)
|
|
7
|
+
self.assertEqual(b.exterior.coords[0], (1.0, 0.0))
|
|
8
|
+
self.assertEqual(b.exterior.coords[1], (1.0, 1.0))
|
|
9
|
+
def test_ccw_default(self):
|
|
10
|
+
b = geometry.box(0, 0, 1, 1)
|
|
11
|
+
self.assertEqual(b.exterior.coords[0], (1.0, 0.0))
|
|
12
|
+
self.assertEqual(b.exterior.coords[1], (1.0, 1.0))
|
|
13
|
+
def test_cw(self):
|
|
14
|
+
b = geometry.box(0, 0, 1, 1, ccw=False)
|
|
15
|
+
self.assertEqual(b.exterior.coords[0], (0.0, 0.0))
|
|
16
|
+
self.assertEqual(b.exterior.coords[1], (0.0, 1.0))
|
|
17
|
+
|
|
18
|
+
def test_suite():
|
|
19
|
+
return unittest.TestLoader().loadTestsFromTestCase(BoxTestCase)
|
|
Binary file
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely.geometry.polygon import LinearRing, orient, Polygon
|
|
3
|
+
|
|
4
|
+
class RingOrientationTestCase(unittest.TestCase):
|
|
5
|
+
def test_ccw(self):
|
|
6
|
+
ring = LinearRing([(1,0),(0,1),(0,0)])
|
|
7
|
+
self.failUnless(ring.is_ccw)
|
|
8
|
+
def test_cw(self):
|
|
9
|
+
ring = LinearRing([(0,0),(0,1),(1,0)])
|
|
10
|
+
self.failIf(ring.is_ccw)
|
|
11
|
+
|
|
12
|
+
class PolygonOrienterTestCase(unittest.TestCase):
|
|
13
|
+
def test_no_holes(self):
|
|
14
|
+
ring = LinearRing([(0,0),(0,1),(1,0)])
|
|
15
|
+
polygon = Polygon(ring)
|
|
16
|
+
self.failIf(polygon.exterior.is_ccw)
|
|
17
|
+
polygon = orient(polygon, 1)
|
|
18
|
+
self.failUnless(polygon.exterior.is_ccw)
|
|
19
|
+
def test_holes(self):
|
|
20
|
+
polygon = Polygon([(0,0),(0,1),(1,0)],
|
|
21
|
+
[[(0.5,0.25),(0.25,0.5),(0.25,0.25)]])
|
|
22
|
+
self.failIf(polygon.exterior.is_ccw)
|
|
23
|
+
self.failUnless(polygon.interiors[0].is_ccw)
|
|
24
|
+
polygon = orient(polygon, 1)
|
|
25
|
+
self.failUnless(polygon.exterior.is_ccw)
|
|
26
|
+
self.failIf(polygon.interiors[0].is_ccw)
|
|
27
|
+
|
|
28
|
+
def test_suite():
|
|
29
|
+
loader = unittest.TestLoader()
|
|
30
|
+
return unittest.TestSuite([
|
|
31
|
+
loader.loadTestsFromTestCase(RingOrientationTestCase),
|
|
32
|
+
loader.loadTestsFromTestCase(PolygonOrienterTestCase)])
|
|
33
|
+
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely.geometry.collection import GeometryCollection
|
|
3
|
+
|
|
4
|
+
class CollectionTestCase(unittest.TestCase):
|
|
5
|
+
def test_array_interface(self):
|
|
6
|
+
m = GeometryCollection()
|
|
7
|
+
self.failUnlessEqual(len(m), 0)
|
|
8
|
+
self.failUnlessEqual(m.geoms, [])
|
|
9
|
+
|
|
10
|
+
def test_suite():
|
|
11
|
+
return unittest.TestLoader().loadTestsFromTestCase(CollectionTestCase)
|
|
Binary file
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely.geometry import Point
|
|
3
|
+
from shapely.impl import BaseImpl
|
|
4
|
+
from shapely.geometry.base import delegated
|
|
5
|
+
|
|
6
|
+
class Geometry(object):
|
|
7
|
+
impl = BaseImpl({})
|
|
8
|
+
@property
|
|
9
|
+
@delegated
|
|
10
|
+
def foo(self):
|
|
11
|
+
return self.impl['foo']()
|
|
12
|
+
|
|
13
|
+
class WrapperTestCase(unittest.TestCase):
|
|
14
|
+
"""When the backend has no support for a method, we get an AttributeError"""
|
|
15
|
+
def test_delegated(self):
|
|
16
|
+
self.assertRaises(AttributeError, getattr, Geometry(), 'foo')
|
|
17
|
+
def test_defaultimpl(self):
|
|
18
|
+
project_impl = Point.impl.map.pop('project', None)
|
|
19
|
+
try:
|
|
20
|
+
self.assertRaises(AttributeError, Point(0, 0).project, 1.0)
|
|
21
|
+
finally:
|
|
22
|
+
if project_impl is not None:
|
|
23
|
+
Point.impl.map['project'] = project_impl
|
|
24
|
+
|
|
25
|
+
def test_suite():
|
|
26
|
+
return unittest.TestLoader().loadTestsFromTestCase(WrapperTestCase)
|
|
Binary file
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
from shapely.geos import load_dll
|
|
4
|
+
|
|
5
|
+
class LoadingTestCase(unittest.TestCase):
|
|
6
|
+
def test_load(self):
|
|
7
|
+
self.assertRaises(OSError, load_dll, 'geosh_c')
|
|
8
|
+
def test_fallbacks(self):
|
|
9
|
+
a = load_dll('geosh_c', fallbacks=[
|
|
10
|
+
'/opt/local/lib/libgeos_c.dylib', # MacPorts
|
|
11
|
+
'/usr/local/lib/libgeos_c.dylib', # homebrew (Mac OS X)
|
|
12
|
+
'libgeos_c.so.1',
|
|
13
|
+
'libgeos_c.so'])
|
|
14
|
+
|
|
15
|
+
def test_suite():
|
|
16
|
+
return unittest.TestLoader().loadTestsFromTestCase(LoadingTestCase)
|
|
Binary file
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import doctest
|
|
2
|
+
import unittest
|
|
3
|
+
import glob
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
optionflags = (doctest.REPORT_ONLY_FIRST_FAILURE |
|
|
7
|
+
doctest.NORMALIZE_WHITESPACE |
|
|
8
|
+
doctest.ELLIPSIS)
|
|
9
|
+
|
|
10
|
+
def list_doctests():
|
|
11
|
+
print __file__
|
|
12
|
+
return [filename
|
|
13
|
+
for filename
|
|
14
|
+
in glob.glob(os.path.join(os.path.dirname(__file__), '*.txt'))]
|
|
15
|
+
|
|
16
|
+
def open_file(filename, mode='r'):
|
|
17
|
+
"""Helper function to open files from within the tests package."""
|
|
18
|
+
return open(os.path.join(os.path.dirname(__file__), filename), mode)
|
|
19
|
+
|
|
20
|
+
def setUp(test):
|
|
21
|
+
test.globs.update(dict(
|
|
22
|
+
open_file = open_file,
|
|
23
|
+
))
|
|
24
|
+
|
|
25
|
+
def test_suite():
|
|
26
|
+
return unittest.TestSuite(
|
|
27
|
+
[doctest.DocFileSuite(os.path.basename(filename),
|
|
28
|
+
optionflags=optionflags,
|
|
29
|
+
setUp=setUp)
|
|
30
|
+
for filename
|
|
31
|
+
in list_doctests()])
|
|
32
|
+
|
|
33
|
+
if __name__ == "__main__":
|
|
34
|
+
runner = unittest.TextTestRunner(verbosity=1)
|
|
35
|
+
runner.run(test_suite())
|
|
Binary file
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely.geometry.base import BaseGeometry
|
|
3
|
+
from shapely.geometry import Point
|
|
4
|
+
|
|
5
|
+
class EmptinessTestCase(unittest.TestCase):
|
|
6
|
+
def test_empty_base(self):
|
|
7
|
+
g = BaseGeometry()
|
|
8
|
+
self.failUnless(g._is_empty, True)
|
|
9
|
+
def test_empty_point(self):
|
|
10
|
+
p = Point()
|
|
11
|
+
self.failUnless(p._is_empty, True)
|
|
12
|
+
def test_emptying_point(self):
|
|
13
|
+
p = Point(0, 0)
|
|
14
|
+
self.failIf(p._is_empty, False)
|
|
15
|
+
p.empty()
|
|
16
|
+
self.failUnless(p._is_empty, True)
|
|
17
|
+
|
|
18
|
+
def test_suite():
|
|
19
|
+
return unittest.TestLoader().loadTestsFromTestCase(EmptinessTestCase)
|
|
Binary file
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely import geometry
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class PointEqualityTestCase(unittest.TestCase):
|
|
6
|
+
|
|
7
|
+
def test_equals_exact(self):
|
|
8
|
+
p1 = geometry.Point(1.0, 1.0)
|
|
9
|
+
p2 = geometry.Point(2.0, 2.0)
|
|
10
|
+
self.failIf(p1.equals(p2))
|
|
11
|
+
self.failIf(p1.equals_exact(p2, 0.001))
|
|
12
|
+
|
|
13
|
+
def test_almost_equals_default(self):
|
|
14
|
+
p1 = geometry.Point(1.0, 1.0)
|
|
15
|
+
p2 = geometry.Point(1.0+1e-7, 1.0+1e-7) # almost equal to 6 places
|
|
16
|
+
p3 = geometry.Point(1.0+1e-6, 1.0+1e-6) # not almost equal
|
|
17
|
+
self.failUnless(p1.almost_equals(p2))
|
|
18
|
+
self.failIf(p1.almost_equals(p3))
|
|
19
|
+
|
|
20
|
+
def test_almost_equals(self):
|
|
21
|
+
p1 = geometry.Point(1.0, 1.0)
|
|
22
|
+
p2 = geometry.Point(1.1, 1.1)
|
|
23
|
+
self.failIf(p1.equals(p2))
|
|
24
|
+
self.failUnless(p1.almost_equals(p2, 0))
|
|
25
|
+
self.failIf(p1.almost_equals(p2, 1))
|
|
26
|
+
|
|
27
|
+
def test_suite():
|
|
28
|
+
return unittest.TestLoader().loadTestsFromTestCase(
|
|
29
|
+
PointEqualityTestCase
|
|
30
|
+
)
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely import geometry
|
|
3
|
+
|
|
4
|
+
class MultiLineTestCase(unittest.TestCase):
|
|
5
|
+
def test_array_interface(self):
|
|
6
|
+
m = geometry.MultiLineString([((0, 0), (1, 1)), ((2, 2), (3, 3))])
|
|
7
|
+
ai = m.geoms[0].__array_interface__
|
|
8
|
+
self.failUnlessEqual(ai['shape'], (2, 2))
|
|
9
|
+
|
|
10
|
+
def test_suite():
|
|
11
|
+
return unittest.TestLoader().loadTestsFromTestCase(MultiLineTestCase)
|
|
Binary file
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely.geometry import Point, LineString, MultiLineString
|
|
3
|
+
|
|
4
|
+
class LinearReferencingTestCase(unittest.TestCase):
|
|
5
|
+
def setUp(self):
|
|
6
|
+
self.point = Point(1, 1)
|
|
7
|
+
self.line1 = LineString(([0, 0], [2, 0]))
|
|
8
|
+
self.line2 = LineString(([3, 0], [3, 6]))
|
|
9
|
+
self.multiline = MultiLineString([
|
|
10
|
+
list(self.line1.coords), list(self.line2.coords)
|
|
11
|
+
])
|
|
12
|
+
|
|
13
|
+
def test_line1_project(self):
|
|
14
|
+
self.assertEqual(self.line1.project(self.point), 1.0)
|
|
15
|
+
self.assertEqual(self.line1.project(self.point, normalized=True), 0.5)
|
|
16
|
+
|
|
17
|
+
def test_line2_project(self):
|
|
18
|
+
self.assertEqual(self.line2.project(self.point), 1.0)
|
|
19
|
+
self.assertAlmostEqual(self.line2.project(self.point, normalized=True),
|
|
20
|
+
0.16666666666, 8)
|
|
21
|
+
|
|
22
|
+
def test_multiline_project(self):
|
|
23
|
+
self.assertEqual(self.multiline.project(self.point), 1.0)
|
|
24
|
+
self.assertEqual(self.multiline.project(self.point, normalized=True),
|
|
25
|
+
0.125)
|
|
26
|
+
|
|
27
|
+
def test_not_supported_project(self):
|
|
28
|
+
self.assertRaises(TypeError, self.point.buffer(1.0).project,
|
|
29
|
+
self.point)
|
|
30
|
+
|
|
31
|
+
def test_not_on_line_project(self):
|
|
32
|
+
# Points that aren't on the line project to 0.
|
|
33
|
+
self.assertEqual(self.line1.project(Point(-10,-10)), 0.0)
|
|
34
|
+
|
|
35
|
+
def test_line1_interpolate(self):
|
|
36
|
+
self.failUnless(self.line1.interpolate(0.5).equals(Point(0.5, 0.0)))
|
|
37
|
+
self.failUnless(
|
|
38
|
+
self.line1.interpolate(0.5, normalized=True).equals(
|
|
39
|
+
Point(1.0, 0.0)))
|
|
40
|
+
|
|
41
|
+
def test_line2_interpolate(self):
|
|
42
|
+
self.failUnless(self.line2.interpolate(0.5).equals(Point(3.0, 0.5)))
|
|
43
|
+
self.failUnless(
|
|
44
|
+
self.line2.interpolate(0.5, normalized=True).equals(
|
|
45
|
+
Point(3.0, 3.0)))
|
|
46
|
+
|
|
47
|
+
def test_multiline_interpolate(self):
|
|
48
|
+
self.failUnless(self.multiline.interpolate(0.5).equals(
|
|
49
|
+
Point(0.5, 0.0)))
|
|
50
|
+
self.failUnless(
|
|
51
|
+
self.multiline.interpolate(0.5, normalized=True).equals(
|
|
52
|
+
Point(3.0, 2.0)))
|
|
53
|
+
|
|
54
|
+
def test_line_ends_interpolate(self):
|
|
55
|
+
# Distances greater than length of the line or less than
|
|
56
|
+
# zero yield the line's ends.
|
|
57
|
+
self.failUnless(self.line1.interpolate(-1000).equals(Point(0.0, 0.0)))
|
|
58
|
+
self.failUnless(self.line1.interpolate(1000).equals(Point(2.0, 0.0)))
|
|
59
|
+
|
|
60
|
+
def test_suite():
|
|
61
|
+
try:
|
|
62
|
+
LineString(([0, 0], [2, 0])).project(Point(0, 0))
|
|
63
|
+
except AttributeError:
|
|
64
|
+
return lambda x: None
|
|
65
|
+
return unittest.TestLoader().loadTestsFromTestCase(
|
|
66
|
+
LinearReferencingTestCase
|
|
67
|
+
)
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely.geometry import Point, mapping
|
|
3
|
+
|
|
4
|
+
class MappingTestCase(unittest.TestCase):
|
|
5
|
+
def test_point(self):
|
|
6
|
+
m = mapping(Point(0, 0))
|
|
7
|
+
self.failUnlessEqual(m['type'], 'Point')
|
|
8
|
+
self.failUnlessEqual(m['coordinates'], (0.0, 0.0))
|
|
9
|
+
|
|
10
|
+
def test_suite():
|
|
11
|
+
return unittest.TestLoader().loadTestsFromTestCase(MappingTestCase)
|
|
Binary file
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely import prepared
|
|
3
|
+
from shapely import geometry
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class PreparedGeometryTestCase(unittest.TestCase):
|
|
7
|
+
|
|
8
|
+
def test_prepared(self):
|
|
9
|
+
polygon = geometry.Polygon([
|
|
10
|
+
(0, 0), (1, 0), (1, 1), (0, 1)
|
|
11
|
+
])
|
|
12
|
+
p = prepared.PreparedGeometry(polygon)
|
|
13
|
+
self.assertTrue(p.contains(geometry.Point(0.5, 0.5)))
|
|
14
|
+
self.assertFalse(p.contains(geometry.Point(0.5, 1.5)))
|
|
15
|
+
|
|
16
|
+
def test_op_not_allowed(self):
|
|
17
|
+
p = prepared.PreparedGeometry(geometry.Point(0.0, 0.0).buffer(1.0))
|
|
18
|
+
self.assertRaises(ValueError, geometry.Point(0.0, 0.0).union, p)
|
|
19
|
+
|
|
20
|
+
def test_predicate_not_allowed(self):
|
|
21
|
+
p = prepared.PreparedGeometry(geometry.Point(0.0, 0.0).buffer(1.0))
|
|
22
|
+
self.assertRaises(ValueError, geometry.Point(0.0, 0.0).contains, p)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def test_suite():
|
|
26
|
+
return unittest.TestLoader().loadTestsFromTestCase(
|
|
27
|
+
PreparedGeometryTestCase
|
|
28
|
+
)
|
|
Binary file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely.geometry import LineString
|
|
3
|
+
|
|
4
|
+
class ProductZTestCase(unittest.TestCase):
|
|
5
|
+
def test_line_intersection(self):
|
|
6
|
+
line1 = LineString([(0,0,0), (1,1,1)])
|
|
7
|
+
line2 = LineString([(0,1,1), (1,0,0)])
|
|
8
|
+
interxn = line1.intersection(line2)
|
|
9
|
+
self.failUnless(interxn.has_z)
|
|
10
|
+
self.failUnless(interxn._ndim == 3)
|
|
11
|
+
self.failUnless(0.0 <= interxn.z <= 1.0)
|
|
12
|
+
|
|
13
|
+
def test_suite():
|
|
14
|
+
return unittest.TestLoader().loadTestsFromTestCase(ProductZTestCase)
|
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely.geometry import Polygon
|
|
3
|
+
|
|
4
|
+
class PolygonTestCase(unittest.TestCase):
|
|
5
|
+
def test_polygon_3(self):
|
|
6
|
+
p = (1.0, 1.0)
|
|
7
|
+
poly = Polygon([p, p, p])
|
|
8
|
+
self.failUnlessEqual(poly.bounds, (1.0, 1.0, 1.0, 1.0))
|
|
9
|
+
def test_polygon_5(self):
|
|
10
|
+
p = (1.0, 1.0)
|
|
11
|
+
poly = Polygon([p, p, p, p, p])
|
|
12
|
+
self.failUnlessEqual(poly.bounds, (1.0, 1.0, 1.0, 1.0))
|
|
13
|
+
|
|
14
|
+
def test_suite():
|
|
15
|
+
return unittest.TestLoader().loadTestsFromTestCase(PolygonTestCase)
|
|
Binary file
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
|
|
3
|
+
from shapely import speedups
|
|
4
|
+
from shapely.geometry import LineString, Polygon
|
|
5
|
+
|
|
6
|
+
class SpeedupsTestCase(unittest.TestCase):
|
|
7
|
+
|
|
8
|
+
def setUp(self):
|
|
9
|
+
self.assertFalse(speedups._orig)
|
|
10
|
+
speedups.enable()
|
|
11
|
+
self.assertTrue(speedups._orig)
|
|
12
|
+
|
|
13
|
+
def tearDown(self):
|
|
14
|
+
self.assertTrue(speedups._orig)
|
|
15
|
+
speedups.disable()
|
|
16
|
+
self.assertFalse(speedups._orig)
|
|
17
|
+
|
|
18
|
+
def test_create_linestring(self):
|
|
19
|
+
ls = LineString([(0, 0), (1, 0), (1, 2)])
|
|
20
|
+
self.assertEqual(ls.length, 3)
|
|
21
|
+
|
|
22
|
+
def test_create_polygon(self):
|
|
23
|
+
p = Polygon([(0, 0), (2, 0), (2, 2), (0, 2)])
|
|
24
|
+
self.assertEqual(p.length, 8)
|
|
25
|
+
|
|
26
|
+
def test_create_polygon_from_linestring(self):
|
|
27
|
+
ls = LineString([(0, 0), (2, 0), (2, 2), (0, 2)])
|
|
28
|
+
p = Polygon(ls)
|
|
29
|
+
self.assertEqual(p.length, 8)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def test_suite():
|
|
33
|
+
if speedups.available:
|
|
34
|
+
return unittest.TestLoader().loadTestsFromTestCase(
|
|
35
|
+
SpeedupsTestCase
|
|
36
|
+
)
|
|
37
|
+
else:
|
|
38
|
+
return lambda x: None
|
|
Binary file
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely.geometry import *
|
|
3
|
+
from shapely.validation import explain_validity
|
|
4
|
+
|
|
5
|
+
class ValidationTestCase(unittest.TestCase):
|
|
6
|
+
def test_valid(self):
|
|
7
|
+
self.failUnlessEqual(explain_validity(Point(0, 0)), 'Valid Geometry')
|
|
8
|
+
|
|
9
|
+
def test_suite():
|
|
10
|
+
return unittest.TestLoader().loadTestsFromTestCase(ValidationTestCase)
|
|
Binary file
|
shapely/tests/test_xy.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import unittest
|
|
2
|
+
from shapely import geometry
|
|
3
|
+
|
|
4
|
+
class XYTestCase(unittest.TestCase):
|
|
5
|
+
"""New geometry/coordseq method 'xy' makes numpy interop easier"""
|
|
6
|
+
def test_arrays(self):
|
|
7
|
+
x, y = geometry.LineString(((0, 0), (1, 1))).xy
|
|
8
|
+
self.failUnless(len(x) == 2)
|
|
9
|
+
self.failUnless(list(x) == [0.0, 1.0])
|
|
10
|
+
self.failUnless(len(y) == 2)
|
|
11
|
+
self.failUnless(list(y) == [0.0, 1.0])
|
|
12
|
+
|
|
13
|
+
def test_suite():
|
|
14
|
+
return unittest.TestLoader().loadTestsFromTestCase(XYTestCase)
|
|
Binary file
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import threading
|
|
2
|
+
|
|
3
|
+
def main():
|
|
4
|
+
num_threads = 10
|
|
5
|
+
use_threads = True
|
|
6
|
+
|
|
7
|
+
if not use_threads:
|
|
8
|
+
# Run core code
|
|
9
|
+
runShapelyBuilding()
|
|
10
|
+
else:
|
|
11
|
+
threads = [threading.Thread(target=runShapelyBuilding, name=str(i), args=(i,)) for i in range(num_threads)]
|
|
12
|
+
for t in threads:
|
|
13
|
+
t.start()
|
|
14
|
+
for t in threads:
|
|
15
|
+
t.join()
|
|
16
|
+
|
|
17
|
+
def runShapelyBuilding(num):
|
|
18
|
+
print "%s: Running shapely tests on wkb" % num
|
|
19
|
+
import shapely.geos
|
|
20
|
+
print "%s GEOS Handle: %s" % (num, shapely.geos.lgeos.geos_handle)
|
|
21
|
+
import shapely.wkt
|
|
22
|
+
import shapely.wkb
|
|
23
|
+
p = shapely.wkt.loads("POINT (0 0)")
|
|
24
|
+
print "%s WKT: %s" % (num, shapely.wkt.dumps(p))
|
|
25
|
+
wkb = shapely.wkb.dumps(p)
|
|
26
|
+
print "%s WKB: %s" % (num, wkb.encode('hex'))
|
|
27
|
+
|
|
28
|
+
for i in xrange(10):
|
|
29
|
+
obj = shapely.wkb.loads(wkb)
|
|
30
|
+
|
|
31
|
+
print "%s GEOS Handle: %s" % (num, shapely.geos.lgeos.geos_handle)
|
|
32
|
+
print "Done %s" % num
|
|
33
|
+
|
|
34
|
+
# Run main
|
|
35
|
+
if __name__ == '__main__':
|
|
36
|
+
main()
|
|
37
|
+
|
|
Binary file
|
shapely/topology.py
CHANGED
|
@@ -10,14 +10,12 @@ These methods return ctypes objects that should be recast by the caller.
|
|
|
10
10
|
from ctypes import byref, c_double
|
|
11
11
|
from shapely.geos import TopologicalError, lgeos
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
class Validating(object):
|
|
15
|
-
def _validate(self, ob):
|
|
16
|
-
|
|
17
|
-
assert ob is not None
|
|
18
|
-
assert ob._geom is not None
|
|
19
|
-
except AssertionError:
|
|
14
|
+
def _validate(self, ob, stop_prepared=False):
|
|
15
|
+
if ob is None or ob._geom is None:
|
|
20
16
|
raise ValueError("Null geometry supports no operations")
|
|
17
|
+
if stop_prepared and not hasattr(ob, 'type'):
|
|
18
|
+
raise ValueError("Prepared geometries cannot be operated on")
|
|
21
19
|
|
|
22
20
|
class Delegating(Validating):
|
|
23
21
|
def __init__(self, name):
|
|
@@ -26,7 +24,7 @@ class Delegating(Validating):
|
|
|
26
24
|
class BinaryRealProperty(Delegating):
|
|
27
25
|
def __call__(self, this, other):
|
|
28
26
|
self._validate(this)
|
|
29
|
-
self._validate(other)
|
|
27
|
+
self._validate(other, stop_prepared=True)
|
|
30
28
|
d = c_double()
|
|
31
29
|
retval = self.fn(this._geom, other._geom, byref(d))
|
|
32
30
|
return d.value
|
|
@@ -41,7 +39,7 @@ class UnaryRealProperty(Delegating):
|
|
|
41
39
|
class BinaryTopologicalOp(Delegating):
|
|
42
40
|
def __call__(self, this, other, *args):
|
|
43
41
|
self._validate(this)
|
|
44
|
-
self._validate(other)
|
|
42
|
+
self._validate(other, stop_prepared=True)
|
|
45
43
|
product = self.fn(this._geom, other._geom, *args)
|
|
46
44
|
if product is None:
|
|
47
45
|
if not this.is_valid:
|
shapely/topology.pyc
CHANGED
|
Binary file
|
shapely/wkb.py
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"""Load/dump geometries using the well-known binary (WKB) format
|
|
2
2
|
"""
|
|
3
3
|
|
|
4
|
-
from ctypes import
|
|
4
|
+
from ctypes import pointer, c_size_t, c_char_p, c_void_p
|
|
5
5
|
|
|
6
6
|
from shapely.geos import lgeos, ReadingError
|
|
7
7
|
|
|
@@ -30,7 +30,7 @@ def dumps(ob):
|
|
|
30
30
|
if ob is None or ob._geom is None:
|
|
31
31
|
raise ValueError("Null geometry supports no operations")
|
|
32
32
|
size = c_size_t()
|
|
33
|
-
return lgeos.GEOSGeomToWKB_buf(c_void_p(ob._geom),
|
|
33
|
+
return lgeos.GEOSGeomToWKB_buf(c_void_p(ob._geom), pointer(size))
|
|
34
34
|
|
|
35
35
|
def dump(ob, fp):
|
|
36
36
|
"""Dump a geometry to an open file."""
|
shapely/wkb.pyc
CHANGED
|
Binary file
|