]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/function/srtm/SrtmTile.java
Use data from viewfinderpanoramas.org
[GpsPrune.git] / src / tim / prune / function / srtm / SrtmTile.java
1 package tim.prune.function.srtm;
2
3 import tim.prune.data.Coordinate;
4 import tim.prune.data.DataPoint;
5
6 /**
7  * Class to represent a single tile of Srtm data, from a single hgt.zip file
8  */
9 public class SrtmTile
10 {
11         /** Latitude in degrees north/south */
12         private int _latitude = 0;
13         /** Longitude in degrees east/west */
14         private int _longitude = 0;
15
16         /**
17          * Constructor working out the tile for a single point
18          * @param inPoint data point
19          */
20         public SrtmTile(DataPoint inPoint)
21         {
22                 Coordinate latitude = inPoint.getLatitude();
23                 _latitude = (int) Math.floor(latitude.getDouble());
24                 Coordinate longitude = inPoint.getLongitude();
25                 _longitude = (int) Math.floor(longitude.getDouble());
26         }
27
28         /**
29          * Constructor working out the tile for a single point
30          * @param inLatitude latitude in degrees
31          * @param inLongitude longitude in degrees
32          */
33         public SrtmTile(int inLatitude, int inLongitude)
34         {
35                 _latitude = inLatitude;
36                 _longitude = inLongitude;
37         }
38
39         /**
40          * Check for equality
41          * @param inOther other tile object
42          * @return true if both represent same tile
43          */
44         public boolean equals(Object inOther)
45         {
46                 if (! (inOther instanceof SrtmTile))
47                 {
48                         return false;
49                 }
50                 SrtmTile otherTile = (SrtmTile) inOther;
51                 return (_latitude == otherTile._latitude) &&
52                         (_longitude == otherTile._longitude);
53         }
54
55         public int hashCode()
56         {
57                 return 360 * _latitude + _longitude;
58         }
59
60         /** @return latitude as int */
61         public int getLatitude() {
62                 return _latitude;
63         }
64
65         /** @return longitude as int */
66         public int getLongitude() {
67                 return _longitude;
68         }
69
70         /**
71          * @return filename of tile
72          */
73         public String getTileName()
74         {
75                 return (_latitude >= 0?"N":"S")
76                         + (Math.abs(_latitude) < 10?"0":"")
77                         + Math.abs(_latitude)
78                         + (_longitude >= 0?"E":"W")
79                         + (Math.abs(_longitude) < 100?"0":"")
80                         + (Math.abs(_longitude) < 10?"0":"")
81                         + Math.abs(_longitude);
82         }
83
84         public SrtmSource findBestCachedSource()
85         {
86                 SrtmSource[] sources = {
87                         new SrtmGl1Source(),
88                         new SrtmViewfinderSource(),
89                         new Srtm3Source(),
90                 };
91                 for (int i = 0; i < sources.length; i++)
92                 {
93                         if (sources[i].isCached(this))
94                         {
95                                 return sources[i];
96                         }
97                 }
98                 return null;
99         }
100 }