Skip to content

Commit

Permalink
added an sql view to track which indoor feature exists where
Browse files Browse the repository at this point in the history
  • Loading branch information
CommanderStorm committed Aug 14, 2024
1 parent d2d73d0 commit 50c6290
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server/migrations/20240814012328_indoor-features.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- Add down migration script here

drop materialized view if exists indoor_features cascade;
40 changes: 40 additions & 0 deletions server/migrations/20240814012328_indoor-features.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
-- Add up migration script here
CREATE materialized VIEW indoor_features as
with geometry(gid, geom, tags) as (SELECT way_id as gid, geom, tags
from indoor_ways
union
DISTINCT
SELECT area_id as gid, geom, tags
from indoor_polygons
union
DISTINCT
SELECT node_id as gid, geom, tags
from indoor_nodes),
geometry_in_lat_lon(gid, geom, tags) as (SELECT gid, ST_Transform(geom, 4326), tags from geometry),
-- clustered to within about ~2m of non-overlapping distance
clustered_geometry(gid, group_id, geom, tags)
as (SELECT gid,
ST_ClusterWithinWin(geom, 0.00001) OVER () AS group_id,
geom,
tags
from geometry_in_lat_lon),
clustered_features(group_id, features) AS (SELECT group_id,
jsonb_build_object(
'type', 'Feature',
'id', gid,
'geometry', ST_AsGeoJSON(geom)::jsonb,
'properties', tags
),
geom
from clustered_geometry),
grouped_features(group_id, features, convex_hull) as (SELECT group_id,
jsonb_agg(features),
ST_ConvexHull(ST_Collect(array_agg(geom)))::geometry
from clustered_features
group by group_id
order by group_id)
SELECT group_id, features, convex_hull
from grouped_features;

CREATE index indoor_features_hull_idx ON indoor_features USING GIST (convex_hull);
CREATE unique index indoor_features_group_idx ON indoor_features(group_id);

0 comments on commit 50c6290

Please sign in to comment.