Changes between Initial Version and Version 1 of UsersWikiCheckInvalidGeometriesFromGeometryColumns


Ignore:
Timestamp:
May 8, 2011, 9:07:27 AM (13 years ago)
Author:
aperi2007
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • UsersWikiCheckInvalidGeometriesFromGeometryColumns

    v1 v1  
     1procedure to check all the tables listed in GeometryColumn table for invalid geometries.
     2
     3The procedure ask as parameter  table for the results.
     4If all tables has valid geometries the table will be empty otherwise it has 1 record for every table with invalid geometries.
     5The record will have two column the query used and the number of invalid geometries found.
     6
     7{{{
     8CREATE OR REPLACE FUNCTION massive_check_geometry_validity(tabris text)
     9RETURNS VOID AS $$
     10DECLARE
     11        sql text;
     12        sql2 text;
     13    _rec1 record;
     14    ris integer;
     15BEGIN
     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;
     28END;
     29$$ LANGUAGE 'plpgsql' STRICT;
     30
     31-- to use execute this query:
     32--     select massive_check_geometry_validity('result_table');
     33--
     34}}}
     35
     36Happy checking,
     37Andrea Peri.