Changeset 35967 in osm for applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap
- Timestamp:
- 2022-04-28T21:26:26+02:00 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/ElevationProfile/src/org/openstreetmap/josm/plugins/elevation/HgtReader.java
r35964 r35967 20 20 import org.openstreetmap.josm.data.Preferences; 21 21 import org.openstreetmap.josm.data.coor.ILatLon; 22 import org.openstreetmap.josm.data.coor.LatLon;23 22 import org.openstreetmap.josm.io.Compression; 24 23 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 83 82 } 84 83 85 public static Bounds read(File file) throws FileNotFoundException,IOException {84 public static Bounds read(File file) throws IOException { 86 85 String location = file.getName(); 87 86 for (String ext : COMPRESSION_EXT) { … … 91 90 // Overwrite the cache file (assume that is desired) 92 91 cache.put(location, sb); 93 Pattern pattern = Pattern.compile("( N|S)([0-9]{2})(E|W)([0-9]{3})");92 Pattern pattern = Pattern.compile("([NS])(\\d{2})([EW])(\\d{3})"); 94 93 Matcher matcher = pattern.matcher(location); 95 94 if (matcher.lookingAt()) { 96 int lat = (matcher.group(1) == "S"? -1 : 1) * Integer.parseInt(matcher.group(2));97 int lon = (matcher.group(3) == "W"? -1 : 1) * Integer.parseInt(matcher.group(4));95 int lat = ("S".equals(matcher.group(1)) ? -1 : 1) * Integer.parseInt(matcher.group(2)); 96 int lon = ("W".equals(matcher.group(3)) ? -1 : 1) * Integer.parseInt(matcher.group(4)); 98 97 return new Bounds(lat, lon, lat + 1, lon + 1); 99 98 } … … 101 100 } 102 101 103 private static short[][] readHgtFile(String file) throws FileNotFoundException,IOException {102 private static short[][] readHgtFile(String file) throws IOException { 104 103 CheckParameterUtil.ensureParameterNotNull(file); 105 104 … … 135 134 * @return the elevation value or <code>Double.NaN</code>, if no value is present 136 135 */ 137 public static double readElevation(LatLon coor) { 136 public static double readElevation(ILatLon coor) { 138 137 String tag = getHgtFileName(coor); 139 138 return readElevation(coor, tag); … … 205 204 double lonDegrees = latLon.lon(); 206 205 207 float fraction = ((float) SRTM_EXTENT) / mapSize;208 int latitude = (int) Math. floor(Math.abs(latDegrees - (int)latDegrees) / fraction);209 int longitude = (int) Math. floor(Math.abs(lonDegrees - (int)lonDegrees) / fraction);206 float fraction = ((float) SRTM_EXTENT) / (mapSize - 1); 207 int latitude = (int) Math.round(frac(latDegrees) / fraction); 208 int longitude = (int) Math.round(frac(lonDegrees) / fraction); 210 209 if (latDegrees >= 0) 211 210 { 212 latitude = mapSize - 1 -latitude;211 latitude = mapSize - latitude - 1; 213 212 } 214 213 if (lonDegrees < 0) 215 214 { 216 longitude = mapSize - 1 -longitude;215 longitude = mapSize - longitude - 1; 217 216 } 218 217 return new int[] { latitude, longitude }; … … 243 242 } 244 243 245 return latPref + lat + lonPref + lon+ HGT_EXT;244 return String.format("%s%2d%s%03d" + HGT_EXT, latPref, lat, lonPref, lon); 246 245 } 247 246
Note:
See TracChangeset
for help on using the changeset viewer.