CityGml import factory change to use the new format for surfaces based in polygons

This commit is contained in:
Guille Gutierrez 2021-04-06 18:06:19 -04:00
parent ba735fb53d
commit 88e43a0770
7 changed files with 37 additions and 89 deletions

View File

@ -184,7 +184,6 @@ class Polygon:
total_points_list.remove(point_to_remove)
concave_points.remove(point_to_remove)
# Was any of the adjacent points convex? -> check if changed status to concave
# for j in range(0, len(convex_points)):
for convex_point in convex_points:
if convex_point == previous_point_in_list:
concave_points, convex_points, end_loop = self._if_concave_change_status(normal, points_list,

View File

@ -15,13 +15,10 @@ class Surface:
"""
Surface class
"""
def __init__(self, solid_polygon, perimeter_polygon, holes_polygons=None, surface_type=None, name=None,
swr=None, id_number=None):
def __init__(self, solid_polygon, perimeter_polygon, holes_polygons=None, surface_type=None, swr=None):
self._type = surface_type
self._name = name
self._id = id_number
self._swr = swr
self._name = None
self._azimuth = None
self._inclination = None
self._area_above_ground = None
@ -35,16 +32,6 @@ class Surface:
self._holes_polygons = holes_polygons
self._solid_polygons = solid_polygon
def parent(self, parent, surface_id):
"""
Assign a city object as surface parent and a surface id
:param parent: CityObject
:param surface_id: str
:return: None
"""
self._parent = parent
self._name = str(surface_id)
@property
def name(self):
"""
@ -55,13 +42,6 @@ class Surface:
self._name = uuid.uuid4()
return self._name
@property
def id(self):
"""
Surface id
:return: str
"""
return self._id
@property
def swr(self):
@ -178,27 +158,6 @@ class Surface:
self._type = 'Roof'
return self._type
def add_shared(self, surface, intersection_area):
"""
Add a given surface and shared area in percent to this surface.
:param surface:
:param intersection_area:
:return:
"""
percent = intersection_area / self.perimeter_polygon.area
self._shared_surfaces.append((percent, surface))
# todo reimplement
def shared(self, surface):
"""
Check if given surface share some area with this surface
:param surface: Surface
:return: None
"""
# intersection_area = 0
# surface.add_shared(self, intersection_area)
raise NotImplementedError
@property
def global_irradiance(self) -> dict:
"""

View File

@ -24,8 +24,8 @@ class Building(CityObject):
"""
Building(CityObject) class
"""
def __init__(self, name, lod, surfaces, zones_surfaces_ids, terrains, year_of_construction, function,
city_lower_corner):
def __init__(self, name, lod, surfaces, terrains, year_of_construction, function,
city_lower_corner, zones_surfaces_ids=[]):
super().__init__(lod, surfaces, name, city_lower_corner)
self._basement_heated = None
self._attic_heated = None

View File

@ -353,9 +353,24 @@ class EnergyAde:
}
}
}
construction = None
opening_construction = None
if thermal_boundary.layers is not None:
construction = uuid.uuid4()
thermal_boundary_dic['energy:construction'] = {
'@xlink:href': f'#GML_{construction}'
}
if thermal_boundary.thermal_openings is not None:
construction = uuid.uuid4()
for opening in thermal_boundary.thermal_openings:
opening_construction = uuid.uuid4()
thermal_boundary_dic['energy:contains'] = {
'energy:ThermalOpening': {
'@gml:id': f'GML_{uuid.uuid4()}',
'energy:construction': f'#GML_{opening_construction}',
}
}
thermal_boundaries.append(thermal_boundary_dic)
return thermal_boundaries

View File

