shapely 1.2.10__py2.6-win-amd64.egg → 1.2.13__py2.6-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 (80) hide show
  1. EGG-INFO/PKG-INFO +48 -29
  2. EGG-INFO/native_libs.txt +1 -0
  3. EGG-INFO/not-zip-safe +1 -1
  4. shapely/__init__.py +2 -1
  5. shapely/__init__.pyc +0 -0
  6. shapely/ctypes_declarations.py +5 -0
  7. shapely/ctypes_declarations.pyc +0 -0
  8. shapely/examples/__init__.py +1 -0
  9. shapely/examples/__init__.pyc +0 -0
  10. shapely/examples/dissolve.py +53 -0
  11. shapely/examples/dissolve.pyc +0 -0
  12. shapely/examples/geoms.py +51 -0
  13. shapely/examples/geoms.pyc +0 -0
  14. shapely/examples/intersect.py +81 -0
  15. shapely/examples/intersect.pyc +0 -0
  16. shapely/examples/world.py +21 -0
  17. shapely/examples/world.pyc +0 -0
  18. shapely/geometry/base.py +4 -1
  19. shapely/geometry/base.pyc +0 -0
  20. shapely/geometry/linestring.py +8 -13
  21. shapely/geometry/linestring.pyc +0 -0
  22. shapely/geometry/multilinestring.py +0 -3
  23. shapely/geometry/multilinestring.pyc +0 -0
  24. shapely/geometry/multipoint.py +3 -2
  25. shapely/geometry/multipoint.pyc +0 -0
  26. shapely/geometry/polygon.py +19 -39
  27. shapely/geometry/polygon.pyc +0 -0
  28. shapely/geos.py +8 -7
  29. shapely/geos.pyc +0 -0
  30. shapely/predicates.py +2 -2
  31. shapely/predicates.pyc +0 -0
  32. shapely/prepared.py +4 -1
  33. shapely/prepared.pyc +0 -0
  34. shapely/speedups/__init__.py +42 -0
  35. shapely/speedups/__init__.pyc +0 -0
  36. shapely/speedups/_speedups.py +7 -0
  37. shapely/speedups/_speedups.pyc +0 -0
  38. shapely/speedups/_speedups.pyd +0 -0
  39. shapely/tests/__init__.py +28 -0
  40. shapely/tests/__init__.pyc +0 -0
  41. shapely/tests/test_box.py +19 -0
  42. shapely/tests/test_box.pyc +0 -0
  43. shapely/tests/test_cga.py +33 -0
  44. shapely/tests/test_cga.pyc +0 -0
  45. shapely/tests/test_collection.py +11 -0
  46. shapely/tests/test_collection.pyc +0 -0
  47. shapely/tests/test_delegated.py +26 -0
  48. shapely/tests/test_delegated.pyc +0 -0
  49. shapely/tests/test_dlls.py +16 -0
  50. shapely/tests/test_dlls.pyc +0 -0
  51. shapely/tests/test_doctests.py +35 -0
  52. shapely/tests/test_doctests.pyc +0 -0
  53. shapely/tests/test_emptiness.py +19 -0
  54. shapely/tests/test_emptiness.pyc +0 -0
  55. shapely/tests/test_equality.py +30 -0
  56. shapely/tests/test_equality.pyc +0 -0
  57. shapely/tests/test_geomseq.py +11 -0
  58. shapely/tests/test_geomseq.pyc +0 -0
  59. shapely/tests/test_linear_referencing.py +67 -0
  60. shapely/tests/test_linear_referencing.pyc +0 -0
  61. shapely/tests/test_mapping.py +11 -0
  62. shapely/tests/test_mapping.pyc +0 -0
  63. shapely/tests/test_prepared.py +28 -0
  64. shapely/tests/test_prepared.pyc +0 -0
  65. shapely/tests/test_products_z.py +14 -0
  66. shapely/tests/test_products_z.pyc +0 -0
  67. shapely/tests/test_singularity.py +15 -0
  68. shapely/tests/test_singularity.pyc +0 -0
  69. shapely/tests/test_speedups.py +38 -0
  70. shapely/tests/test_speedups.pyc +0 -0
  71. shapely/tests/test_validation.py +10 -0
  72. shapely/tests/test_validation.pyc +0 -0
  73. shapely/tests/test_xy.py +14 -0
  74. shapely/tests/test_xy.pyc +0 -0
  75. shapely/tests/threading_test.py +37 -0
  76. shapely/tests/threading_test.pyc +0 -0
  77. shapely/topology.py +6 -8
  78. shapely/topology.pyc +0 -0
  79. shapely/wkb.py +2 -2
  80. shapely/wkb.pyc +0 -0
