-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoordiante_check.py
More file actions
72 lines (57 loc) · 2.81 KB
/
coordiante_check.py
File metadata and controls
72 lines (57 loc) · 2.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# import of libraries
import matplotlib.path as mplP
import numpy as np
import lxml.etree as ET
# import of functions
import string_manipulation as sm
def border_check(border, list_of_border, list_of_coordinates):
"""checks if two area intersect each other """
for point in list_of_coordinates:
if border.contains_point(point):
return True
n_border = mplP.Path(np.array(list_of_coordinates))
for point in list_of_border:
if n_border.contains_point(point):
return True
return False
def check_element(element, namespace, selCor_path, selCor_list):
"""searches groundSurface and checks if building/buildingPart is located inside the selCor_path/sel_Cor_list"""
groundSurface_E = element.find('./bldg:boundedBy/bldg:GroundSurface', namespace)
if groundSurface_E != None:
posList_E = groundSurface_E.find('.//gml:posList', namespace) # searching for list of coordinates
if posList_E != None: # case aachen lod2
coor_list = sm.get_2dPosList_from_str(posList_E.text)
result = border_check(selCor_path, selCor_list, coor_list)
else: # case hamburg lod2 2020
pos_Es = groundSurface_E.findall('.//gml:pos', namespace)
polygon = []
for pos_E in pos_Es:
polygon.append(pos_E.text)
polyStr = ' '.join(polygon)
coor_list = sm.get_2dPosList_from_str(polyStr)
result = border_check(selCor_path, selCor_list, coor_list)
if result: # groundSurface of building is in the selected area -> building is considered
return True
else: # groundSurface of building is not in the selected area -> checking if there are buildingParts
return False
# checking if no groundSurface element has been found
else: # case for lod1 files
poly_Es = element.findall('.//gml:Polygon', namespace)
all_poylgons = []
for poly_E in poly_Es:
polygon = []
posList_E = element.find('.//gml:posList', namespace) # searching for list of coordinates
if posList_E != None:
polyStr = posList_E.text
else:
pos_Es = poly_E.findall('.//gml:pos', namespace) # searching for individual coordinates in polygon
for pos_E in pos_Es:
polygon.append(pos_E.text)
polyStr = ' '.join(polygon)
coor_list = sm.get_2dPosList_from_str(polyStr)
all_poylgons.append(coor_list)
for polygon in all_poylgons:
result = border_check(selCor_path, selCor_list, polygon)
if result:
return True
return False