Log outage geometries to database (#68)
To enable us to detect changes to to the geometry for future updating of the map (#67) Reviewed-on: #68
This commit is contained in:
parent
fbdc85bc29
commit
e6722876bd
2 changed files with 38 additions and 7 deletions
|
@ -1,4 +1,5 @@
|
|||
from shapely import MultiPolygon, Polygon
|
||||
from shapely import MultiPolygon, Polygon, Geometry, to_wkb, from_wkb
|
||||
from sqlalchemy.types import TypeDecorator, LargeBinary
|
||||
|
||||
|
||||
def convert_outage_geometry(event) -> MultiPolygon:
|
||||
|
@ -9,3 +10,21 @@ def convert_outage_geometry(event) -> MultiPolygon:
|
|||
for ring in event["polygons"]["rings"]:
|
||||
polygon_list.append(Polygon(ring))
|
||||
return MultiPolygon(polygon_list)
|
||||
|
||||
|
||||
class DBGeometry(TypeDecorator):
|
||||
impl = LargeBinary
|
||||
cache_ok = True
|
||||
|
||||
def process_bind_param(self, value, dialect):
|
||||
if isinstance(value, Geometry):
|
||||
value = to_wkb(value)
|
||||
return value
|
||||
|
||||
def process_result_value(self, value, dialect):
|
||||
if value is None:
|
||||
return value
|
||||
else:
|
||||
if not isinstance(value, Geometry):
|
||||
value = from_wkb(value)
|
||||
return value
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue