Changeset 29877 in osm for applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap
- Timestamp:
- 2013-08-25T20:50:29+02:00 (11 years ago)
- Location:
- applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/HgtReader.java
r29876 r29877 20 20 */ 21 21 public class HgtReader { 22 private static final int SECONDS_PER_MINUTE = 60; 23 22 24 public static final String HGT_EXT = ".hgt"; 23 25 … … 25 27 public static final int HGT_RES = 3; // resolution in arc seconds 26 28 public static final int HGT_ROW_LENGTH = 1201; // number of elevation values per line 29 public static final int HGT_VOID = -32768; // magic number which indicates 'void data' in HGT file 27 30 28 31 private HashMap<String, ShortBuffer> cache = new HashMap<String, ShortBuffer>(); … … 38 41 // but is not there' 39 42 cache.put(file, null); 40 // Try all otherresource directories43 // Try all resource directories 41 44 for (String location : Main.pref.getAllPossiblePreferenceDirs()) { 42 45 String fullPath = new File(location + File.separator + "elevation", file).getPath(); 43 46 44 System.out.println( "Search in " + location);47 System.out.println(fullPath); 45 48 File f = new File(fullPath); 46 49 if (f.exists()) { … … 108 111 109 112 // see http://gis.stackexchange.com/questions/43743/how-to-extract-elevation-from-hgt-file 110 double fLat = frac(coor.lat()) * 60;111 double fLon = frac(coor.lon()) * 60;113 double fLat = frac(coor.lat()) * SECONDS_PER_MINUTE; 114 double fLon = frac(coor.lon()) * SECONDS_PER_MINUTE; 112 115 113 114 int row = (int)Math.round(fLat * 60/ HGT_RES);115 int col = (int)Math.round(fLon * 60/ HGT_RES);116 // compute offset within HGT file 117 int row = (int)Math.round(fLat * SECONDS_PER_MINUTE / HGT_RES); 118 int col = (int)Math.round(fLon * SECONDS_PER_MINUTE / HGT_RES); 116 119 117 120 row = HGT_ROW_LENGTH - row; 118 121 int cell = (HGT_ROW_LENGTH* (row - 1)) + col; 119 122 120 return sb.get(cell); 123 // valid position in buffer? 124 if (cell < sb.limit()) { 125 short ele = sb.get(cell); 126 // check for data voids 127 if (ele == HGT_VOID) { 128 return Double.NaN; 129 } else { 130 return ele; 131 } 132 } else { 133 return Double.NaN; 134 } 121 135 } 122 136 -
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/tests/HgtReaderTest.java
r29876 r29877 38 38 double d = hr.getElevationFromHgt(l); 39 39 System.out.println(d); 40 assert(!Double.isNaN(d)); 40 assertFalse("Data missing or void for coor " + l, Double.isNaN(d)); 41 41 42 assertEquals((int)d, expHeight); 42 43 }
Note:
See TracChangeset
for help on using the changeset viewer.