Changeset 675


Ignore:
Timestamp:
Jan 18, 2009, 2:47:38 PM (11 years ago)
Author:
Nick Burch
Message:

Map legend support for meta files

File:
1 edited

Legend:

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

    r635 r675  
    11#!/usr/bin/perl
    2 # 
     2#
    33# Copyright (c) 2006-2007 David Sheldon and Nick Burch
    44# Permission is hereby granted, free of charge, to any person obtaining a
     
    5959# Process the files into a hash, based on easting and northing
    6060foreach my $f (@files) {
    61   $f =~ m/-(\d+)-(\d+)\./;
     61  $f =~ m/-(\d+)-(\-?\d+)\./;
    6262  my ($x, $y) = ($1 +0, $2 +0);
    6363  $tiles{$x} ||= {};
     
    6868$maxx = max(keys %tiles);
    6969$maxy = max(map { max(keys %{$tiles{$_}})} keys %tiles);
     70$miny = min(map { min(keys %{$tiles{$_}})} keys %tiles);
    7071
    7172# The meta info's to re-create
     
    7778
    7879foreach my $x (0..($maxx/$scale)) {
    79     foreach my $y (0..($maxy/$scale)) {
     80    foreach my $y (($miny/$scale)..($maxy/$scale)) {
     81        # Note - channel island maps with negative y values will end up
     82        #   as scaledX/ddd/-dd.jpg, as the - counts as a digit
    8083        my $filename = sprintf("%s/%03d/%03d.jpg", $outdir, $x, $y);
     84
    8185                my $meta_filename = sprintf("meta1/%03d.txt", $x);
    8286        my $outdir = sprintf("%s/%03d/", $outdir, $x);
     
    148152}
    149153
     154# Load in our list of what legends apply
     155my %legends;
     156open(LEGENDS, "<../legends/which.txt");
     157while(my $line = <LEGENDS>) {
     158    chomp $line;
     159    unless($line) { next; }
     160    if($line =~ /^(\d+.*?-19\d\d)\s+([\w\d\-\_]+)\s*$/) {
     161        my ($dir,$legend) = ($1,$2);
     162        $legends{$dir} = $legend;
     163    } elsif($line =~ /^(\d+.*?-tiles-WO)\s+([\w\d\-\_]+)\s*$/) {
     164        my ($dir,$legend) = ($1,$2);
     165        $legends{$dir} = $legend;
     166    } else {
     167        warn("Invalid legends line: '$line'\n");
     168    }
     169}
     170
    150171# Re-create the meta files
    151172foreach my $easting (sort keys %update_meta) {
    152173        my $meta_filename = sprintf("meta1/%03d.txt", $easting);
    153174        open(META, ">$meta_filename");
    154         print META "# easting,northing,sheet,year\n";
     175        print META "# easting,northing,sheet,year,legend\n";
    155176       
    156177        foreach my $northing (sort keys %{$tiles{$easting}}) {
     
    158179                my ($sheet) = ($file =~ /^(\d+\w?)\-/);
    159180                my ($year) = ($file =~ /^\d+\w?\-tiles\-(\d+)/);
    160                 print META "${easting},${northing},$sheet,$year\n";
     181                my ($dir) = ($file =~ /^(\d+.*?)\//);
     182
     183        my $legend = $legends{$dir} or "";
     184
     185        # Handle Channel Island maps
     186        if(!$sheet && $file =~ /^([GJ]\w+)\-tiles\-(\d+)/) {
     187            $sheet = $1;
     188            $year = $2;
     189        }
     190
     191                print META "${easting},${northing},$sheet,$year,$legend\n";
    161192        }
    162193
Note: See TracChangeset for help on using the changeset viewer.