forked from s_ranjbar/city_retrofit
correct shared walls
This commit is contained in:
parent
e978d56320
commit
0f8816a053
|
@ -18,7 +18,6 @@ from hub.city_model_structure.attributes.polyhedron import Polyhedron
|
||||||
from hub.helpers.location import Location
|
from hub.helpers.location import Location
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MapPoint:
|
class MapPoint:
|
||||||
def __init__(self, x, y):
|
def __init__(self, x, y):
|
||||||
self._x = int(x)
|
self._x = int(x)
|
||||||
|
@ -58,7 +57,7 @@ class GeometryHelper:
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def factor():
|
def factor():
|
||||||
return 2.0
|
return 0.5
|
||||||
|
|
||||||
def __init__(self, delta=0, area_delta=0):
|
def __init__(self, delta=0, area_delta=0):
|
||||||
self._delta = delta
|
self._delta = delta
|
||||||
|
@ -67,10 +66,11 @@ class GeometryHelper:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def coordinate_to_map_point(coordinate, city):
|
def coordinate_to_map_point(coordinate, city):
|
||||||
factor = GeometryHelper.factor()
|
factor = GeometryHelper.factor()
|
||||||
return MapPoint(((city.upper_corner[0] - coordinate[0]) * factor), ((city.upper_corner[1] - coordinate[1]) * factor))
|
return MapPoint(((coordinate[0] - city.lower_corner[0]) * factor), ((coordinate[1] - city.lower_corner[1]) * factor))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def city_mapping(city, building_names=None, plot=False):
|
def city_mapping(city, building_names=None, plot=False):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
Returns a shared_information dictionary like
|
Returns a shared_information dictionary like
|
||||||
|
@ -82,8 +82,9 @@ class GeometryHelper:
|
||||||
if building_names is None:
|
if building_names is None:
|
||||||
building_names = [b.name for b in city.buildings]
|
building_names = [b.name for b in city.buildings]
|
||||||
factor = GeometryHelper.factor()
|
factor = GeometryHelper.factor()
|
||||||
x = int((city.upper_corner[0] - city.lower_corner[0]) * factor) + 1
|
x = math.ceil((city.upper_corner[0] - city.lower_corner[0]) * factor) + 1
|
||||||
y = int((city.upper_corner[1] - city.lower_corner[1]) * factor) + 1
|
y = math.ceil((city.upper_corner[1] - city.lower_corner[1]) * factor) + 1
|
||||||
|
# print(x, y)
|
||||||
city_map = [['' for _ in range(y + 1)] for _ in range(x + 1)]
|
city_map = [['' for _ in range(y + 1)] for _ in range(x + 1)]
|
||||||
map_info = [[{} for _ in range(y + 1)] for _ in range(x + 1)]
|
map_info = [[{} for _ in range(y + 1)] for _ in range(x + 1)]
|
||||||
img = Image.new('RGB', (x + 1, y + 1), "black") # create a new black image
|
img = Image.new('RGB', (x + 1, y + 1), "black") # create a new black image
|
||||||
|
@ -99,15 +100,19 @@ class GeometryHelper:
|
||||||
if i == length:
|
if i == length:
|
||||||
j = 0
|
j = 0
|
||||||
next_coordinate = ground.perimeter_polygon.coordinates[j]
|
next_coordinate = ground.perimeter_polygon.coordinates[j]
|
||||||
point = GeometryHelper.coordinate_to_map_point(coordinate, city)
|
distance = GeometryHelper.distance_between_points(coordinate, next_coordinate)
|
||||||
distance = int(GeometryHelper.distance_between_points(coordinate, next_coordinate))
|
|
||||||
if distance == 0:
|
if distance == 0:
|
||||||
continue
|
continue
|
||||||
delta_x = (coordinate[0] - next_coordinate[0]) / (distance / factor)
|
delta_x = (next_coordinate[0] - coordinate[0]) / (distance / factor)
|
||||||
delta_y = (coordinate[1] - next_coordinate[1]) / (distance / factor)
|
delta_y = (next_coordinate[1] - coordinate[1]) / (distance / factor)
|
||||||
for k in range(0, distance):
|
steps = int(distance/factor)
|
||||||
x = MapPoint(point.x + (delta_x * k), point.y + (delta_y * k)).x
|
# print(steps, distance, delta_x, delta_y)
|
||||||
y = MapPoint(point.x + (delta_x * k), point.y + (delta_y * k)).y
|
for k in range(0, steps):
|
||||||
|
new_coordinate = (coordinate[0] + (delta_x * k), coordinate[1] + (delta_y * k))
|
||||||
|
point = GeometryHelper.coordinate_to_map_point(new_coordinate, city)
|
||||||
|
x = point.x
|
||||||
|
y = point.y
|
||||||
|
# print(x, y, new_coordinate[0]-city.lower_corner[0], new_coordinate[1]-city.lower_corner[1])
|
||||||
if city_map[x][y] == '':
|
if city_map[x][y] == '':
|
||||||
city_map[x][y] = building.name
|
city_map[x][y] = building.name
|
||||||
map_info[x][y] = {
|
map_info[x][y] = {
|
||||||
|
@ -179,49 +184,6 @@ class GeometryHelper:
|
||||||
img.show()
|
img.show()
|
||||||
return lines_information
|
return lines_information
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def fast_city_mapping(city, building_names=None):
|
|
||||||
lines_information = {}
|
|
||||||
factor = GeometryHelper.factor()
|
|
||||||
if building_names is None:
|
|
||||||
building_names = [b.name for b in city.buildings]
|
|
||||||
x = int((city.upper_corner[0] - city.lower_corner[0]) * factor) + 1
|
|
||||||
y = int((city.upper_corner[1] - city.lower_corner[1]) * factor) + 1
|
|
||||||
city_map = [['' for _ in range(y + 1)] for _ in range(x + 1)]
|
|
||||||
for building_name in building_names:
|
|
||||||
building = city.city_object(building_name)
|
|
||||||
line = 0
|
|
||||||
for ground in building.grounds:
|
|
||||||
length = len(ground.perimeter_polygon.coordinates) - 1
|
|
||||||
for i, coordinate in enumerate(ground.perimeter_polygon.coordinates):
|
|
||||||
j = i + 1
|
|
||||||
if i == length:
|
|
||||||
j = 0
|
|
||||||
next_coordinate = ground.perimeter_polygon.coordinates[j]
|
|
||||||
point = GeometryHelper.coordinate_to_map_point(coordinate, city)
|
|
||||||
distance = int(GeometryHelper.distance_between_points(coordinate, next_coordinate))
|
|
||||||
if distance == 0:
|
|
||||||
continue
|
|
||||||
delta_x = (coordinate[0] - next_coordinate[0]) / (distance / factor)
|
|
||||||
delta_y = (coordinate[1] - next_coordinate[1]) / (distance / factor)
|
|
||||||
for k in range(0, distance):
|
|
||||||
x = MapPoint(point.x + (delta_x * k), point.y + (delta_y * k)).x
|
|
||||||
y = MapPoint(point.x + (delta_x * k), point.y + (delta_y * k)).y
|
|
||||||
if city_map[x][y] == '':
|
|
||||||
city_map[x][y] = building.name
|
|
||||||
elif city_map[x][y] != building.name:
|
|
||||||
neighbour = city.city_object(city_map[x][y])
|
|
||||||
if building.neighbours is None:
|
|
||||||
building.neighbours = [neighbour]
|
|
||||||
elif neighbour not in building.neighbours:
|
|
||||||
building.neighbours.append(neighbour)
|
|
||||||
if neighbour.neighbours is None:
|
|
||||||
neighbour.neighbours = [building]
|
|
||||||
elif building not in neighbour.neighbours:
|
|
||||||
neighbour.neighbours.append(building)
|
|
||||||
line += 1
|
|
||||||
return lines_information
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def segment_list_to_trimesh(lines) -> Trimesh:
|
def segment_list_to_trimesh(lines) -> Trimesh:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -164,7 +164,7 @@ class TestGeometryFactory(TestCase):
|
||||||
year_of_construction_field='ANNEE_CONS',
|
year_of_construction_field='ANNEE_CONS',
|
||||||
function_field='LIBELLE_UT')
|
function_field='LIBELLE_UT')
|
||||||
|
|
||||||
info_lod0 = GeometryHelper.city_mapping(city, plot=False)
|
# info_lod0 = GeometryHelper.city_mapping(city, plot=False)
|
||||||
hub.exports.exports_factory.ExportsFactory('obj', city, self._output_path).export()
|
hub.exports.exports_factory.ExportsFactory('obj', city, self._output_path).export()
|
||||||
self.assertEqual(info_lod0, info_lod1)
|
self.assertEqual(info_lod0, info_lod1)
|
||||||
for building in city.buildings:
|
for building in city.buildings:
|
||||||
|
@ -189,10 +189,16 @@ class TestGeometryFactory(TestCase):
|
||||||
name_field='OBJECTID_12',
|
name_field='OBJECTID_12',
|
||||||
function_field='CODE_UTILI',
|
function_field='CODE_UTILI',
|
||||||
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
|
function_to_hub=Dictionaries().montreal_function_to_hub_function).city
|
||||||
|
# print(city.lower_corner, city.upper_corner)
|
||||||
|
for building in city.buildings:
|
||||||
|
#for ground in building.grounds:
|
||||||
|
# print(ground.perimeter_polygon.coordinates)
|
||||||
|
# print(ground.perimeter_polygon.coordinates[0][0] - city.lower_corner[0], ground.perimeter_polygon.coordinates[0][1] - city.lower_corner[1])
|
||||||
|
# print(ground.perimeter_polygon.coordinates[1][0] - city.lower_corner[0], ground.perimeter_polygon.coordinates[1][1] - city.lower_corner[1])
|
||||||
|
break
|
||||||
ConstructionFactory('nrcan', city).enrich()
|
ConstructionFactory('nrcan', city).enrich()
|
||||||
UsageFactory('nrcan', city).enrich()
|
UsageFactory('nrcan', city).enrich()
|
||||||
info_lod1 = GeometryHelper.city_mapping(city, plot=True)
|
info_lod1 = GeometryHelper.city_mapping(city, plot=True)
|
||||||
print('info', info_lod1)
|
|
||||||
for building in city.buildings:
|
for building in city.buildings:
|
||||||
print(building.name)
|
print(building.name)
|
||||||
ns = ''
|
ns = ''
|
||||||
|
|
Loading…
Reference in New Issue
Block a user