|
@@ -23,35 +23,23 @@ $$
|
|
|
from matplotlib.path import Path
|
|
|
import json
|
|
|
|
|
|
-def is_in_meta_polygon(point, single_poly, radius):
|
|
|
- poly_len = len(single_poly)
|
|
|
- poly = []
|
|
|
- for i in range(poly_len):
|
|
|
- pair = single_poly[i]
|
|
|
- poly.append((pair["X"], pair["Y"]))
|
|
|
- p = Path(poly)
|
|
|
- return p.contains_points([point], None, radius)
|
|
|
-
|
|
|
-def is_point_in_polygon(x, y, json_poly):
|
|
|
+def is_in_meta_polygon(x, y, json_poly):
|
|
|
try:
|
|
|
- polygons = json.loads(json_poly)
|
|
|
- total_len = len(polygons)
|
|
|
- point_pair = (float(x), float(y))
|
|
|
- if total_len == 0:
|
|
|
- return False
|
|
|
- for i in range(total_len):
|
|
|
- polygon = polygons[i]
|
|
|
- if(i == 0):
|
|
|
- if not is_in_meta_polygon(point_pair, polygon, -0.001):
|
|
|
- return False
|
|
|
- else:
|
|
|
- if is_in_meta_polygon(point_pair, polygon, 0.001):
|
|
|
- return False
|
|
|
- return True
|
|
|
+ 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:
|
|
|
+ plpy.info(e)
|
|
|
return False
|
|
|
else:
|
|
|
- return True
|
|
|
+ return p.contains_points([points], None, -0.0001)
|
|
|
+
|
|
|
try:
|
|
|
# 将下面对数据库的操作作为一个事务, 出异常则自动rollback
|
|
|
with plpy.subtransaction():
|
|
@@ -66,18 +54,17 @@ try:
|
|
|
if outline == None or len(outline) == 0 or location == None or len(location) == 0:
|
|
|
if floor['model_id'] == floor['model_id']:
|
|
|
equip['floor_id'] = floor['id']
|
|
|
- else:
|
|
|
- continue
|
|
|
+ continue
|
|
|
location = location.split(',')
|
|
|
try:
|
|
|
- if is_point_in_polygon(location[0], location[1], outline):
|
|
|
+ if is_in_meta_polygon(location[0], location[1], outline):
|
|
|
equip['floor_id'] = floor['id']
|
|
|
except Exception as ex:
|
|
|
continue
|
|
|
for equip in equips:
|
|
|
if equip.__contains__('floor_id'):
|
|
|
try:
|
|
|
- plpy.info("equip id {0}, floor id {1}".format(equip['id'], equip['floor_id']))
|
|
|
+ #plpy.info("equip id {0}, floor id {1}".format(equip['id'], equip['floor_id']))
|
|
|
plan = plpy.prepare("update equipment set floor_id = $1 where id = $2", ["text", "text"])
|
|
|
plan.execute([equip['floor_id'], equip['id']])
|
|
|
except Exception as ex:
|