source: trunk/npemap.org.uk/scripts/tile-processing/make-scaled-wld.pl @ 467

Last change on this file since 467 was 467, checked in by Nick Burch, 13 years ago

Add world making scripts

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 1.5 KB
Line 
1#!/usr/bin/perl
2# Makes .wld files for NPE tiles
3#
4# Nick Burch - 27/10/2006
5
6use strict;
7
8my $scale = shift;
9if($scale && $scale =~ /^\d+$/ && -d "scaled$scale") {
10        # Good
11} else {
12        print "Use:\n";
13        print "   make-scaled-wld.pl <scale>\n";
14        print "\nWhere the directory scaled<scale>/ is a child of the current one\n";
15        exit;
16}
17
18# Files are in:
19#   scaled<scale>/<sc easting>/<sc northing>.jpg
20
21# Loop over the scaled eastings
22my @eastings = `cd scaled${scale} && find . -maxdepth 1 -type d | grep -v '^.\$' | sed s#./##`;
23
24foreach my $e (@eastings) {
25        chomp $e;
26        print "Processing scaled${scale}/$e/\n";
27
28        # Get northings
29        my @files = `cd scaled${scale}/$e/ && find . -maxdepth 1 -type f -name '*.jpg' | sed s#./##`;
30        foreach my $f (@files) {
31                chomp $f;
32                my ($n) = ($f =~ /^(.*?)\.jpg$/);
33                ##print "$e - $n - $f\n";
34
35                # Note - Add 1 to northing, as y offset is -ve
36
37                my ($easting, $northing) = ( (($e) * $scale), (($n+1) * $scale) );
38                $easting *= 1000;
39                $northing *= 1000;
40
41                # Write the .wld file
42                open(WLD, "> scaled${scale}/${e}/${n}.wld");
43
44                # Images are 125x125, and cover one grid square at scale 1
45
46                # size of pixel in x direction
47                print WLD (1000 * $scale / 125)."\n";
48
49                # rotation term for row - typically zero
50                # rotation term for column - typically zero
51                print WLD "0.000\n0.000\n";
52
53                # size of pixel in y direction
54                print WLD (-1000 * $scale / 125)."\n";
55
56                # x coordinate of centre of upper left pixel in map units
57                print WLD "$easting\n";
58
59                # y coordinate of centre of upper left pixel in map units
60                print WLD "$northing\n";
61
62                close WLD;
63        }
64}
65
Note: See TracBrowser for help on using the repository browser.