def test_split(self): to_test = [ self.fixture_polygon_with_hole, MultiPolygon( [self.fixture_polygon_with_hole, box(200, 100, 300, 400)]) ] desired_counts = {0: 4, 1: 5} for ctr, t in enumerate(to_test): ge = GeometrySplitter(t) split = ge.split() self.assertEqual(len(split), desired_counts[ctr]) self.assertEqual(split.area, t.area) actual_bounds = [g.bounds for g in split] actual_areas = [g.area for g in split] desired_bounds = [(2.0, 10.0, 3.0, 13.0), (3.0, 10.0, 4.0, 13.0), (3.0, 13.0, 4.0, 20.0), (2.0, 13.0, 3.0, 20.0)] desired_areas = [1.75, 1.75, 5.75, 5.75] if ctr == 1: desired_bounds.append((200.0, 100.0, 300.0, 400.0)) desired_areas.append(30000.0) self.assertEqual(actual_bounds, desired_bounds) self.assertEqual(actual_areas, desired_areas)
def test_split(self): to_test = [self.fixture_polygon_with_hole, MultiPolygon([self.fixture_polygon_with_hole, box(200, 100, 300, 400)])] desired_counts = {0: 4, 1: 5} for ctr, t in enumerate(to_test): ge = GeometrySplitter(t) split = ge.split() self.assertEqual(len(split), desired_counts[ctr]) self.assertEqual(split.area, t.area) actual_bounds = [g.bounds for g in split] actual_areas = [g.area for g in split] desired_bounds = [(2.0, 10.0, 3.0, 13.0), (3.0, 10.0, 4.0, 13.0), (3.0, 13.0, 4.0, 20.0), (2.0, 13.0, 3.0, 20.0)] desired_areas = [1.75, 1.75, 5.75, 5.75] if ctr == 1: desired_bounds.append((200.0, 100.0, 300.0, 400.0)) desired_areas.append(30000.0) self.assertEqual(actual_bounds, desired_bounds) self.assertEqual(actual_areas, desired_areas)
def test_init(self): ge = GeometrySplitter(self.fixture_polygon_with_hole) self.assertIsInstance(ge.geometry, Polygon) # Test a geometry with no holes. with self.assertRaises(NoInteriorsError): GeometrySplitter(box(1, 2, 3, 4))
def test_create_split_polygons(self): ge = GeometrySplitter(self.fixture_polygon_with_hole) spolygons = ge.create_split_polygons(list(ge.iter_interiors())[0]) self.assertEqual(len(spolygons), 4) actual = [sp.bounds for sp in spolygons] desired = [(1.999999, 9.999999, 3.0, 13.0), (3.0, 9.999999, 4.000001, 13.0), (3.0, 13.0, 4.000001, 20.000001), (1.999999, 13.0, 3.0, 20.000001)] self.assertEqual(actual, desired)
def test_create_split_vector_dict(self): ge = GeometrySplitter(self.fixture_polygon_with_hole) desired = [{ 'rows': (9.999999, 13.0, 20.000001), 'cols': (1.999999, 3.0, 4.000001) }] actual = list( [ge.create_split_vector_dict(i) for i in ge.iter_interiors()]) self.assertEqual(actual, desired)
def test_convert_to_geometry_coordinates_polygon_interior(self): ph = self.fixture_polygon_with_hole gvar = GeometryVariable.from_shapely(ph) desired_count = len(GeometrySplitter(ph).split()) keywords = dict(split_interiors=[True, False]) for k in self.iter_product_keywords(keywords): try: gc = gvar.convert_to(split_interiors=k.split_interiors) except ValueError: self.assertFalse(k.split_interiors) continue actual_count = gc.cindex.get_value()[0] actual_count = np.sum( actual_count == OcgisConvention.Value.MULTI_BREAK_VALUE) + 1 self.assertEqual(actual_count, desired_count)
def test_iter_interiors(self): ge = GeometrySplitter(self.fixture_polygon_with_hole) actual = list([g.bounds for g in ge.iter_interiors()]) self.assertEqual(actual, [(2.5, 10.5, 3.5, 15.5)])
def test_create_split_vector_dict(self): ge = GeometrySplitter(self.fixture_polygon_with_hole) desired = [{'rows': (9.999999, 13.0, 20.000001), 'cols': (1.999999, 3.0, 4.000001)}] actual = list([ge.create_split_vector_dict(i) for i in ge.iter_interiors()]) self.assertEqual(actual, desired)