2014-01-08 06:46:50 +00:00
|
|
|
from shapely.geometry import *
|
|
|
|
import unittest
|
|
|
|
|
|
|
|
from descartes.patch import PolygonPatch
|
|
|
|
|
|
|
|
class PolygonTestCase(unittest.TestCase):
|
|
|
|
polygon = Point(0, 0).buffer(10.0).difference(
|
|
|
|
MultiPoint([(-5, 0), (5, 0)]).buffer(3.0))
|
|
|
|
def test_patch(self):
|
|
|
|
patch = PolygonPatch(self.polygon)
|
2018-05-26 01:43:40 +00:00
|
|
|
self.assertEqual(str(type(patch)),
|
2014-01-08 06:46:50 +00:00
|
|
|
"<class 'matplotlib.patches.PathPatch'>")
|
|
|
|
path = patch.get_path()
|
2018-05-26 01:43:40 +00:00
|
|
|
self.assertTrue(len(path.vertices) == len(path.codes) == 198)
|
2014-01-08 06:46:50 +00:00
|
|
|
|
|
|
|
class JSONPolygonTestCase(unittest.TestCase):
|
|
|
|
polygon = Point(0, 0).buffer(10.0).difference(
|
|
|
|
MultiPoint([(-5, 0), (5, 0)]).buffer(3.0))
|
|
|
|
def test_patch(self):
|
|
|
|
geo = self.polygon.__geo_interface__
|
|
|
|
patch = PolygonPatch(geo)
|
2018-05-26 01:43:40 +00:00
|
|
|
self.assertEqual(str(type(patch)),
|
2014-01-08 06:46:50 +00:00
|
|
|
"<class 'matplotlib.patches.PathPatch'>")
|
|
|
|
path = patch.get_path()
|
2018-05-26 01:43:40 +00:00
|
|
|
self.assertTrue(len(path.vertices) == len(path.codes) == 198)
|
2014-01-08 06:46:50 +00:00
|
|
|
|
|
|
|
class GeoInterfacePolygonTestCase(unittest.TestCase):
|
|
|
|
class GeoThing:
|
|
|
|
__geo_interface__ = None
|
|
|
|
thing = GeoThing()
|
|
|
|
thing.__geo_interface__ = Point(0, 0).buffer(10.0).difference(
|
|
|
|
MultiPoint([(-5, 0), (5, 0)]).buffer(3.0)).__geo_interface__
|
|
|
|
def test_patch(self):
|
|
|
|
patch = PolygonPatch(self.thing)
|
2018-05-26 01:43:40 +00:00
|
|
|
self.assertEqual(str(type(patch)),
|
2014-01-08 06:46:50 +00:00
|
|
|
"<class 'matplotlib.patches.PathPatch'>")
|
|
|
|
path = patch.get_path()
|
2018-05-26 01:43:40 +00:00
|
|
|
self.assertTrue(len(path.vertices) == len(path.codes) == 198)
|