shapely 1.2.10__py2.7-win-amd64.egg → 1.2.13__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.
Files changed (79) hide show
  1. EGG-INFO/PKG-INFO +48 -29
  2. EGG-INFO/native_libs.txt +1 -0
  3. shapely/__init__.py +2 -1
  4. shapely/__init__.pyc +0 -0
  5. shapely/ctypes_declarations.py +5 -0
  6. shapely/ctypes_declarations.pyc +0 -0
  7. shapely/examples/__init__.py +1 -0
  8. shapely/examples/__init__.pyc +0 -0
  9. shapely/examples/dissolve.py +53 -0
  10. shapely/examples/dissolve.pyc +0 -0
  11. shapely/examples/geoms.py +51 -0
  12. shapely/examples/geoms.pyc +0 -0
  13. shapely/examples/intersect.py +81 -0
  14. shapely/examples/intersect.pyc +0 -0
  15. shapely/examples/world.py +21 -0
  16. shapely/examples/world.pyc +0 -0
  17. shapely/geometry/base.py +4 -1
  18. shapely/geometry/base.pyc +0 -0
  19. shapely/geometry/linestring.py +8 -13
  20. shapely/geometry/linestring.pyc +0 -0
  21. shapely/geometry/multilinestring.py +0 -3
  22. shapely/geometry/multilinestring.pyc +0 -0
  23. shapely/geometry/multipoint.py +3 -2
  24. shapely/geometry/multipoint.pyc +0 -0
  25. shapely/geometry/polygon.py +19 -39
  26. shapely/geometry/polygon.pyc +0 -0
  27. shapely/geos.py +8 -7
  28. shapely/geos.pyc +0 -0
  29. shapely/predicates.py +2 -2
  30. shapely/predicates.pyc +0 -0
  31. shapely/prepared.py +4 -1
  32. shapely/prepared.pyc +0 -0
  33. shapely/speedups/__init__.py +42 -0
  34. shapely/speedups/__init__.pyc +0 -0
  35. shapely/speedups/_speedups.py +7 -0
  36. shapely/speedups/_speedups.pyc +0 -0
  37. shapely/speedups/_speedups.pyd +0 -0
  38. shapely/tests/__init__.py +28 -0
  39. shapely/tests/__init__.pyc +0 -0
  40. shapely/tests/test_box.py +19 -0
  41. shapely/tests/test_box.pyc +0 -0
  42. shapely/tests/test_cga.py +33 -0
  43. shapely/tests/test_cga.pyc +0 -0
  44. shapely/tests/test_collection.py +11 -0
  45. shapely/tests/test_collection.pyc +0 -0
  46. shapely/tests/test_delegated.py +26 -0
  47. shapely/tests/test_delegated.pyc +0 -0
  48. shapely/tests/test_dlls.py +16 -0
  49. shapely/tests/test_dlls.pyc +0 -0
  50. shapely/tests/test_doctests.py +35 -0
  51. shapely/tests/test_doctests.pyc +0 -0
  52. shapely/tests/test_emptiness.py +19 -0
  53. shapely/tests/test_emptiness.pyc +0 -0
  54. shapely/tests/test_equality.py +30 -0
  55. shapely/tests/test_equality.pyc +0 -0
  56. shapely/tests/test_geomseq.py +11 -0
  57. shapely/tests/test_geomseq.pyc +0 -0
  58. shapely/tests/test_linear_referencing.py +67 -0
  59. shapely/tests/test_linear_referencing.pyc +0 -0
  60. shapely/tests/test_mapping.py +11 -0
  61. shapely/tests/test_mapping.pyc +0 -0
  62. shapely/tests/test_prepared.py +28 -0
  63. shapely/tests/test_prepared.pyc +0 -0
  64. shapely/tests/test_products_z.py +14 -0
  65. shapely/tests/test_products_z.pyc +0 -0
  66. shapely/tests/test_singularity.py +15 -0
  67. shapely/tests/test_singularity.pyc +0 -0
  68. shapely/tests/test_speedups.py +38 -0
  69. shapely/tests/test_speedups.pyc +0 -0
  70. shapely/tests/test_validation.py +10 -0
  71. shapely/tests/test_validation.pyc +0 -0
  72. shapely/tests/test_xy.py +14 -0
  73. shapely/tests/test_xy.pyc +0 -0
  74. shapely/tests/threading_test.py +37 -0
  75. shapely/tests/threading_test.pyc +0 -0
  76. shapely/topology.py +6 -8
  77. shapely/topology.pyc +0 -0
  78. shapely/wkb.py +2 -2
  79. shapely/wkb.pyc +0 -0
shapely/predicates.py CHANGED
@@ -7,13 +7,13 @@ from shapely.topology import Delegating
7
7
  class BinaryPredicate(Delegating):
8
8
  def __call__(self, this, other, *args):
9
9
  self._validate(this)
