{
// Compile list of tiles to get
ArrayList<SrtmTile> tileList = new ArrayList<SrtmTile>();
- boolean hasZeroAltitudePoints = false;
- boolean hasNonZeroAltitudePoints = false;
- // First, loop to see what kind of points we have
- for (int i = 0; i < _track.getNumPoints(); i++)
- {
- if (_track.getPoint(i).hasAltitude())
- {
- if (_track.getPoint(i).getAltitude().getValue() == 0) {
- hasZeroAltitudePoints = true;
- }
- else {
- hasNonZeroAltitudePoints = true;
- }
- }
- }
- // Should we overwrite the zero altitude values?
- boolean overwriteZeros = hasZeroAltitudePoints && !hasNonZeroAltitudePoints;
- // If non-zero values present as well, ask user whether to overwrite the zeros or not
- if (hasNonZeroAltitudePoints && hasZeroAltitudePoints && JOptionPane.showConfirmDialog(_parentFrame,
- I18nManager.getText("dialog.lookupsrtm.overwritezeros"), I18nManager.getText(getNameKey()),
- JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
- {
- overwriteZeros = true;
- }
// Now loop again to extract the required tiles
for (int i = 0; i < _track.getNumPoints(); i++)
{
- // Consider points which don't have altitudes or have zero values
- if (needsAltitude(_track.getPoint(i), overwriteZeros))
+ SrtmTile tile = new SrtmTile(_track.getPoint(i));
+ boolean alreadyGot = false;
+ for (int t = 0; t < tileList.size(); t++)
{
- SrtmTile tile = new SrtmTile(_track.getPoint(i));
- boolean alreadyGot = false;
- for (int t = 0; t < tileList.size(); t++)
- {
- if (tileList.get(t).equals(tile)) {
- alreadyGot = true;
- }
+ if (tileList.get(t).equals(tile)) {
+ alreadyGot = true;
}
- if (!alreadyGot) {tileList.add(tile);}
}
+ if (!alreadyGot) {tileList.add(tile);}
}
- lookupValues(tileList, overwriteZeros);
+ lookupValues(tileList);
// Finished
_running = false;
}
- /**
- * true if we need to set the altitude of this point
- */
- private boolean needsAltitude(DataPoint point, boolean overwriteZeros)
- {
- if (!point.hasAltitude())
- {
- return true;
- }
- if (overwriteZeros && point.getAltitude().getValue() == 0)
- {
- return true;
- }
- return false;
- }
-
/**
* Lookup the values from SRTM data
* @param inTileList list of tiles to get
* @param inOverwriteZeros true to overwrite zero altitude values
*/
- private void lookupValues(ArrayList<SrtmTile> inTileList, boolean inOverwriteZeros)
+ private void lookupValues(ArrayList<SrtmTile> inTileList)
{
UndoLookupSrtm undo = new UndoLookupSrtm(_app.getTrackInfo());
int numAltitudesFound = 0;
}
try {
- numAltitudesFound += applySrtmTileToWholeTrack(tile, heights, rowSize, inOverwriteZeros);
+ numAltitudesFound += applySrtmTileToWholeTrack(tile, heights, rowSize);
}
catch (SrtmSourceException e)
{
* in the track with missing altitude
* @param inTile tile being applied
* @param inHeights height data read in from file
- * @param inOverwriteZeros true to overwrite zero altitude values
* @return number of altitudes found
*/
- private int applySrtmTileToWholeTrack(SrtmTile inTile, int[] inHeights, int inRowSize, boolean inOverwriteZeros)
+ private int applySrtmTileToWholeTrack(SrtmTile inTile, int[] inHeights, int inRowSize)
throws SrtmSourceException
{
int numAltitudesFound = 0;
for (int p = 0; p < _track.getNumPoints(); p++)
{
DataPoint point = _track.getPoint(p);
- if (needsAltitude(point, inOverwriteZeros))
+ if (new SrtmTile(point).equals(inTile))
{
- if (new SrtmTile(point).equals(inTile))
+ double x = (point.getLongitude().getDouble() - inTile.getLongitude()) * (inRowSize - 1);
+ double y = inRowSize - (point.getLatitude().getDouble() - inTile.getLatitude()) * (inRowSize - 1);
+ int idx1 = ((int)y)*inRowSize + (int)x;
+ try
{
- double x = (point.getLongitude().getDouble() - inTile.getLongitude()) * (inRowSize - 1);
- double y = inRowSize - (point.getLatitude().getDouble() - inTile.getLatitude()) * (inRowSize - 1);
- int idx1 = ((int)y)*inRowSize + (int)x;
- try
+ int[] fouralts = {inHeights[idx1], inHeights[idx1+1], inHeights[idx1-inRowSize], inHeights[idx1-inRowSize+1]};
+ int numVoids = (fouralts[0]==VOID_VAL?1:0) + (fouralts[1]==VOID_VAL?1:0)
+ + (fouralts[2]==VOID_VAL?1:0) + (fouralts[3]==VOID_VAL?1:0);
+ // if (numVoids > 0) System.out.println(numVoids + " voids found");
+ double altitude = 0.0;
+ switch (numVoids)
{
- int[] fouralts = {inHeights[idx1], inHeights[idx1+1], inHeights[idx1-inRowSize], inHeights[idx1-inRowSize+1]};
- int numVoids = (fouralts[0]==VOID_VAL?1:0) + (fouralts[1]==VOID_VAL?1:0)
- + (fouralts[2]==VOID_VAL?1:0) + (fouralts[3]==VOID_VAL?1:0);
- // if (numVoids > 0) System.out.println(numVoids + " voids found");
- double altitude = 0.0;
- switch (numVoids)
- {
- case 0: altitude = bilinearInterpolate(fouralts, x, y); break;
- case 1: altitude = bilinearInterpolate(fixVoid(fouralts), x, y); break;
- case 2:
- case 3: altitude = averageNonVoid(fouralts); break;
- default: altitude = VOID_VAL;
- }
- // Special case for terrain tracks, don't interpolate voids yet
- if (!_normalTrack && numVoids > 0) {
- altitude = VOID_VAL;
- }
- if (altitude != VOID_VAL)
- {
- point.setFieldValue(Field.ALTITUDE, ""+altitude, false);
- // depending on settings, this value may have been added as feet, we need to force metres
- point.getAltitude().reset(new Altitude((int)altitude, UnitSetLibrary.UNITS_METRES));
- numAltitudesFound++;
- }
+ case 0: altitude = bilinearInterpolate(fouralts, x, y); break;
+ case 1: altitude = bilinearInterpolate(fixVoid(fouralts), x, y); break;
+ case 2:
+ case 3: altitude = averageNonVoid(fouralts); break;
+ default: altitude = VOID_VAL;
}
- catch (ArrayIndexOutOfBoundsException obe) {
- throw new SrtmSourceException("Point not in tile? lat=" + point.getLatitude().getDouble() + ", x=" + x + ", y=" + y + ", idx=" + idx1+"\n");
+ // Special case for terrain tracks, don't interpolate voids yet
+ if (!_normalTrack && numVoids > 0) {
+ altitude = VOID_VAL;
}
+ if (altitude != VOID_VAL)
+ {
+ point.setFieldValue(Field.ALTITUDE, ""+altitude, false);
+ // depending on settings, this value may have been added as feet, we need to force metres
+ point.getAltitude().reset(new Altitude((int)altitude, UnitSetLibrary.UNITS_METRES));
+ numAltitudesFound++;
+ }
+ }
+ catch (ArrayIndexOutOfBoundsException obe) {
+ System.err.println("Point not in tile? lat=" + point.getLatitude().getDouble() + ", x=" + x + ", y=" + y + ", idx=" + idx1+"\n");
}
}
}