File: create_spatial_ref_sys_config_dump.pl

package info (click to toggle)
postgis 2.3.1%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 58,660 kB
  • ctags: 10,181
  • sloc: ansic: 132,858; sql: 131,148; xml: 46,460; sh: 4,832; perl: 4,476; makefile: 2,749; python: 1,198; yacc: 442; lex: 131
file content (56 lines) | stat: -rwxr-xr-x 1,215 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/perl

#
# PostGIS - Spatial Types for PostgreSQL
# http://postgis.net
#
# Copyright (C) 2016 Sandro Santilli <strk@kbt.io>
#
# This is free software; you can redistribute and/or modify it under
# the terms of the GNU General Public Licence. See the COPYING file.
#

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;
  #print "min:$min\n";
  # Find upper bound
  my $max = $min;
  while (@SRIDS)
  {
    #print "next:$SRIDS[@SRIDS-1]\n";
    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 ")');"
#mark_editable_objects.sql.in