|
@@ -0,0 +1,97 @@
|
|
|
+from relations import utils
|
|
|
+from shapely.geometry import Polygon
|
|
|
+def calc_plane(space_datas):
|
|
|
+ '''Calc plane business space adjoin relation.
|
|
|
+ :param floor_id:
|
|
|
+ :param space_type:
|
|
|
+ :return:
|
|
|
+ '''
|
|
|
+ relationcollection = utils.BinaryRelationCollection()
|
|
|
+ for i in range(len(space_datas)):
|
|
|
+ for j in range(i+1,len(space_datas)):
|
|
|
+ relations=calc_adjoinspace(space_datas[i],space_datas[j])
|
|
|
+ relationcollection.extend(relations)
|
|
|
+ return relationcollection
|
|
|
+
|
|
|
+def calc_verticalface(space_datas1,space_datas2):
|
|
|
+ '''Calc vertical business space adjoin relaiton.
|
|
|
+ :param floor_id1:
|
|
|
+ :param floor_id2:
|
|
|
+ :param space_type:
|
|
|
+ :return:
|
|
|
+ '''
|
|
|
+ relationcollection = utils.BinaryRelationCollection()
|
|
|
+ for s1 in space_datas1:
|
|
|
+ for s2 in space_datas2:
|
|
|
+ relations = calc_adjoinspace(s1, s2)
|
|
|
+ relationcollection.extend(relations)
|
|
|
+ return relationcollection
|
|
|
+
|
|
|
+def calc_adjoinspace(space,target_spaces):
|
|
|
+ '''Judge business space adjoin to other target_spaces.
|
|
|
+ :param space:
|
|
|
+ :param target_spaces:
|
|
|
+ :return:
|
|
|
+ '''
|
|
|
+ relationcollection=utils.BinaryRelationCollection()
|
|
|
+ for target in target_spaces:
|
|
|
+ if(judge_space(space,target)):
|
|
|
+ relationitem=utils.BinaryRelationItem(space.id,target.id)
|
|
|
+ relationcollection.update(relationitem)
|
|
|
+ return relationcollection
|
|
|
+def judge_space(space,target_space):
|
|
|
+ '''Judge business space adjoin relation.
|
|
|
+ business space may contain more than one basespace
|
|
|
+ :param space:
|
|
|
+ :param target_space:
|
|
|
+ :return:
|
|
|
+ '''
|
|
|
+ for b1 in space.outline2:
|
|
|
+ for b2 in target_space.outline2:
|
|
|
+ # find one,break
|
|
|
+ if(judge_space(b1,b2)):
|
|
|
+ return True
|
|
|
+ return False
|
|
|
+def judge_bspace(b1,b2):
|
|
|
+ '''Judge base space b1,b2 adjoin relation.
|
|
|
+ 1. b1 outer polygon intersect b2 out polygon;
|
|
|
+ 2. if b1 outer contain b2 outer,judge whether b1 inner contain b2, if true not adjoin,break;
|
|
|
+ 3. exchange b1 b2.perform to step2;
|
|
|
+ :param b1:
|
|
|
+ :param b2:
|
|
|
+ :return:
|
|
|
+ '''
|
|
|
+ if(len(b1)<1 or len(b2)<1):
|
|
|
+ return False
|
|
|
+ p1_outer=convert2polygon(b1[0])
|
|
|
+ p2_outer=convert2polygon(b2[0])
|
|
|
+ # judge intersect.
|
|
|
+ result=p1_outer.intersects(p2_outer)
|
|
|
+ if(result):
|
|
|
+ # judge contain,outer contain and inner not contain.
|
|
|
+ result=judge_bspace_contain(p1_outer,p2_outer,b1)
|
|
|
+ if(result):
|
|
|
+ result=judge_bspace_contain(p2_outer, p1_outer, b2)
|
|
|
+ return result
|
|
|
+def judge_bspace_contain(p1_outer,p2_outer,b1):
|
|
|
+ '''Intersect space ,calc contain relation .
|
|
|
+ :param p1_outer:big outer
|
|
|
+ :param p2_outer:small outer
|
|
|
+ :param b1:big space outline
|
|
|
+ :return:
|
|
|
+ '''
|
|
|
+ result=True
|
|
|
+ if (p1_outer.contains(p2_outer)):
|
|
|
+ for i in range(1, len(b1)):
|
|
|
+ inner = b1[i]
|
|
|
+ p_inner = convert2polygon(inner)
|
|
|
+ if (p_inner.contains(p2_outer)):
|
|
|
+ result = False
|
|
|
+ break
|
|
|
+ return result
|
|
|
+def convert2polygon(p):
|
|
|
+ coords =[]
|
|
|
+ for xyz in p:
|
|
|
+ coords.append((xyz.X,xyz.Y))
|
|
|
+ poly = Polygon(coords)
|
|
|
+ return poly
|