source: subversion/applications/rendering/tilesAtHome/lib/OceanTiles.pm @ 11415

Last change on this file since 11415 was 11213, checked in by Dirk Stoecker, 11 years ago

added lowzoom directly into client, currently not yet default

File size: 1.8 KB
Line 
1# This class encapsulates access to the oceantiles database.
2=pod
3
4=head1 Oceantiles status data access
5
6=head2 License and authors
7
8 # Copyright 2008, by Dirk Stöcker
9 # Copyright 2007, by Oliver White
10 # licensed under the GPL v2 or (at your option) any later version.
11
12=head2 Overview
13
14The I<OceanTiles> object encapsulates the access to the tile status database.
15
16=cut
17
18#see rest of the pd documentation is at the end of this file. Please keep
19# the description of public methofs/attributes up to date
20package OceanTiles;
21
22use warnings;
23use strict;
24
25#-----------------------------------------------------------------------------
26# OceanTiles can be instantiated with ->new(filename) or ->new().
27# e.g. my $r = new Request or my $r = Request->new("oceantiles_12.dat")
28#-----------------------------------------------------------------------------
29sub new
30{
31    my $class = shift;
32    my $self = {
33        zoom => 12,
34    };
35    my $filename = shift || "png2tileinfo/oceantiles_".$self->{zoom}.".dat";
36    my $fh;
37    return undef if !open($fh,"<",$filename);
38    $self->{file} = $fh;
39    bless $self, $class;
40    return $self;
41}
42
43# pass x and y coordinate
44sub getState
45{
46    my ($self, $X, $Y) = @_;
47
48    my $tileoffset = ($Y * (2**$self->{zoom})) + $X;
49
50    seek $self->{file}, int($tileoffset / 4), 0;
51    my $buffer;
52    read $self->{file}, $buffer, 1;
53    $buffer = substr( $buffer."\0", 0, 1 );
54    $buffer = unpack "B*", $buffer;
55    my $str = substr( $buffer, 2*($tileoffset % 4), 2 );
56
57    # $str eq "00" => unknown (not yet checked)
58    # $str eq "01" => known land
59    # $str eq "10" => known sea
60    # $str eq "11" => known edge tile
61
62    if ($str eq "10") { return "sea"; }
63    elsif ($str eq "01") { return "land"; }
64    elsif ($str eq "11") { return "mixed"; }
65    return "unknown";
66}
67
681;
Note: See TracBrowser for help on using the repository browser.