]> gitweb.fperrin.net Git - GpsPrune.git/blobdiff - src/tim/prune/function/srtm/TileFinder.java
Use SRTM 1deg data from NASA servers
[GpsPrune.git] / src / tim / prune / function / srtm / TileFinder.java
index 60a9479d1289faae0523e0fd7d025b56e816d37e..8683268ef3b9babc846c0d7c5df346a3f0eea6a8 100644 (file)
@@ -13,11 +13,7 @@ import java.util.ArrayList;
 public abstract class TileFinder
 {
        /** URL prefix for all tiles */
-       private static final String URL_PREFIX = "https://dds.cr.usgs.gov/srtm/version2_1/SRTM3/";
-       /** Directory names for each continent */
-       private static final String[] CONTINENTS = {"", "Eurasia", "North_America", "Australia",
-               "Islands", "South_America", "Africa"};
-
+       private static final String URL_PREFIX = "https://fred_earthdata:Xaev0oca@e4ftl01.cr.usgs.gov/MEASURES/SRTMGL1.003/2000.02.11/";
 
        /**
         * Get the Urls for the given list of tiles
@@ -29,54 +25,14 @@ public abstract class TileFinder
                if (inTiles == null || inTiles.size() < 1) {return null;}
                URL[] urls = new URL[inTiles.size()];
                // Read dat file into array
-               byte[] lookup = readDatFile();
                for (int t=0; t<inTiles.size(); t++)
                {
                        SrtmTile tile = inTiles.get(t);
                        // Get byte from lookup array
-                       int idx = (tile.getLatitude() + 59)*360 + (tile.getLongitude() + 180);
-                       try
-                       {
-                               int dir = lookup[idx];
-                               if (dir > 0) {
-                                       try {
-                                               urls[t] = new URL(URL_PREFIX + CONTINENTS[dir] + "/" + tile.getTileName());
-                                       } catch (MalformedURLException e) {} // ignore error, url stays null
-                               }
-                       } catch (ArrayIndexOutOfBoundsException e) {} // ignore error, url stays null
-               }
-               return urls;
-       }
-
-       /**
-        * Read the dat file and get the contents
-        * @return byte array containing file contents
-        */
-       private static byte[] readDatFile()
-       {
-               InputStream in = null;
-               try
-               {
-                       // Need absolute path to dat file
-                       in = TileFinder.class.getResourceAsStream("/tim/prune/function/srtm/srtmtiles.dat");
-                       if (in != null)
-                       {
-                               byte[] buffer = new byte[in.available()];
-                               in.read(buffer);
-                               in.close();
-                               return buffer;
-                       }
-               }
-               catch (java.io.IOException e) {
-                       System.err.println("Exception trying to read srtmtiles.dat : " + e.getMessage());
-               }
-               finally
-               {
                        try {
-                               in.close();
-                       }
-                       catch (Exception e) {} // ignore
+                               urls[t] = new URL(URL_PREFIX + tile.getTileName());
+                       } catch (MalformedURLException e) {} // ignore error, url stays null
                }
-               return null;
+               return urls;
        }
 }