def test_sitenode_attribution_and_accessors(self): mainsite = SiteNode(self.big_rect_coords, id="{Main site ID}") subsite = SiteNode(self.subsite_A_coords, id="{Subsite ID}", parent_site=mainsite) level_curve_B = LevelCurve(self.level_curve_B_coords, altitude=20.0, parent_site=subsite, id=None) level_curve_A = LevelCurve(self.level_curve_A_coords, altitude=10.0, parent_site=mainsite, id=None) waterbody = WaterBody(self.waterbody_coords, altitude=5, parent_site=mainsite, id=None) vegarea = VegetationArea([(1, 1), (1, 3), (3, 1)], material=GroundMaterial('pine'), height=3, id=None) vegarea.parent_site = mainsite mainsite.add_child(self.material_area_A) self.assertCountEqual(mainsite.level_curves, [level_curve_A, waterbody]) self.assertCountEqual(mainsite.material_areas, [self.material_area_A, waterbody, vegarea]) self.assertCountEqual(mainsite.subsites, [subsite]) self.assertCountEqual(subsite.level_curves, [level_curve_B])
def build_features(self): self.mainsite = SiteNode(self.big_rect_coords, id="{Main site ID}") self.level_curve_A = LevelCurve(self.level_curve_A_coords, altitude=self.altitude_A, parent_site=self.mainsite, id="{Level curve A}") self.grass_area = MaterialArea(self.grass_area_coords, material=self.grass, parent_site=self.mainsite, id="{Grass area}") self.veg_area = VegetationArea(self.pine_area_coords, material=self.pine, height=5, parent_site=self.mainsite, id="{Pine area}") self.waterbody = WaterBody(self.waterbody_coords, altitude=self.altitude_water, parent_site=self.mainsite, id="{Water body}") self.subsite = SiteNode(self.subsite_A_coords, id="{Subsite ID}", parent_site=self.mainsite) self.level_curve_B = LevelCurve(self.level_curve_B_coords, altitude=self.altitude_B, parent_site=self.subsite, id="{Level curve B}") self.out_of_subsite = MaterialArea(rect(9, 9, 10, 10), material=self.grass, parent_site=self.subsite, id="{Out of subsite area}") self.building = InfrastructureLandtake(self.landtake_coords, parent_site=self.mainsite, id="{Building}")
def test_parent_site(self): level_curve_B = LevelCurve(self.level_curve_B_coords, altitude=20.0, id=None) self.assertIsNone(self.subsite_A.parent_site) level_curve_B.parent_site = self.subsite_A self.assertIn(level_curve_B, self.subsite_A.children["LevelCurve"]) del level_curve_B.parent_site self.assertNotIn(level_curve_B, self.subsite_A.children['LevelCurve'])
def build_more_features_in_subsites(self): self.subsubsite = SiteNode(rect(6, 6.5, 7, 7.5), id="{SubSubsite ID}", parent_site=self.subsite) self.sub_level_curve = LevelCurve([(6.5, 5), (6.5, 9)], altitude=6.0, id="{Cut level curve}", parent_site=self.subsite) self.subsub_level_curve = LevelCurve([(5, 5.5), (8, 8.5)], altitude=7.0, id="{Subsub level curve}", parent_site=self.subsubsite)
def test_site_belonging(self): self.assertIsNone(self.subsite_A.parent_site) level_curve_B = LevelCurve(self.level_curve_B_coords, altitude=20.0, parent_site=self.subsite_A, id=None) self.assertIn(level_curve_B, self.subsite_A.children["LevelCurve"]) self.assertEqual(level_curve_B.parent_site_id, "{Sub-site A ID}")
def setUp(self): TestFeatures.build_features(self) TestFeatures.build_more_features_in_subsites(self) # NB Level curve A intersects this one : altitudes must be the same self.landtake_level_curve = LevelCurve(self.big_rect_coords, altitude=self.altitude_A, close_it=True, parent_site=self.mainsite, id="{Mainsite ref altitude}")
def test_cached_shape_property(self): level_curve_B = LevelCurve(self.level_curve_B_coords, altitude=20.0, id=None) self.assertIsNone(level_curve_B._shape) shape = level_curve_B.shape self.assertTrue(shape.equals(level_curve_B.as_shape)) self.assertIs(shape, level_curve_B._shape)
def test_elementary_shapes(self): mainsite = SiteNode(self.big_rect_coords, id="{Main site ID}") mls = MultiLineString([[(0.0, 0.0), (1.0, 0.0)], [(1.0, 1.0), (1.0, 2.0)]]) ls1 = LineString([(0.0, 0.0), (1.0, 0.0)]) ls2 = LineString([(1.0, 1.0), (1.0, 2.0)]) level_curve = LevelCurve(mls, altitude=10.0, parent_site=mainsite, id=None) shapes = elementary_shapes(level_curve.shape) self.assertEqual(len(shapes), 2) for shape in shapes: self.assertTrue(ls1.equals(shape) or ls2.equals(shape))
def test_intersecting_level_curves_error(self): # build a new level curve that intersects site landtake level curve and # has a different altitude other_level_curve_coords = [(-2, -3), (1, 2)] level_curve = LevelCurve(other_level_curve_coords, altitude=20., parent_site=self.mainsite, id="{Other level curve}") cleaner = builder.recursively_merge_all_subsites(self.mainsite) msite = cleaner.merged_site() mbuilder = builder.MeshBuilder(msite) with self.assertRaises(InconsistentGeometricModel) as cm: bmesh = mbuilder.build_mesh(refine=False) self.assertEqual( str(cm.exception), "Intersecting constraints with different altitudes: " "['{Mainsite ref altitude}', '{Other level curve}'] at (0.0, 0.33333333333333337)" )
class AltimetryDataTC(unittest.TestCase): big_rect_coords = rect(0, 0, 12, 10) level_curve_A_coords = [(0, 0), (2.5, 3.5), (4, 4.0)] level_curve_A = LevelCurve(level_curve_A_coords, altitude=10.0, id="{123456}") level_curve_A_json = ( '{"geometry": {"coordinates": [[[0.0, 0.0], [2.5, 3.5], [4.0, 4.0]]],' ' "type": "MultiLineString"}, "id": "{123456}",' ' "properties": {"altitude": 10.0, "type": "LevelCurve"},' ' "type": "Feature"}') material_area_A_coords = big_rect_coords grass = GroundMaterial("grass") material_area_A = MaterialArea(material_area_A_coords, material=grass, id=None) material_area_A_json = ( '{"geometry": {' '"coordinates": [[[0.0, 0.0], [12.0, 0.0], [12.0, 10.0], [0.0, 10.0]]],' ' "type": "Polygon"},' ' "properties": {"material": "grass", "type": "MaterialArea"},' ' "type": "Feature"}') waterbody_coords = [(3, 3), (5, 4), (3, 5)] subsite_A_coords = [(8.0, 4.0), (8.0, 7.0), (12.0, 7.0)] subsite_A = SiteNode(subsite_A_coords, id='{Sub-site A ID}') level_curve_B_coords = [(8.0, 4.0), (8.0, 7.0), (12.0, 7.0)] def test_LevelCurve_as_json(self): self.assertEqual(self.level_curve_A.as_geojson, self.level_curve_A_json) def test_MaterialArea_as_json(self): self.assertEqual(self.material_area_A.as_geojson, self.material_area_A_json) def test_LevelCurve_as_shape(self): shape = self.level_curve_A.as_shape self.assertTrue( shape.equals(geometry.LineString(self.level_curve_A_coords))) def test_MaterialArea_as_shape(self): shape = geometry.shape(self.material_area_A) self.assertTrue( shape.equals(geometry.Polygon(self.material_area_A_coords))) def test_SiteNode_as_shape(self): shape = geometry.shape(self.subsite_A) self.assertTrue(shape.equals(geometry.Polygon(self.subsite_A_coords))) def test_site_belonging(self): self.assertIsNone(self.subsite_A.parent_site) level_curve_B = LevelCurve(self.level_curve_B_coords, altitude=20.0, parent_site=self.subsite_A, id=None) self.assertIn(level_curve_B, self.subsite_A.children["LevelCurve"]) self.assertEqual(level_curve_B.parent_site_id, "{Sub-site A ID}") def test_parent_site(self): level_curve_B = LevelCurve(self.level_curve_B_coords, altitude=20.0, id=None) self.assertIsNone(self.subsite_A.parent_site) level_curve_B.parent_site = self.subsite_A self.assertIn(level_curve_B, self.subsite_A.children["LevelCurve"]) del level_curve_B.parent_site self.assertNotIn(level_curve_B, self.subsite_A.children['LevelCurve']) def test_cached_shape_property(self): level_curve_B = LevelCurve(self.level_curve_B_coords, altitude=20.0, id=None) self.assertIsNone(level_curve_B._shape) shape = level_curve_B.shape self.assertTrue(shape.equals(level_curve_B.as_shape)) self.assertIs(shape, level_curve_B._shape) def test_polygon_validity(self): poly = PolygonalTympanFeature(self.big_rect_coords, id=None) try: poly.ensure_ok() except InconsistentGeometricModel: self.fail("poly was expected to be valid") coords = self.big_rect_coords[:] coords[1:3] = coords[2:0:-1] poly2 = PolygonalTympanFeature(coords, id="toto") with self.assertRaises(InconsistentGeometricModel) as cm: poly2.ensure_ok() self.assertEqual(cm.exception.ids, ["toto"]) self.assertIn("Self-intersection", str(cm.exception)) def test_polygon_exterior_orientation(self): coords = self.big_rect_coords[:] coords.reverse() # change orientation to CW poly = PolygonalTympanFeature(coords, id=None) self.assertTrue(poly.shape.exterior.is_ccw) def test_WaterBody_initialisation(self): waterbody = WaterBody(self.waterbody_coords, altitude=20, id=None) self.assertEqual(waterbody.altitude, 20.0) self.assertEqual(waterbody.material, MATERIAL_WATER) def test_sitenode_attribution_and_accessors(self): mainsite = SiteNode(self.big_rect_coords, id="{Main site ID}") subsite = SiteNode(self.subsite_A_coords, id="{Subsite ID}", parent_site=mainsite) level_curve_B = LevelCurve(self.level_curve_B_coords, altitude=20.0, parent_site=subsite, id=None) level_curve_A = LevelCurve(self.level_curve_A_coords, altitude=10.0, parent_site=mainsite, id=None) waterbody = WaterBody(self.waterbody_coords, altitude=5, parent_site=mainsite, id=None) vegarea = VegetationArea([(1, 1), (1, 3), (3, 1)], material=GroundMaterial('pine'), height=3, id=None) vegarea.parent_site = mainsite mainsite.add_child(self.material_area_A) self.assertCountEqual(mainsite.level_curves, [level_curve_A, waterbody]) self.assertCountEqual(mainsite.material_areas, [self.material_area_A, waterbody, vegarea]) self.assertCountEqual(mainsite.subsites, [subsite]) self.assertCountEqual(subsite.level_curves, [level_curve_B]) def test_elementary_shapes(self): mainsite = SiteNode(self.big_rect_coords, id="{Main site ID}") mls = MultiLineString([[(0.0, 0.0), (1.0, 0.0)], [(1.0, 1.0), (1.0, 2.0)]]) ls1 = LineString([(0.0, 0.0), (1.0, 0.0)]) ls2 = LineString([(1.0, 1.0), (1.0, 2.0)]) level_curve = LevelCurve(mls, altitude=10.0, parent_site=mainsite, id=None) shapes = elementary_shapes(level_curve.shape) self.assertEqual(len(shapes), 2) for shape in shapes: self.assertTrue(ls1.equals(shape) or ls2.equals(shape))