File: create_spatial_ref_sys_config_dump.pl

package info (click to toggle)
postgis 3.3.2%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 87,748 kB
  • sloc: ansic: 158,671; sql: 91,546; xml: 54,004; cpp: 12,339; sh: 5,187; perl: 5,100; makefile: 3,085; python: 1,205; yacc: 447; lex: 151; javascript: 6
file content (55 lines) | stat: -rwxr-xr-x 1,199 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env 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>) {
  /^\(([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