source: subversion/applications/rendering/tilesAtHome/mercatorize.pl @ 6008

Last change on this file since 6008 was 4268, checked in by spaetz, 13 years ago

outsource mercatorization to mercatorize.pl. This one has a dependency on Geo::Proj4 which is needed if the mercator preprocessor is called.

File size: 956 bytes
Line 
1#!/usr/bin/perl
2use Geo::Proj4;
3#project lat lon values into mlat mlon values, using mercator projection
4# it takes infile, outfile as arguments
5
6mercatorize(@ARGV);
7
8#-----------------------------------------------------------------------------
9# Transform lat/lon to mercator coordinates (in preprocess)
10#-----------------------------------------------------------------------------
11sub mercatorize
12{
13    my $proj = Geo::Proj4->new(proj => "merc");
14    my ($inputFile) = @_;
15
16    open(my $fr, "<", $inputFile) || return;
17    while (my $line = <$fr>) {
18        my ($lat, $lon)=undef;
19        if ($line =~ /^(.*lat=['"]?)([^'"])+(['"]?.*$)/) {
20            $lat = $2; 
21        } 
22        if ($line =~ /^(.*lon=['"]?)([^'"])+(['"]?.*$)/) {
23            $lon = $2; 
24        }
25        if ($lat or $lon) {
26            my ($x, $y) = $proj->forward($lat, $lon);
27            $line =~ s/(lat=['"][^'"]+['"]|lon=['"][^'"]+['"])/$1 mlat="$y" mlon="$x"/;
28        }
29        print $line;
30    }
31    close $fr; 
32    return 1;
33}
34
Note: See TracBrowser for help on using the repository browser.