]> gitweb.fperrin.net Git - GpsPrune.git/blob - src/tim/prune/function/srtm/SrtmTile.java
Version 20.1, December 2020
[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         @Override
40         public int hashCode()
41         {
42                 return _latitude * 1000 + _longitude;
43         }
44
45         /**
46          * Check for equality
47          * @param inOther other tile object
48          * @return true if both represent same tile
49          */
50         @Override
51         public boolean equals(Object inOther)
52         {
53                 if (inOther == null || inOther.getClass() != getClass()) {
54                         return false;
55                 }
56                 SrtmTile otherTile = (SrtmTile) inOther;
57                 return (_latitude == otherTile._latitude) && (_longitude == otherTile._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                         + ".hgt.zip";
83         }
84 }