from helper import seq from shapely.wkb import loads from sqlalchemy import and_ from itertools import chain from multiprocessing import Pool, cpu_count, Process from numpy import mean from itertools import groupby # DATA IMPORT ############################################################################### print("Database connection established.") # import white area including coastdat id ww_isection = session.query(CosmoClmGrid.gid, func.ST_Intersection(CosmoClmGrid.geom, GeoPotArea.geom)).\ filter(func.ST_Intersects(GeoPotArea.geom, CosmoClmGrid.geom)) ww_isection = [(wid, loads(bytes(geom.data))) for wid, geom in ww_isection] # import grid districts gds = session.query(GridDistrict.subst_id, func.ST_Transform(GridDistrict.geom, 4326)) gds = [(sid, to_shape(geom)) for sid, geom in gds] # import weadata data for Germany (roughly bounding box in cosmoclmgrid) weadata = session.query(Spatial.gid, Timeseries.tsarray).\ join(Located, Located.spatial_id == Spatial.gid).\ join(Timeseries, Located.data_id == Timeseries.id).\ join(Scheduled, Scheduled.data_id == Timeseries.id).\ join(Year, Scheduled.time_id == Year.year).\
def geom_intersection(cls, geometry, srid): wkb_geometry = _wrap_wkb_geometry(geometry, srid) geom_column = cls.geometry_column() return func.ST_Intersection( geom_column, transform_geometry(geom_column, wkb_geometry, srid))
def bboxClippedGeom(cls, bbox, srid=4326): bboxGeom = shapelyBBox(bbox) wkbGeometry = WKBElement(buffer(bboxGeom.wkb), srid) geomColumn = cls.geometryColumn() return func.ST_Intersection(geomColumn, wkbGeometry)