计算元空间轮廓是否和楼层轮廓是否有重叠 # 前置条件 1. 元空间和楼层必须都有轮廓 2. 轮廓必须符合规则 # 处理逻辑 将楼层的外轮廓与元空间的最外层轮廓做是否重叠检查操作 # 函数
源码 ``` CREATE OR REPLACE FUNCTION "public"."other_ispace_floor_overlap"("ispace_outline" jsonb, "floor_outline" jsonb) RETURNS "pg_catalog"."bool" AS $BODY$ from shapely.geometry import Polygon import json # 获取Polygon对象 def get_polygon(single_poly): poly_len = len(single_poly) poly = [] for i in range(poly_len): pair = single_poly[i] poly.append((pair["X"], pair["Y"])) return Polygon(poly) try: if ispace_outline is None or floor_outline is None: return False ispace_json = json.loads(ispace_outline) floor_json = json.loads(floor_outline) if len(floor_json) < 3 or len(ispace_json) == 0 or len(ispace_json[0]) < 3 : return False ispace_poly = get_polygon(ispace_json[0]) floor_poly = get_polygon(floor_json) if floor_poly.contains(ispace_poly) or floor_poly.equals(ispace_poly) or floor_poly.overlaps(ispace_poly): return True return False except Exception as e: #plpy.warning(e) return False $BODY$ LANGUAGE plpython3u VOLATILE COST 100 ```
## 输入 1. 元空间轮廓 2. 楼层轮廓 ## 返回结果 true 有重叠 false 未重叠