shapely/geos.py CHANGED
@@ -12,7 +12,7 @@ from ctypes import cdll, CDLL, CFUNCTYPE, c_char_p, c_void_p, string_at
12
12
  from ctypes.util import find_library
13
13
 
14
14
  import ftools
15
- from ctypes_declarations import prototype
15
+ from ctypes_declarations import prototype, EXCEPTION_HANDLER_FUNCTYPE
16
16
 
17
17
 
18
18
 
@@ -43,7 +43,7 @@ def load_dll(libname, fallbacks=None):
43
43
  "Could not find library %s or load any of its variants %s" % (
44
44
  libname, fallbacks or []))
45
45
 
46
- if sys.platform == 'linux2':
46
+ if sys.platform.startswith('linux'):
47
47
  _lgeos = load_dll('geos_c', fallbacks=['libgeos_c.so.1', 'libgeos_c.so'])
48
48
  free = load_dll('c').free
49
49
  free.argtypes = [c_void_p]
@@ -64,7 +64,7 @@ elif sys.platform == 'darwin':
64
64
  elif sys.platform == 'win32':
65
65
  try:
66
66
  egg_dlls = os.path.abspath(os.path.join(os.path.dirname(__file__),
67
- r"..\DLLs"))
67
+ r"..\DLLs"))
68
68
  wininst_dlls = os.path.abspath(os.__file__ + "../../../DLLs")
69
69
  original_path = os.environ['PATH']
70
70
  os.environ['PATH'] = "%s;%s;%s" % (egg_dlls, wininst_dlls, original_path)
@@ -92,6 +92,7 @@ else: # other *nix systems
92
92
 
93
93
  def _geos_c_version():
94
94
  func = _lgeos.GEOSversion
95
+ func.argtypes = []
95
96
  func.restype = c_char_p
96
97
  v = func().split('-')[2]
97
98
  return tuple(int(n) for n in v.split('.'))
@@ -129,7 +130,7 @@ if geos_c_version >= (1,5,0):
129
130
 
130
131
  # Handle special case.
131
132
  _lgeos.initGEOS_r.restype = c_void_p
132
- _lgeos.initGEOS_r.argtypes = [c_void_p, c_void_p]
133
+ _lgeos.initGEOS_r.argtypes = [EXCEPTION_HANDLER_FUNCTYPE, EXCEPTION_HANDLER_FUNCTYPE]
133
134
  _lgeos.finishGEOS_r.argtypes = [c_void_p]
134
135
 
135
136
  # Exceptions
@@ -148,11 +149,11 @@ class PredicateError(Exception):
148
149
 
149
150
  def error_handler(fmt, list):
150
151
  LOG.error("%s", list)
151
- error_h = CFUNCTYPE(None, c_char_p, c_char_p)(error_handler)
152
+ error_h = EXCEPTION_HANDLER_FUNCTYPE(error_handler)
152
153
 
153
154
  def notice_handler(fmt, list):
154
155
  LOG.warning("%s", list)
155
- notice_h = CFUNCTYPE(None, c_char_p, c_char_p)(notice_handler)
156
+ notice_h = EXCEPTION_HANDLER_FUNCTYPE(notice_handler)
156
157
 
157
158
  def cleanup():
158
159
  if _lgeos is not None :
@@ -166,7 +167,7 @@ def errcheck_wkb(result, func, argtuple):
166
167
  if not result:
167
168
  return None
168
169
  size_ref = argtuple[-1]
169
- size = size_ref._obj
170
+ size = size_ref.contents
170
171
  retval = ctypes.string_at(result, size.value)[:]
171
172
  lgeos.GEOSFree(result)
172
173
  return retval
shapely/geos.pyc CHANGED
Binary file
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