tests.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from shapely.geometry import *
  2. import unittest
  3. from descartes.patch import PolygonPatch
  4. class PolygonTestCase(unittest.TestCase):
  5. polygon = Point(0, 0).buffer(10.0).difference(
  6. MultiPoint([(-5, 0), (5, 0)]).buffer(3.0))
  7. def test_patch(self):
  8. patch = PolygonPatch(self.polygon)
  9. self.assertEqual(str(type(patch)),
  10. "<class 'matplotlib.patches.PathPatch'>")
  11. path = patch.get_path()
  12. self.assertTrue(len(path.vertices) == len(path.codes) == 198)
  13. class JSONPolygonTestCase(unittest.TestCase):
  14. polygon = Point(0, 0).buffer(10.0).difference(
  15. MultiPoint([(-5, 0), (5, 0)]).buffer(3.0))
  16. def test_patch(self):
  17. geo = self.polygon.__geo_interface__
  18. patch = PolygonPatch(geo)
  19. self.assertEqual(str(type(patch)),
  20. "<class 'matplotlib.patches.PathPatch'>")
  21. path = patch.get_path()
  22. self.assertTrue(len(path.vertices) == len(path.codes) == 198)
  23. class GeoInterfacePolygonTestCase(unittest.TestCase):
  24. class GeoThing:
  25. __geo_interface__ = None
  26. thing = GeoThing()
  27. thing.__geo_interface__ = Point(0, 0).buffer(10.0).difference(
  28. MultiPoint([(-5, 0), (5, 0)]).buffer(3.0)).__geo_interface__
  29. def test_patch(self):
  30. patch = PolygonPatch(self.thing)
  31. self.assertEqual(str(type(patch)),
  32. "<class 'matplotlib.patches.PathPatch'>")
  33. path = patch.get_path()
  34. self.assertTrue(len(path.vertices) == len(path.codes) == 198)