Ignore:
Timestamp:
Jan 18, 2007, 9:40:24 AM (13 years ago)
Author:
Nick Burch
Message:

Re-create tiles if their source files are newer. When deciding which of multiple copies of a tile to use, go with the newest one

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/scripts/tile-processing/makeSmaller.pl

    r423 r447  
    2727my $minx, $miny, $maxx, $maxy;
    2828
     29# Sort the tiles by directory name
     30# (If we have two copies of the same tile, we want the newest one)
     31@files = sort {
     32        my ($adate) = ($a =~ /.*?\-(\d\d\d\d)$/);
     33        my ($bdate) = ($b =~ /.*?\-(\d\d\d\d)$/);
     34        if($adata && !$bdate) { return 1; }
     35        if($bdata && !$adate) { return -1; }
     36        return $adate <=> $bdate;
     37} @files;
     38
     39# Process the files into a hash, based on easting and northing
    2940foreach my $f (@files) {
    3041  $f =~ m/-(\d+)-(\d+)\./;
     
    3445}
    3546
    36 
     47# Figure out our largest easting and northing values
    3748$maxx = max(keys %tiles);
    3849$maxy = max(map { max(keys %{$tiles{$_}})} keys %tiles);
     
    5667                }
    5768
     69                # Do we need to create / re-create the tile?
     70                # (Check if tile exists, then if any of the parent tiles are newer)
     71                my $create_tile = 0;
    5872        if( (! -f $filename) && any_tiles($x, $y, \%tiles) ) {
     73                        $create_tile = 1;
     74                }
     75                foreach my $i (0..($scale -1)) {
     76                        foreach my $j (0..($scale -1)) {
     77                                if (defined $tiles{($x*$scale)+$i}{($y*$scale)+$j}) {
     78                                        my $input = $tiles{($x*$scale)+$i}{($y*$scale)+$j};
     79                                        # Is this newer than the tile?
     80                                        if(-M $input < -M $filename) {
     81                                                $create_tile = 1;
     82                                        }
     83                                }
     84                        }
     85                }
     86
     87                if($create_tile) {
    5988            print "Making $filename\n";
    6089            my $out = Image::Magick->new( size => "".($out_tile_size*$scale)."x".($out_tile_size*$scale) );
Note: See TracChangeset for help on using the changeset viewer.