blob: 3f7736659a7082846cad1839d422948ebaa029e1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import os
import psycopg
import yaml
with open(os.path.join('configs', 'database.yml'), 'r') as file:
db_con_params = yaml.safe_load(file.read())
def get_supermarkets() -> (list[dict], list[str]):
with psycopg.connect(**db_con_params, row_factory=psycopg.rows.dict_row) as conn:
with conn.cursor() as cur:
cur.execute("""
SELECT name,
CASE WHEN brand ILIKE '%365%' THEN '365discount' ELSE BRAND END,
ST_Y(ST_Transform(geom, 4326)) AS lat, ST_X(ST_Transform(geom, 4326)) AS long
FROM shop WHERE subclass = 'supermarket';
""")
supermarkets = cur.fetchall()
return supermarkets
def voronoi_polygons() -> (list[dict], list[str]):
with psycopg.connect(**db_con_params, row_factory=psycopg.rows.dict_row) as conn:
with conn.cursor() as cur:
cur.execute("""
SELECT ST_AsGeoJSON(ST_Transform(ST_VoronoiPolygons(ST_Collect(geom)), 4326)) as geojson
FROM shop
WHERE subclass = 'supermarket';
""")
voronoi_polygons = cur.fetchone()['geojson']
return voronoi_polygons
|