small style correction
This commit is contained in:
parent
fae577deaa
commit
7e5ead2363
|
@ -5,30 +5,30 @@ Copyright © 2022 Concordia CERC group
|
||||||
Project Coder: Milad Aghamohamadnia --- milad.aghamohamadnia@concordia.ca
|
Project Coder: Milad Aghamohamadnia --- milad.aghamohamadnia@concordia.ca
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import trimesh.exchange.load
|
|
||||||
from trimesh import Scene
|
|
||||||
import trimesh.geometry
|
|
||||||
from shapely.geometry import Polygon as ShapelyPoly
|
|
||||||
from shapely.geometry import Point
|
|
||||||
import trimesh
|
import trimesh
|
||||||
from pyproj import CRS
|
import trimesh.exchange.load
|
||||||
from city_model_structure.city import City
|
import trimesh.geometry
|
||||||
|
from shapely.geometry import Point
|
||||||
|
from shapely.geometry import Polygon as ShapelyPoly
|
||||||
|
from trimesh import Scene
|
||||||
|
|
||||||
|
from city_model_structure.attributes.polygon import Polygon
|
||||||
from city_model_structure.building import Building
|
from city_model_structure.building import Building
|
||||||
from city_model_structure.building_demand.surface import Surface
|
from city_model_structure.building_demand.surface import Surface
|
||||||
from city_model_structure.attributes.polygon import Polygon
|
from city_model_structure.city import City
|
||||||
import numpy as np
|
|
||||||
|
import helpers.constants as cte
|
||||||
|
|
||||||
|
|
||||||
class GPandas:
|
class GPandas:
|
||||||
"""
|
"""
|
||||||
GeoPandas class
|
GeoPandas class
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, gdataframe, srs_name='EPSG:26911'):
|
def __init__(self, gdataframe, srs_name='EPSG:26911'):
|
||||||
"""_summary_
|
"""_summary_
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
gdataframe {Geopandas.Dataframe} -- input geometry data in geopandas table
|
gdataframe {Geopandas.Dataframe} -- input geometry data in geopandas table
|
||||||
|
|
||||||
Keyword Arguments:
|
Keyword Arguments:
|
||||||
srs_name {str} -- coordinate system of coordinate system (default: {'EPSG:26911'})
|
srs_name {str} -- coordinate system of coordinate system (default: {'EPSG:26911'})
|
||||||
"""
|
"""
|
||||||
|
@ -36,9 +36,9 @@ class GPandas:
|
||||||
self._city = None
|
self._city = None
|
||||||
self._scene = gdataframe
|
self._scene = gdataframe
|
||||||
self._scene = self._scene.to_crs(self._srs_name)
|
self._scene = self._scene.to_crs(self._srs_name)
|
||||||
minx, miny, maxx, maxy = self._scene.total_bounds
|
min_x, min_y, max_x, max_y = self._scene.total_bounds
|
||||||
self._lower_corner = [minx, miny, 0]
|
self._lower_corner = [min_x, min_y, 0]
|
||||||
self._upper_corner = [maxx, maxy, 0]
|
self._upper_corner = [max_x, max_y, 0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def scene(self) -> Scene:
|
def scene(self) -> Scene:
|
||||||
|
@ -55,7 +55,6 @@ class GPandas:
|
||||||
if self._city is None:
|
if self._city is None:
|
||||||
self._city = City(self._lower_corner, self._upper_corner, self._srs_name)
|
self._city = City(self._lower_corner, self._upper_corner, self._srs_name)
|
||||||
for ix, bldg in self._scene.iterrows():
|
for ix, bldg in self._scene.iterrows():
|
||||||
polygon = bldg['geometry']
|
|
||||||
geom = bldg.geom
|
geom = bldg.geom
|
||||||
polygon = ShapelyPoly(geom['coordinates'][0])
|
polygon = ShapelyPoly(geom['coordinates'][0])
|
||||||
height = float(bldg['height_mean'])
|
height = float(bldg['height_mean'])
|
||||||
|
@ -66,10 +65,9 @@ class GPandas:
|
||||||
name = str(ix)
|
name = str(ix)
|
||||||
lod = 1
|
lod = 1
|
||||||
if year_of_construction > 2000:
|
if year_of_construction > 2000:
|
||||||
function = 'residential'
|
function = cte.RESIDENTIAL
|
||||||
else:
|
else:
|
||||||
function = 'industry'
|
function = cte.INDUSTRY
|
||||||
average_storey_height = 3
|
|
||||||
|
|
||||||
surfaces = []
|
surfaces = []
|
||||||
face_normal = building_mesh.face_normals
|
face_normal = building_mesh.face_normals
|
||||||
|
@ -79,7 +77,7 @@ class GPandas:
|
||||||
points.append(building_mesh.vertices[vertex_index])
|
points.append(building_mesh.vertices[vertex_index])
|
||||||
solid_polygon = Polygon(points)
|
solid_polygon = Polygon(points)
|
||||||
perimeter_polygon = solid_polygon
|
perimeter_polygon = solid_polygon
|
||||||
s_type = 'Ground' if face_normal[ix][2]==-1 else ('Roof' if face_normal[ix][2]==1 else 'Wall')
|
s_type = cte.GROUND if face_normal[ix][2] == -1 else (cte.ROOF if face_normal[ix][2] == 1 else cte.WALL)
|
||||||
surface = Surface(solid_polygon, perimeter_polygon, surface_type=s_type)
|
surface = Surface(solid_polygon, perimeter_polygon, surface_type=s_type)
|
||||||
surfaces.append(surface)
|
surfaces.append(surface)
|
||||||
building = Building(name, lod, surfaces, year_of_construction, function, self._lower_corner, terrains=None)
|
building = Building(name, lod, surfaces, year_of_construction, function, self._lower_corner, terrains=None)
|
||||||
|
@ -87,10 +85,9 @@ class GPandas:
|
||||||
return self._city
|
return self._city
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def resize_polygon(poly, factor=0.10, expand=False):
|
def resize_polygon(poly, factor=0.10, expand=False) -> ShapelyPoly:
|
||||||
"""
|
"""
|
||||||
returns the shapely polygon which is smaller or bigger by passed factor.
|
returns the shapely polygon which is smaller or bigger by passed factor.
|
||||||
|
|
||||||
Arguments:
|
Arguments:
|
||||||
poly {shapely.geometry.Polygon} -- an input geometry in shapely polygon format
|
poly {shapely.geometry.Polygon} -- an input geometry in shapely polygon format
|
||||||
|
|
||||||
|
@ -106,7 +103,6 @@ class GPandas:
|
||||||
x_center = 0.5 * min(xs) + 0.5 * max(xs)
|
x_center = 0.5 * min(xs) + 0.5 * max(xs)
|
||||||
y_center = 0.5 * min(ys) + 0.5 * max(ys)
|
y_center = 0.5 * min(ys) + 0.5 * max(ys)
|
||||||
min_corner = Point(min(xs), min(ys))
|
min_corner = Point(min(xs), min(ys))
|
||||||
max_corner = Point(max(xs), max(ys))
|
|
||||||
center = Point(x_center, y_center)
|
center = Point(x_center, y_center)
|
||||||
shrink_distance = center.distance(min_corner) * factor
|
shrink_distance = center.distance(min_corner) * factor
|
||||||
|
|
||||||
|
@ -115,4 +111,3 @@ class GPandas:
|
||||||
else:
|
else:
|
||||||
poly_resized = poly.buffer(-shrink_distance) # shrink
|
poly_resized = poly.buffer(-shrink_distance) # shrink
|
||||||
return poly_resized
|
return poly_resized
|
||||||
|
|
||||||
|
|
|
@ -16,3 +16,4 @@ rhino3dm==7.7.0
|
||||||
scipy
|
scipy
|
||||||
PyYAML
|
PyYAML
|
||||||
pyecore==0.12.2
|
pyecore==0.12.2
|
||||||
|
shapely
|
|
@ -147,6 +147,18 @@ class TestGeometryFactory(TestCase):
|
||||||
for building in city.buildings:
|
for building in city.buildings:
|
||||||
self._check_surfaces(building)
|
self._check_surfaces(building)
|
||||||
|
|
||||||
|
def test_import_geopandas(self):
|
||||||
|
"""
|
||||||
|
Test geopandas import
|
||||||
|
"""
|
||||||
|
file = 'kelowna.obj'
|
||||||
|
city = self._get_obj(file)
|
||||||
|
self.assertIsNotNone(city, 'city is none')
|
||||||
|
self.assertTrue(len(city.buildings) == 1)
|
||||||
|
self._check_buildings(city)
|
||||||
|
for building in city.buildings:
|
||||||
|
self._check_surfaces(building)
|
||||||
|
|
||||||
# osm
|
# osm
|
||||||
def test_subway(self):
|
def test_subway(self):
|
||||||
"""
|
"""
|
||||||
|
|
Loading…
Reference in New Issue
Block a user