| 1 | procedure to check all the tables listed in GeometryColumn table for invalid geometries. |
| 2 | |
| 3 | The procedure ask as parameter table for the results. |
| 4 | If all tables has valid geometries the table will be empty otherwise it has 1 record for every table with invalid geometries. |
| 5 | The record will have two column the query used and the number of invalid geometries found. |
| 6 | |
| 7 | {{{ |
| 8 | CREATE OR REPLACE FUNCTION massive_check_geometry_validity(tabris text) |
| 9 | RETURNS VOID AS $$ |
| 10 | DECLARE |
| 11 | sql text; |
| 12 | sql2 text; |
| 13 | _rec1 record; |
| 14 | ris integer; |
| 15 | BEGIN |
| 16 | sql := 'DROP TABLE IF EXISTS ' || quote_ident(tabris) ||';'; |
| 17 | execute(sql); |
| 18 | sql := 'CREATE TABLE ' || quote_ident(tabris) || ' (id serial, query TEXT, conteggio INTEGER);'; |
| 19 | sql := 'select ''select count(*) from '' || quote_ident(f_table_schema) || ''.'' || quote_ident(f_table_name) || '' where ST_IsValid('' || f_geometry_column || '')=false;'' as query from public.geometry_columns'; |
| 20 | |
| 21 | FOR _rec1 IN execute (sql) |
| 22 | LOOP |
| 23 | raise notice 'executing: %', _rec1.query; |
| 24 | execute(_rec1.query) into ris; |
| 25 | END LOOP; |
| 26 | |
| 27 | RETURN; |
| 28 | END; |
| 29 | $$ LANGUAGE 'plpgsql' STRICT; |
| 30 | |
| 31 | -- to use execute this query: |
| 32 | -- select massive_check_geometry_validity('result_table'); |
| 33 | -- |
| 34 | }}} |
| 35 | |
| 36 | Happy checking, |
| 37 | Andrea Peri. |