source: subversion/applications/rendering/png2tileinfo/process-changes @ 27713

Last change on this file since 27713 was 13825, checked in by stephankn, 11 years ago

set eol-style to let svn take care of correct line endings

  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 3.2 KB
RevLine 
[4204]1#!/usr/bin/perl -w
2
3# This program grabs the changes to oceantiles submitted by users via
4# informationfreeway and applies them to the oceantiles_12.png file.
5#
6# The file is grabbed from http://osm.test.le.ac.uk/tiles.txt and processed.
7# There is no attempt (yet) to pick up where the previous run left off,
8# however it does note when the request would have no change.
9#
10# Todo:
11# - Automatically request a rerender of changed tiles. Currently not done as
12#   client do not regularly update their oceantiles db
13
14# written by Martijn van Oosterhout <kleptog@gmail.com>
15
16use strict;
17use LWP::Simple;
18
19use GD;
20use strict;
21use bytes;
22
23use constant TILETYPE_UNKNOWN => 0;
24use constant TILETYPE_LAND => 1;
25use constant TILETYPE_SEA => 2;
26use constant TILETYPE_TILE => 3;
27
28#
29#
30#
31sub get_type 
32{
33  my($image, $x, $y) = @_;
34
35  my($r,$g,$b) = $image->rgb( $image->getPixel( $x,$y ) );
36 
37  return TILETYPE_LAND if $r == 0 && $g == 255 && $b == 0;
38  return TILETYPE_SEA if $r == 0 && $g == 0   && $b == 255;
39  return TILETYPE_TILE if $r == 255 && $g == 255 && $b == 255;
40  return TILETYPE_UNKNOWN if $r == 0 && $g == 0 && $b == 0;
41 
42  die "Wierd tiletype at [$x,$y]: ($r,$g,$b)\n";
43}
44
45#
46#
47#
48sub set_type
49{
50  my($image, $x, $y, $type) = @_;
51  my $color;
52
53  # Resolve not Allocate so we don't run out of colors
54  $color = $image->colorResolve(0,0,255) if($type == TILETYPE_SEA);
55  $color = $image->colorResolve(0,255,0) if($type == TILETYPE_LAND);
56  $color = $image->colorResolve(255,255,255) if($type == TILETYPE_TILE);
57  die if not defined $color;
58  print STDERR "Setting $x,$y to $color\n";
59  $image->setPixel($x,$y, $color);
60}
61
62
63
64my $data = get("http://osm.test.le.ac.uk/tiles.txt");
65
66if( not defined $data )
67{
68  die "Couldn't fetch tile changes\n";
69}
70
71my @data = split /\n/, $data;
72
73my %hash;
74my @todo;
75
76my($done,$unnecessary,$double) = (0,0,0);
77
78for my $line (@data)
79{
[4207]80  my($x,$y,$zoom,$type,$time,$score) = split /,/,$line;
[4204]81
[5453]82  next unless $score =~ /^\d+(\.\d+)?$/ and $score >= 1;
[4204]83  next unless $zoom =~ /^\d+$/ and $zoom==12;
84  next unless $x =~ /^\d+$/ and $x >= 0 and $x < 4096;
85  next unless $y =~ /^\d+$/ and $y >= 0 and $y < 4096;
86  next unless $type =~ /^(land|sea|mixed)$/;
87
88  if( not defined $hash{$x.",".$y} )
89  {
90    push @todo, [$x,$y];
91  }
92  else
93  {
94    $double++;
95  }
96  $hash{$x.",".$y} = $type;
97}
98
99open my $world_fh, "<oceantiles_12.png" or die "Couldn't open oceantiles_12.png ($!)\n";
[6209]100# use binmode so it works on windows too
101binmode $world_fh;
[4204]102my $world_im = GD::Image->newFromPng( $world_fh, 1 );
103close $world_fh;
104
105# Autoflush on
106$|=1;
107
108for my $entry (@todo)
109{
110  my ($x,$y) = @$entry;
111  my $type  = $hash{$x.",".$y};
112
113  my $oldtype = get_type( $world_im, $x, $y );
114  my $newtype = 0; 
115  $newtype = TILETYPE_LAND if ($type eq "land");
116  $newtype = TILETYPE_SEA  if ($type eq "sea");
117  $newtype = TILETYPE_TILE if ($type eq "mixed");
118
119  if( $newtype != $oldtype )
120  {
[4207]121    print "Setting $x, $y to $type: ";
[4204]122    set_type($world_im, $x, $y, $newtype);
123    print "done ($newtype != $oldtype)\n";
124    $done++;
125  }
126  else
127  {
[4207]128#    print "unnecessary\n";
[4204]129    $unnecessary++;
130  }
131}
132
133print "Complete: done($done), unnecessary($unnecessary), double($double)\n";
134
135open $world_fh, ">oceantiles_12.png" or die;
[6209]136# use binmode so it works on windows too
137binmode $world_fh;
[4204]138print $world_fh $world_im->png;
139close $world_fh;
140
Note: See TracBrowser for help on using the repository browser.