File:  [Local Repository] / register / prgsrc / updatemap.pl
Revision 1.2: download - view: text, annotated - select for diffs - revision graph
Sat Oct 13 23:39:44 2001 UTC (22 years, 8 months ago) by boris
Branches: MAIN
CVS tags: HEAD
Works...

    1: #!/usr/bin/perl
    2: 
    3: =pod
    4: 
    5: =head1 NAME 
    6: 
    7: updatemap.pl - update map of regions for Club register
    8: 
    9: =head1 SYNOPSIS
   10: 
   11: updatemap.pl
   12: 
   13: =head1 DESCRIPTION
   14: 
   15: The script searches for latitudes and longitudes of CHGK regions
   16: and outputs them superimposed on the world map. The world map
   17: is taken from the gnuplot distribution. Then the script outputs
   18: an include file for register.cgi(1)
   19: 
   20: =head1 AUTHOR
   21: 
   22: Boris Veytsman
   23: 
   24: =head1 DATE
   25: 
   26: $Date: 2001/10/13 23:39:44 $
   27: 
   28: =head1 REVISION
   29: 
   30: $Revision: 1.2 $
   31: 
   32: =cut
   33: 
   34:     use strict;
   35: use DBI;
   36: my $dbh;
   37: $dbh = DBI->connect("DBI:mysql:chgk", "piataev", "") or 
   38:     die ($dbh->errstr);
   39: my $width=640;
   40: my $height=320;
   41: my $offset=160;
   42: #######################################################
   43: # Opening the files
   44: #######################################################
   45: open (INCLUDE, ">regions.html");
   46: open (GNU, ">regions.gnu");
   47: open (DAT, ">regions.dat");
   48: 
   49: print GNU <<END;
   50:  set term png medium color
   51:  set ou "regions.png"
   52:  set noborder
   53:  set nokey
   54:  set size ratio 0.5 1, 1
   55:  set tmargin 0
   56:  set bmargin 0
   57:  set lmargin 0
   58:  set rmargin 0
   59:  set noyzeroaxis
   60:  set noxtics
   61:  set noytics
   62:  set xrange [-180:180]
   63:  set yrange [-90:90]
   64: END
   65: print INCLUDE <<END;
   66:  <map name="regions">
   67: END
   68: 
   69: ##########################################################
   70: # Writing clubs coordinates
   71: ##########################################################
   72: 
   73: my $sth = $dbh->prepare ("
   74: SELECT rid,Name,Lon,Lat from Regions 
   75: where NOT ISNULL(Lat) and NOT ISNULL(Lon)");
   76: $sth->execute;
   77: while (my ($rid,$Name,$Lon,$Lat) = $sth->fetchrow_array) {
   78:     print DAT <<END;
   79:  $Lon, $Lat
   80: END
   81:     my $x=int($width*($Lon+180)/360);
   82:     my $y=int($height*(90-$Lat)/180);
   83:     print INCLUDE <<END;
   84:  <area shape="circle" coords="$x, $y, 3" 
   85:  href="/znatoki/cgi-bin/register.cgi?rid=$rid&clubs=1&level=10000" 
   86:  alt="$Name">
   87: END
   88: }
   89: 
   90: ##########################################################
   91: # Finishing up
   92: ##########################################################
   93: print INCLUDE <<END;
   94:  </map>
   95:  <img usemap="#regions" src="../images/regions.gif"
   96:  alt="Карта клубов" width=$width height=$height>
   97: END
   98: print GNU <<END;
   99:  plot 'world.dat'  with lines 3 4, 'regions.dat' with points 1
  100: END
  101: close GNU;
  102: close INCLUDE;
  103: close DAT;
  104: `gnuplot regions.gnu`;
  105: my $dim=$width.'x'.$height.'+0+'.$offset;
  106: `convert -crop $dim regions.png gif:regions.tmp`;
  107: `giftrans -t '#ffffff' regions.tmp> regions.gif`;
  108: exit 0;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>