feat(workbench): add runtime GIS and sample integrations
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
"""Read-only access to imported source GIS attributes."""
|
||||
|
||||
from typing import Any
|
||||
|
||||
from psycopg import AsyncConnection
|
||||
|
||||
|
||||
class GisAttributeRepository:
|
||||
@staticmethod
|
||||
async def list_element_groups(
|
||||
conn: AsyncConnection,
|
||||
element_type: str,
|
||||
element_id: str,
|
||||
) -> list[dict[str, Any]]:
|
||||
async with conn.cursor() as cur:
|
||||
await cur.execute(
|
||||
"SELECT to_regclass('source_gis.element_links') AS relation"
|
||||
)
|
||||
availability = await cur.fetchone()
|
||||
if not availability or availability["relation"] is None:
|
||||
return []
|
||||
await cur.execute(
|
||||
"""
|
||||
SELECT
|
||||
dataset.dataset_key,
|
||||
dataset.title AS dataset_title,
|
||||
dataset.source_date,
|
||||
layer.layer_key,
|
||||
layer.display_name AS layer_name,
|
||||
feature.source_fid,
|
||||
link.match_method,
|
||||
link.distance_m AS match_distance_m,
|
||||
feature.attributes
|
||||
FROM source_gis.element_links AS link
|
||||
JOIN source_gis.features AS feature
|
||||
ON feature.layer_key = link.layer_key
|
||||
AND feature.source_fid = link.source_fid
|
||||
JOIN source_gis.layers AS layer
|
||||
ON layer.layer_key = feature.layer_key
|
||||
JOIN source_gis.datasets AS dataset
|
||||
ON dataset.dataset_key = layer.dataset_key
|
||||
WHERE link.element_type = %s
|
||||
AND link.element_id = %s
|
||||
ORDER BY dataset.source_date DESC, layer.display_name, feature.source_fid
|
||||
""",
|
||||
(element_type, element_id),
|
||||
)
|
||||
return [dict(row) for row in await cur.fetchall()]
|
||||
|
||||
@staticmethod
|
||||
async def get_source_feature_group(
|
||||
conn: AsyncConnection,
|
||||
layer_key: str,
|
||||
source_fid: int,
|
||||
) -> dict[str, Any] | None:
|
||||
async with conn.cursor() as cur:
|
||||
await cur.execute(
|
||||
"""
|
||||
SELECT
|
||||
dataset.dataset_key,
|
||||
dataset.title AS dataset_title,
|
||||
dataset.source_date,
|
||||
layer.layer_key,
|
||||
layer.display_name AS layer_name,
|
||||
feature.source_fid,
|
||||
'source' AS match_method,
|
||||
NULL::double precision AS match_distance_m,
|
||||
feature.attributes
|
||||
FROM source_gis.features AS feature
|
||||
JOIN source_gis.layers AS layer
|
||||
ON layer.layer_key = feature.layer_key
|
||||
JOIN source_gis.datasets AS dataset
|
||||
ON dataset.dataset_key = layer.dataset_key
|
||||
WHERE feature.layer_key = %s
|
||||
AND feature.source_fid = %s
|
||||
""",
|
||||
(layer_key, source_fid),
|
||||
)
|
||||
row = await cur.fetchone()
|
||||
return dict(row) if row else None
|
||||
Reference in New Issue
Block a user