public static void main(String[] args) throws IOException { SRTMProvider provider = new SRTMProvider(); // 337 System.out.println(provider.getEle(49.949784, 11.57517)); // 466 System.out.println(provider.getEle(49.968668, 11.575127)); // 466 System.out.println(provider.getEle(49.968682, 11.574842)); // 3100 System.out.println(provider.getEle(-22.532854, -65.110474)); // 122 System.out.println(provider.getEle(38.065392, -87.099609)); // 1617 System.out.println(provider.getEle(40, -105.2277023)); System.out.println(provider.getEle(39.99999999, -105.2277023)); System.out.println(provider.getEle(39.9999999, -105.2277023)); System.out.println(provider.getEle(39.999999, -105.2277023)); // 1046 System.out.println(provider.getEle(47.468668, 14.575127)); // 1113 System.out.println(provider.getEle(47.467753, 14.573911)); // 1946 System.out.println(provider.getEle(46.468835, 12.578777)); // 845 System.out.println(provider.getEle(48.469123, 9.576393)); }
@Override String getFileName(double lat, double lon) { int intKey = calcIntKey(lat, lon); String str = areas.get(intKey); if (str == null) return null; int minLat = Math.abs(down(lat)); int minLon = Math.abs(down(lon)); str += "/"; if (lat >= 0) str += "N"; else str += "S"; if (minLat < 10) str += "0"; str += minLat; if (lon >= 0) str += "E"; else str += "W"; if (minLon < 10) str += "0"; if (minLon < 100) str += "0"; str += minLon; return str; }
public SRTMProvider(String cacheDir) { super( "https://srtm.kurviger.de/SRTM3/", cacheDir.isEmpty()? "/tmp/srtm": cacheDir, "GraphHopper SRTMReader", 1201 ); // move to explicit calls? init(); }
@Ignore public void testGetEleVerticalBorder() { instance = new SRTMProvider(); // Border between the tiles N42E011 and N43E011 assertEquals("Eurasia/N42E011", instance.getFileName(42.999999, 11.48)); assertEquals(419, instance.getEle(42.999999, 11.48), precision); assertEquals("Eurasia/N43E011", instance.getFileName(43.000001, 11.48)); assertEquals(419, instance.getEle(43.000001, 11.48), precision); }
lat = (int) (lat * precision) / precision; lon = (int) (lon * precision) / precision; int intKey = calcIntKey(lat, lon); HeightTile demProvider = cacheData.get(intKey); if (demProvider != null) cacheDir.mkdirs(); String fileDetails = getFileString(lat, lon); if (fileDetails == null) return 0; DataAccess heights = getDirectory().find("dem" + intKey); boolean loadExisting = false; try { updateHeightsFromZipFile(fileDetails, heights); width = DEFAULT_WIDTH; demProvider = new HeightTile(down(lat), down(lon), width, precision, 1); cacheData.put(intKey, demProvider); demProvider.setCalcMean(calcMean);
public static void main( String[] args ) throws IOException { SRTMProvider provider = new SRTMProvider(); // 1046 System.out.println(provider.getEle(47.468668, 14.575127)); // 1113 System.out.println(provider.getEle(47.467753, 14.573911)); // 1946 System.out.println(provider.getEle(46.468835, 12.578777)); // 845 System.out.println(provider.getEle(48.469123, 9.576393)); // 1113 vs new: provider.setCalcMean(true); System.out.println(provider.getEle(47.467753, 14.573911)); }
@Before public void setUp() { instance = new SRTMProvider(); }
/** * The URLs are a bit ugly and so we need to find out which area name a certain lat,lon * coordinate has. */ private SRTMProvider init() { try { String strs[] = {"Africa", "Australia", "Eurasia", "Islands", "North_America", "South_America"}; for (String str : strs) { InputStream is = getClass().getResourceAsStream(str + "_names.txt"); for (String line : Helper.readFile(new InputStreamReader(is, Helper.UTF_CS))) { int lat = Integer.parseInt(line.substring(1, 3)); if (line.substring(0, 1).charAt(0) == 'S') lat = -lat; int lon = Integer.parseInt(line.substring(4, 7)); if (line.substring(3, 4).charAt(0) == 'W') lon = -lon; int intKey = calcIntKey(lat, lon); String key = areas.put(intKey, str); if (key != null) throw new IllegalStateException("do not overwrite existing! key " + intKey + " " + key + " vs. " + str); } } return this; } catch (Exception ex) { throw new IllegalStateException("Cannot load area names from classpath", ex); } }
@Override String getDownloadURL(double lat, double lon) { return getFileName(lat, lon) + ".hgt.zip"; } }
private void updateHeightsFromZipFile(String fileDetails, DataAccess heights) throws RuntimeException { try { byte[] bytes = getByteArrayFromZipFile(fileDetails); heights.create(bytes.length); for (int bytePos = 0; bytePos < bytes.length; bytePos += 2) { short val = BIT_UTIL.toShort(bytes, bytePos); if (val < -1000 || val > 12000) val = Short.MIN_VALUE; heights.setShort(bytePos, val); } heights.setHeader(WIDTH_BYTE_INDEX, bytes.length / 2); heights.flush(); } catch (Exception ex) { throw new RuntimeException(ex); } }
@Ignore public void testGetEleHorizontalBorder() { instance = new SRTMProvider(); // Border between the tiles N42E011 and N42E012 assertEquals("Eurasia/N42E011", instance.getFileName(42.1, 11.999999)); assertEquals(324, instance.getEle(42.1, 11.999999), precision); assertEquals("Eurasia/N42E012", instance.getFileName(42.1, 12.000001)); assertEquals(324, instance.getEle(42.1, 12.000001), precision); }
int intKey = calcIntKey(lat, lon); HeightTile demProvider = cacheData.get(intKey); if (demProvider != null) cacheDir.mkdirs(); String fileDetails = getFileString(lat, lon); if (fileDetails == null) return 0; DataAccess heights = getDirectory().find("dem" + intKey); boolean loadExisting = false; try updateHeightsFromZipFile(fileDetails, heights); width = DEFAULT_WIDTH; demProvider = new HeightTile(down(lat), down(lon), width, precision, 1); demProvider.setCalcMean(calcMean); cacheData.put(intKey, demProvider);
public static void main(String[] args) throws IOException { SRTMProvider provider = new SRTMProvider(); // 1046 System.out.println(provider.getEle(47.468668, 14.575127)); // 1113 System.out.println(provider.getEle(47.467753, 14.573911)); // 1946 System.out.println(provider.getEle(46.468835, 12.578777)); // 845 System.out.println(provider.getEle(48.469123, 9.576393)); // 1113 vs new: provider.setCalcMean(true); System.out.println(provider.getEle(47.467753, 14.573911)); }
ElevationProvider tmpProvider = ElevationProvider.NOOP; if (eleProviderStr.equalsIgnoreCase("srtm")) { tmpProvider = new SRTMProvider(cacheDirStr); } else if (eleProviderStr.equalsIgnoreCase("cgiar")) { tmpProvider = new CGIARProvider(cacheDirStr);
/** * The URLs are a bit ugly and so we need to find out which area name a certain lat,lon * coordinate has. */ private SRTMProvider init() { try { String strs[] = {"Africa", "Australia", "Eurasia", "Islands", "North_America", "South_America"}; for (String str : strs) { InputStream is = getClass().getResourceAsStream(str + "_names.txt"); for (String line : Helper.readFile(new InputStreamReader(is, Helper.UTF_CS))) { int lat = Integer.parseInt(line.substring(1, 3)); if (line.substring(0, 1).charAt(0) == 'S') lat = -lat; int lon = Integer.parseInt(line.substring(4, 7)); if (line.substring(3, 4).charAt(0) == 'W') lon = -lon; int intKey = calcIntKey(lat, lon); String key = areas.put(intKey, str); if (key != null) throw new IllegalStateException("do not overwrite existing! key " + intKey + " " + key + " vs. " + str); } } return this; } catch (Exception ex) { throw new IllegalStateException("Cannot load area names from classpath", ex); } }
@Test public void testGetFileString() { assertEquals("Eurasia/N49E011", instance.getFileName(49, 11)); assertEquals("Eurasia/N52W002", instance.getFileName(52.268157, -1.230469)); assertEquals("Africa/S06E034", instance.getFileName(-5.965754, 34.804687)); assertEquals("Australia/S29E131", instance.getFileName(-28.304381, 131.484375)); assertEquals("South_America/S09W045", instance.getFileName(-9, -45)); assertEquals("South_America/S10W046", instance.getFileName(-9.1, -45.1)); assertEquals("South_America/S10W045", instance.getFileName(-9.6, -45)); assertEquals("South_America/S28W071", instance.getFileName(-28, -71)); assertEquals("South_America/S29W072", instance.getFileName(-28.88316, -71.070557)); }
private void updateHeightsFromZipFile( String fileDetails, DataAccess heights ) throws RuntimeException { try { byte[] bytes = getByteArrayFromZipFile(fileDetails); heights.create(bytes.length); for (int bytePos = 0; bytePos < bytes.length; bytePos += 2) { short val = BIT_UTIL.toShort(bytes, bytePos); if (val < -1000 || val > 12000) val = Short.MIN_VALUE; heights.setShort(bytePos, val); } heights.setHeader(WIDTH_BYTE_INDEX, bytes.length / 2); heights.flush(); } catch (Exception ex) { throw new RuntimeException(ex); } }
@Test public void testGetHeightMMap() throws IOException { instance = new SRTMProvider("./files/"); assertEquals(161, instance.getEle(55.8943144, -3), 1e-1); }