Skip to content

Commit

Permalink
feat: use st_subdivide function to improve the speed
Browse files Browse the repository at this point in the history
  • Loading branch information
YingtingChen committed Sep 20, 2024
1 parent 1e9d7f0 commit 0eca5fc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
12 changes: 8 additions & 4 deletions db/sql/deploy/buildings_reference/functions/suburb_locality.sql
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,15 @@ COMMENT ON FUNCTION buildings_reference.suburb_locality_attribute_update_buildin
CREATE OR REPLACE FUNCTION buildings_reference.suburb_locality_geometry_update_building_outlines(varchar)
RETURNS integer AS
$$
UPDATE buildings.building_outlines
SET suburb_locality_id = buildings_reference.suburb_locality_intersect_polygon(shape),
WITH sub_tas AS (
SELECT ST_Subdivide(ST_SetSRID(ST_GeometryFromText($1), 2193)) AS shape
)
UPDATE buildings.building_outlines bo
SET suburb_locality_id = buildings_reference.suburb_locality_intersect_polygon(bo.shape),
last_modified = NOW()
WHERE ST_Intersects(shape, ST_SetSRID(ST_GeometryFromText($1), 2193))
AND suburb_locality_id != buildings_reference.suburb_locality_intersect_polygon(shape)
FROM sub_tas ta
WHERE ST_Intersects(bo.shape, ta.shape)
AND suburb_locality_id != buildings_reference.suburb_locality_intersect_polygon(bo.shape)
RETURNING building_outline_id;
$$
LANGUAGE sql VOLATILE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,12 +171,16 @@ COMMENT ON FUNCTION buildings_reference.territorial_authority_attribute_update_b
CREATE OR REPLACE FUNCTION buildings_reference.territorial_authority_geometry_update_building_outlines(varchar)
RETURNS integer AS
$$
UPDATE buildings.building_outlines
SET territorial_authority_id = buildings_reference.territorial_authority_grid_intersect_polygon(shape),
last_modified = NOW()
WHERE ST_Intersects(shape, ST_SetSRID(ST_GeometryFromText($1), 2193))
AND territorial_authority_id != buildings_reference.territorial_authority_grid_intersect_polygon(shape)
RETURNING building_outline_id;
WITH sub_tas AS (
SELECT ST_Subdivide(ST_SetSRID(ST_GeometryFromText($1), 2193)) AS shape
)
UPDATE buildings.building_outlines bo
SET territorial_authority_id = buildings_reference.territorial_authority_grid_intersect_polygon(bo.shape),
last_modified = NOW()
FROM sub_tas ta
WHERE ST_Intersects(bo.shape, ta.shape)
AND territorial_authority_id != buildings_reference.territorial_authority_grid_intersect_polygon(bo.shape)
RETURNING building_outline_id;
$$
LANGUAGE sql VOLATILE;

Expand Down

0 comments on commit 0eca5fc

Please sign in to comment.