Skip to content

Commit

Permalink
Update boundaries centroid
Browse files Browse the repository at this point in the history
  • Loading branch information
Rub21 committed Dec 6, 2024
1 parent 32ea85e commit 6f536f6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
31 changes: 14 additions & 17 deletions images/tiler-imposm/queries/admin_boundaries_centroids.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
-- Create a function that updates the osm_admin_boundaries_centroid_* if relations has labels or not
-- Create a function that updates the osm_admin_boundaries_centroid_* if relations have labels or not
CREATE OR REPLACE FUNCTION update_admin_boundaries_centroids()
RETURNS void AS $$
DECLARE
table_name text;
BEGIN
-- Loop through all table names that match the pattern
FOR table_name IN
SELECT table_name
FROM information_schema.tables
WHERE table_name LIKE 'osm_admin_boundaries_centroid%'
SELECT t.table_name
FROM information_schema.tables AS t
WHERE t.table_name LIKE 'osm_admin_boundaries_centroid%'
LOOP
-- Dynamically execute the update query for each table
BEGIN
Expand All @@ -21,34 +21,31 @@ BEGIN
WHERE role = ''label''
);', table_name);
EXCEPTION WHEN OTHERS THEN
-- Log an error if the update fails for a specific table
RAISE NOTICE 'Error updating table %: %', table_name, SQLERRM;
RAISE NOTICE ''Error updating table %: %'', table_name, SQLERRM;
END;
END LOOP;

-- Log completion
RAISE NOTICE 'Update completed for all matching tables.';
RAISE NOTICE ''Update completed for all matching tables.'';
END;
$$ LANGUAGE plpgsql;


-- Create a function and trigger that will update every time a new admin area is inserted or updated in osm_admin_areas table

-- Create a function that updates the osm_admin_boundaries_centroid_* if relations have labels or not
CREATE OR REPLACE FUNCTION create_update_has_label_triggers(pattern text)
RETURNS void AS $$
DECLARE
table_name text;
BEGIN
-- Loop through all tables matching the provided pattern
FOR table_name IN
SELECT table_name
FROM information_schema.tables
WHERE table_name LIKE pattern
SELECT t.table_name
FROM information_schema.tables AS t
WHERE t.table_name LIKE pattern
LOOP
-- Create a dynamic function for each table
EXECUTE format(
'CREATE OR REPLACE FUNCTION %I_update_has_label_row()
RETURNS TRIGGER AS $$
RETURNS TRIGGER AS $trigger_body$
BEGIN
IF EXISTS (
SELECT 1
Expand All @@ -61,7 +58,7 @@ BEGIN
END IF;
RETURN NEW;
END;
$$ LANGUAGE plpgsql;',
$trigger_body$ LANGUAGE plpgsql;',
table_name
);

Expand All @@ -82,8 +79,8 @@ END;
$$ LANGUAGE plpgsql;


-- Execute update_admin_boundaries_centroids when the import is done
-- Execute the update function when the import is done
SELECT update_admin_boundaries_centroids();

-- Execute for tiger creattinog when new data is added or updated
-- Execute the function to create triggers for tables matching the pattern
SELECT create_update_has_label_triggers('osm_admin_boundaries_centroid%');
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ SELECT
FROM
osm_admin_boundaries_centroid_z0_2
WHERE
geometry && !BBOX!
has_label = 0
AND geometry && !BBOX!
"""

[[providers.layers]]
Expand All @@ -41,7 +42,8 @@ SELECT
FROM
osm_admin_boundaries_centroid_z3_5
WHERE
geometry && !BBOX!
has_label = 0
AND geometry && !BBOX!
"""

[[providers.layers]]
Expand All @@ -64,10 +66,7 @@ SELECT
FROM
osm_admin_boundaries_centroid_z6_7
WHERE
admin_level IN (1,2,3,4,5,6)
AND has_label = 0
AND name IS NOT NULL
AND name <> ''
has_label = 0
AND geometry && !BBOX!
"""

Expand All @@ -91,7 +90,8 @@ SELECT
FROM
osm_admin_boundaries_centroid_z8_9
WHERE
geometry && !BBOX!
has_label = 0
AND geometry && !BBOX!
"""

[[providers.layers]]
Expand All @@ -114,7 +114,8 @@ SELECT
FROM
osm_admin_boundaries_centroid_z10_12
WHERE
geometry && !BBOX!
has_label = 0
AND geometry && !BBOX!
"""


Expand All @@ -138,7 +139,8 @@ SELECT
FROM
osm_admin_boundaries_centroid_z13_15
WHERE
geometry && !BBOX!
has_label = 0
AND geometry && !BBOX!
"""

[[providers.layers]]
Expand All @@ -161,5 +163,6 @@ SELECT
FROM
osm_admin_boundaries_centroid_z16_20
WHERE
geometry && !BBOX!
has_label = 0
AND geometry && !BBOX!
"""

0 comments on commit 6f536f6

Please sign in to comment.