10
- self._validate(other)
10
+ self._validate(other, stop_prepared=True)
11
11
  return self.fn(this._geom, other._geom, *args)
12
12
 
13
13
  class RelateOp(Delegating):
14
14
  def __call__(self, this, other):
15
15
  self._validate(this)
16
- self._validate(other)
16
+ self._validate(other, stop_prepared=True)
17
17
  return self.fn(this._geom, other._geom)
18
18
 
19
19
  class UnaryPredicate(Delegating):
shapely/predicates.pyc CHANGED
Binary file
shapely/prepared.py CHANGED
@@ -27,7 +27,10 @@ class PreparedGeometry(object):
27
27
 
28
28
  def __del__(self):
29
29
  if self.__geom__ is not None:
30
- lgeos.GEOSPreparedGeom_destroy(self.__geom__)
30
+ try:
31
+ lgeos.GEOSPreparedGeom_destroy(self.__geom__)
32
+ except AttributeError:
33
+ pass # lgeos might be empty on shutdown
31
34
  self.__geom__ = None
32
35
  self.context = None
33
36
 
shapely/prepared.pyc CHANGED
Binary file
@@ -0,0 +1,42 @@
1
+ import warnings
2
+
3
+ from shapely.geometry import linestring, polygon
4
+ from shapely import coords
5
+
6
+ try:
7
+ from shapely.speedups import _speedups
8
+ available = True
9
+ import_error_msg = None
10
+ except ImportError:
11
+ import sys
12
+ available = False
13
+ import_error_msg = tuple(sys.exc_info()[1])
14
+
15
+ __all__ = ['available', 'enable', 'disable']
16
+ _orig = {}
17
+
18
+ def enable():
19
+ if not available:
20
+ warnings.warn("shapely.speedups not available", RuntimeWarning)
21
+ return
22
+
23
+ if _orig:
24
+ return
25
+
26
+ _orig['CoordinateSequence.ctypes'] = coords.CoordinateSequence.ctypes
27
+ coords.CoordinateSequence.ctypes = property(_speedups.coordseq_ctypes)
28
+
29
+ _orig['geos_linestring_from_py'] = linestring.geos_linestring_from_py
30
+ linestring.geos_linestring_from_py = _speedups.geos_linestring_from_py
31
+
32
+ _orig['geos_linearring_from_py'] = polygon.geos_linearring_from_py
33
+ polygon.geos_linearring_from_py = _speedups.geos_linearring_from_py
34
+
35
+ def disable():
36
+ if not _orig:
37
+ return
38
+
39
+ coords.CoordinateSequence.ctypes = _orig['CoordinateSequence.ctypes']
40
+ linestring.geos_linestring_from_py = _orig['geos_linestring_from_py']
41
+ polygon.geos_linearring_from_py = _orig['geos_linearring_from_py']
42
+ _orig.clear()
Binary file
@@ -0,0 +1,7 @@
1
+ def __bootstrap__():
2
+ global __bootstrap__, __loader__, __file__
3
+ import sys, pkg_resources, imp
4
+ __file__ = pkg_resources.resource_filename(__name__,'_speedups.pyd')
5
+ __loader__ = None; del __bootstrap__, __loader__
6
+ imp.load_dynamic(__name__,__file__)
7
+ __bootstrap__()
Binary file
Binary file
@@ -0,0 +1,28 @@
1
+ from unittest import TestSuite
2
+
3
+ import test_doctests, test_prepared, test_equality, test_geomseq, test_xy
4
+ import test_collection, test_emptiness, test_singularity, test_validation
5
+ import test_mapping, test_delegated, test_dlls, test_linear_referencing
6
+ import test_products_z, test_box, test_speedups, test_cga
7
+
8
+ def test_suite():
9
+ suite = TestSuite()
10
+ suite.addTest(test_doctests.test_suite())
11
+ suite.addTest(test_prepared.test_suite())
12
+ suite.addTest(test_emptiness.test_suite())
13
+ suite.addTest(test_equality.test_suite())
14
+ suite.addTest(test_geomseq.test_suite())
15
+ suite.addTest(test_xy.test_suite())
16
+ suite.addTest(test_collection.test_suite())
17
+ suite.addTest(test_singularity.test_suite())
18
+ suite.addTest(test_validation.test_suite())
19
+ suite.addTest(test_mapping.test_suite())
20
+ suite.addTest(test_delegated.test_suite())
21
+ suite.addTest(test_dlls.test_suite())
22
+ suite.addTest(test_linear_referencing.test_suite())
23
+ suite.addTest(test_products_z.test_suite())
24
+ suite.addTest(test_box.test_suite())
25
+ suite.addTest(test_speedups.test_suite())
26
+ suite.addTest(test_cga.test_suite())
27
+ return suite
28
+
Binary file
@@ -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
+ )
@@ -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
@@ -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