@ -131,41 +131,42 @@ class CityGml:
@staticmethod
def _lod1_solid(o):
try:
surfaces = [Surface(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']['#text']))
solid_points = [CityGml._solid_points(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']['#text']))
for s in o['Building']['lod1Solid']['Solid']['exterior']['CompositeSurface']['surfaceMember']]
except TypeError:
surfaces = [Surface(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
solid_points = [CityGml._solid_points(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['lod1Solid']['Solid']['exterior']['CompositeSurface']['surfaceMember']]
return surfaces
return [Surface(Polygon(sp),Polygon(sp)) for sp in solid_points]
@staticmethod
def _lod1_multi_surface(o):
surfaces = [Surface(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
solid_points = [CityGml._solid_points(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['lod1MultiSurface']['MultiSurface']['surfaceMember']]
return surfaces
return [Surface(Polygon(sp),Polygon(sp)) for sp in solid_points]
@staticmethod
def _lod2_solid_multi_surface(o):
surfaces = [Surface(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
polygons = [Polygon(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']))
for s in o['Building']['lod2MultiSurface']['MultiSurface']['surfaceMember']]
return surfaces
return [Surface(p,p) for p in polygons]
@staticmethod
def _lod2_composite_surface(s):
surfaces = [Surface(CityGml._remove_last_point(sm['Polygon']['exterior']['LinearRing']['posList']))
solid_points = [CityGml._solid_points((CityGml._remove_last_point(sm['Polygon']['exterior']['LinearRing']['posList'])))
for sm in s['CompositeSurface']['surfaceMember']]
return surfaces
return [Surface(Polygon(sp),Polygon(sp)) for sp in solid_points]
@staticmethod
def _lod2_multi_surface(s, surface_type):
# todo: this need to be changed into surface bounded?
try:
surfaces = [Surface(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']['#text']),
surface_type=GeometryHelper.gml_surface_to_libs(surface_type))]
solid_points = [CityGml._solid_points(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']
['#text']))]
except TypeError:
surfaces = [Surface(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']['posList']),
surface_type=GeometryHelper.gml_surface_to_libs(surface_type))]
return surfaces
solid_points = [CityGml._solid_points(CityGml._remove_last_point(s['Polygon']['exterior']['LinearRing']
['posList']))]
return [Surface(Polygon(sp),Polygon(sp), surface_type=surface_type) for sp in solid_points]
@staticmethod
def _lod2(bound):

View File

@ -112,12 +112,6 @@ class TestGeometryFactory(TestCase):
self.assertIsNotNone(surface.inclination, 'surface inclination is none')
self.assertIsNotNone(surface.area_below_ground, 'surface area_below_ground is none')
self.assertIsNotNone(surface.area_above_ground, 'surface area_above_ground is none')
self.assertIsNotNone(surface.points, 'surface points is none')
self.assertIsNone(surface.holes_points, 'surface holes_points is not none')
self.assertIsNotNone(surface.perimeter_points, 'surface perimeter_points is none')
self.assertIsNotNone(surface.points_list, 'surface points_list is none')
self.assertIsNone(surface.holes_points_list, 'surface holes_points_list is not none')
self.assertIsNotNone(surface.perimeter_points_list, 'surface perimeter_points_list is none')
self.assertIsNotNone(surface.global_irradiance, 'monthly irradiance is none')
self.assertIsNone(surface.swr, 'surface swr is not none')
self.assertIsNotNone(surface.envelope_lower_corner, 'surface envelope_lower_corner is none')
@ -222,22 +216,3 @@ class TestGeometryFactory(TestCase):
city.save(pickle_file)
for building in city.buildings:
self.assertIsNotNone(building.volume, 'building volume is none')
def test_surface(self):
coordinates = '0.0 0.0 0.0 0.0 4.0 0.0 4.0 4.0 0.0 4.0 0.0 0.0 0.0 0.0 0.0 ' \
'1.0 1.0 0.0 2.0 1.0 0.0 2.0 2.0 0.0 1.0 2.0 0.0 1.0 1.0 0.0 0.0 0.0 0.0 ' \
'2.0 2.0 0.0 3.0 2.0 0.0 3.0 3.0 0.0 2.0 3.0 0.0 2.0 2.0 0.0'
holes_coordinates = ['1.0 1.0 0.0 2.0 1.0 0.0 2.0 2.0 0.0 1.0 2.0 0.0',
'2.0 2.0 0.0 3.0 2.0 0.0 3.0 3.0 0.0 2.0 3.0 0.0']
surface = Surface(coordinates, holes_coordinates=holes_coordinates)
print('solid:', surface.points)
print(surface.holes_points)
print('perimeter:', surface.perimeter_points)
for i in range(0, len(holes_coordinates)):
print(surface.holes_polygons[i].area)
print('perimeter:', surface.perimeter_polygon.area)
print('solid:', surface.solid_polygon.area)
for i in range(0, len(holes_coordinates)):
print(surface.holes_polygons[i].normal)
print('perimeter:', surface.perimeter_polygon.normal)
print('solid:', surface.solid_polygon.normal)

View File

@ -25,9 +25,8 @@ class TestWeatherFactory(TestCase):
self._example_path = (Path(__file__).parent / 'tests_data').resolve()
def _get_citygml(self, file_path):
if self._city_gml is None:
self._city_gml = GeometryFactory('citygml', file_path).city
self.assertIsNotNone(self._city_gml, 'city is none')
self._city_gml = GeometryFactory('citygml', file_path).city
self.assertIsNotNone(self._city_gml, 'city is none')
return self._city_gml
def _get_city_with_weather(self):