楼层必须有轮廓, 且合法
1. 楼层外轮廓数据只有一个由点组成的数组围成, 因此直接判断指定的点是否在点数组围成的多边形内即可
[
{点坐标的XYZ信息},
{点坐标的XYZ信息}...
]
输入为浮点型
CREATE OR REPLACE FUNCTION "public"."is_point_in_polygon_v1"("x" float8, "y" float8, "json_poly" jsonb)
RETURNS "pg_catalog"."bool" AS $BODY$
from matplotlib.path import Path
import json
try:
poly = []
polygon = json.loads(json_poly)
l = len(polygon)
points = (x, y)
for i in range(l):
pair = polygon[i]
poly.append((pair["X"], pair["Y"]))
p = Path(poly)
except Exception as e:
return False
else:
return p.contains_points([points], None, -0.0001)
$BODY$
LANGUAGE plpython3u VOLATILE
COST 100
输入为字符串类型
CREATE OR REPLACE FUNCTION "public"."is_point_in_polygon_v1_str"("x" varchar, "y" varchar, "json_poly" jsonb)
RETURNS "pg_catalog"."bool" AS $BODY$
from matplotlib.path import Path
import json
try:
poly = []
polygon = json.loads(json_poly)
l = len(polygon)
points = (float(x), float(y))
for i in range(l):
pair = polygon[i]
poly.append((pair["X"], pair["Y"]))
p = Path(poly)
except Exception as e:
return False
else:
return p.contains_points([points], None, -0.0001)
$BODY$
LANGUAGE plpython3u VOLATILE
COST 100
1. 点的x坐标
2. 点的y坐标
3. 楼层的轮廓
true 成功
false 失败