Wikipedia Diskussion:Archiv/GEOnet Names Server (PostgreSQL)

bin/geokoordinate

Bearbeiten
#! /usr/bin/env perl

for my $name (@ARGV)
{
   my $R;
   open R, "psql -c \"select LAT, LONG, DSG, DMS_LAT, DMS_LONG, ADM1, FULL_NAME \
           from GEONET where CC1 = 'GM' and FULL_NAME_ND like '%$name%';\" |"
   or die "could not psql select $name: $!";
   for (<R>;) { 
       /^ *5+/ or next;
       if (/([^|]*)[|]([^|]*)[|]([^|]*)[|]([^|]*)[|]([^|]*)[|]([^|]*)[|]([^|]*)/) {
           my ($LAT,$LONG,$DSG,$DMS_LAT,$DMS_LONG,$ADM1,$NAME) = ($1,$2,$3,$4,$5,$6,$7);
           $LAT =~ s/\s+//sg;
           $LONG =~ s/\s+//sg;
           $DSG =~ s/\s+//sg;
           $DMS_LAT =~ s/\s+//sg;
           $DMS_LONG =~ s/\s+//sg;
           $ADM1 =~ s/\s+//sg;
           $NAME =~ s/^\s+//s; $NAME =~ s/\s+$//s;
           $DMS_LAT =~ s/(\d\d)(\d\d)$/°$1\'$2/;
           $DMS_LONG =~ s/(\d\d)(\d\d)$/°$1\'$2/;
           $dms_LAT  = $DMS_LAT;  $dms_LAT  =~ s/00$//;
           $dms_LONG = $DMS_LONG; $dms_LONG =~ s/00$//;
           print "\n<!-- $NAME ($ADM1) -->;\n";
           print "{{Koordinate|${LAT}_N_${LONG}_E",
           "|$dms_LAT\&nbsp;N $dms_LONG\&nbsp;O}}","\n";
           print "{{Geokoordinate|${LAT}_N_${LONG}_E_type:${DSG}",
           "|$DMS_LAT N $DMS_LONG O}}"," <!-- GEOnet -->;\n";
       } else {
           print ": $_";
       }
   }
   close R;
}