source: subversion/applications/rendering/tilesAtHome/lib/tahproject.pm @ 12207

Last change on this file since 12207 was 11110, checked in by matthiasj, 11 years ago

move all *.pm files into lib and add lib to the library search paths

File size: 2.5 KB
Line 
1use strict;
2use Math::Trig;
3
4# =====================================================================
5# The following is duplicated from tilesGen.pl
6# =====================================================================
7
8# Setup map projection
9my $LimitY = ProjectF(RadToDeg(atan(sinh(pi)))); #atan(sinh(pi)) = 85.0511 deg
10my $LimitY2 = ProjectF(RadToDeg(atan(sinh(-&pi))));
11my $RangeY = $LimitY - $LimitY2;
12
13#-----------------------------------------------------------------------------
14# Project latitude in degrees to Y coordinates in mercator projection
15#-----------------------------------------------------------------------------
16sub ProjectF 
17{
18    my $Lat = DegToRad(shift());
19    my $Y = log(tan($Lat) + sec($Lat));
20    return($Y);
21}
22#-----------------------------------------------------------------------------
23# Project tile Y to latitude bounds
24#-----------------------------------------------------------------------------
25sub Project 
26{
27    my ($Y, $Zoom) = @_;
28   
29    my $Unit = 1 / (2 ** $Zoom);
30    my $relY1 = $Y * $Unit;
31    my $relY2 = $relY1 + $Unit;
32   
33    $relY1 = $LimitY - $RangeY * $relY1;
34    $relY2 = $LimitY - $RangeY * $relY2;
35   
36    my $Lat1 = ProjectMercToLat($relY1);
37    my $Lat2 = ProjectMercToLat($relY2);
38    return(($Lat1, $Lat2));
39}
40
41#-----------------------------------------------------------------------------
42# Project tile X to longitude bounds
43#-----------------------------------------------------------------------------
44sub ProjectL 
45{
46    my ($X, $Zoom) = @_;
47   
48    my $Unit = 360 / (2 ** $Zoom);
49    my $Long1 = -180 + $X * $Unit;
50    return(($Long1, $Long1 + $Unit)); 
51}
52
53#-----------------------------------------------------------------------------
54# Project tile coordinates to bounding box
55#-----------------------------------------------------------------------------
56sub ProjectXY
57{
58    my ($Z, $X, $Y) = @_;
59    my ($W, $E) = ProjectL($X, $Z);
60    my ($N, $S) = Project($Y, $Z);
61    return ($N, $E, $S, $W);
62}
63
64#-----------------------------------------------------------------------------
65# Convert Y units in mercator projection to latitudes in degrees (not tile coordinate Y)
66#-----------------------------------------------------------------------------
67sub ProjectMercToLat($)
68{
69    my $MercY = shift();
70    return(RadToDeg(atan(sinh($MercY))));
71}
72
73#-----------------------------------------------------------------------------
74# Angle unit-conversions
75#-----------------------------------------------------------------------------
76sub DegToRad {return pi * shift() / 180;}
77sub RadToDeg {return 180 * shift() / pi;}
78
79
801;
Note: See TracBrowser for help on using the repository browser.