@@ -26,25 +26,49 @@ def build_db_query(tile, session: Session):
26
26
lon_min , lat_min , lon_max , lat_max = tile_bounds (z , x , y )
27
27
28
28
geometry_column = "geometry"
29
- if dataset == "conservation-area" :
30
- geometry_column = "point"
31
29
32
30
tile_width = 256
33
31
34
32
mvt_geom_query = text (
35
- f"""
36
- SELECT ST_AsMVT(q, 'entities_layer', { tile_width } , 'geom') AS mvt
37
- FROM (
38
- SELECT ST_AsMVTGeom(
39
- { geometry_column } ,
40
- ST_MakeEnvelope(:lon_min, :lat_min, :lon_max, :lat_max, 4326),
41
- { tile_width } , 4096, true) AS geom
42
- FROM entity
43
- WHERE dataset = :dataset
44
- AND ST_Intersects({ geometry_column } , ST_MakeEnvelope(:lon_min, :lat_min, :lon_max, :lat_max, 4326))
33
+ f"""SELECT ST_AsMVT(q, :dataset, :tile_width, 'geom') FROM
34
+ (SELECT
35
+ ST_AsMVTGeom(
36
+ { geometry_column } ,
37
+ ST_MakeEnvelope(:lon_min, :lat_min, :lon_max, :lat_max, 4326),
38
+ :tile_width,
39
+ 4096,
40
+ true
41
+ ) as geom,
42
+ jsonb_build_object(
43
+ 'name', entity.name,
44
+ 'dataset', entity.dataset,
45
+ 'organisation-entity', entity.organisation_entity,
46
+ 'entity', entity.entity,
47
+ 'entry-date', entity.entry_date,
48
+ 'start-date', entity.start_date,
49
+ 'end-date', entity.end_date,
50
+ 'prefix', entity.prefix,
51
+ 'reference', entity.reference
52
+ ) AS properties
53
+ FROM entity
54
+ WHERE dataset = :dataset
55
+ AND ST_Intersects({ geometry_column } , ST_MakeEnvelope(:lon_min, :lat_min, :lon_max, :lat_max, 4326))
45
56
) AS q
46
- """
57
+ """
47
58
)
59
+ # f"""
60
+ # SELECT ST_AsMVT(q, 'entities_layer', {tile_width}, 'geom') AS mvt
61
+ # FROM (
62
+ # SELECT ST_AsMVTGeom(
63
+ # {geometry_column},
64
+ # ST_MakeEnvelope(:lon_min, :lat_min, :lon_max, :lat_max, 4326),
65
+ # {tile_width}, 4096, true) AS geom
66
+ # FROM entity
67
+ # WHERE dataset = :dataset
68
+ # AND ST_Intersects({geometry_column}, ST_MakeEnvelope(:lon_min, :lat_min, :lon_max, :lat_max, 4326))
69
+ # ) AS q
70
+ # """
71
+ # )
48
72
49
73
result = session .execute (
50
74
mvt_geom_query ,
@@ -54,6 +78,7 @@ def build_db_query(tile, session: Session):
54
78
"lon_max" : lon_max ,
55
79
"lat_max" : lat_max ,
56
80
"dataset" : dataset ,
81
+ "tile_width" : tile_width ,
57
82
},
58
83
).scalar ()
59
84
return result
0 commit comments