use warnings;
use strict;
(@ARGV) ||
die "Usage: perl $0 <spatial_ref_sys>\n" .
"Creates an SQL script to mark system records of spatial_ref_sys.\n";
my $SRSFILE=$ARGV[0];
open SRSFILE, "<$SRSFILE" || die "Can't open $SRSFILE for reading\n";
my @SRIDS = ();
while (<SRSFILE>) {
/^INSERT/ || next;
/\(([0-9]*),/ || next;
push @SRIDS, $1;
}
@SRIDS = sort {$b <=> $a} @SRIDS;
print "SELECT pg_catalog.pg_extension_config_dump('spatial_ref_sys',";
print " 'WHERE NOT (\n";
my $OR="";
while (@SRIDS)
{
my $min = pop @SRIDS;
my $max = $min;
while (@SRIDS)
{
last if ( $SRIDS[@SRIDS-1] != $max+1 );
$max = pop @SRIDS
};
if ( $min != $max ) {
print $OR . "srid BETWEEN $min AND $max\n";
} else {
print $OR . "srid = $min\n";
}
$OR = "OR ";
}
print join ",\n", @SRIDS;
print ")');"