public static GenericFunction FUNCTION_DELETE_BY_DATE = null;
public static SingleNumericParameterFunction FUNCTION_INTERPOLATE = null;
public static GenericFunction FUNCTION_LOOKUP_SRTM = null;
+ public static GenericFunction FUNCTION_OVERWRITE_SRTM = null;
public static GenericFunction FUNCTION_DOWNLOAD_SRTM = null;
public static GenericFunction FUNCTION_NEARBY_WIKIPEDIA = null;
public static GenericFunction FUNCTION_SEARCH_WIKIPEDIA = null;
FUNCTION_MARK_IN_RECTANGLE = new MarkPointsInRectangleFunction(inApp);
FUNCTION_DELETE_BY_DATE = new DeleteByDateFunction(inApp);
FUNCTION_INTERPOLATE = new InterpolateFunction(inApp);
- FUNCTION_LOOKUP_SRTM = new LookupSrtmFunction(inApp);
+ FUNCTION_LOOKUP_SRTM = new LookupSrtmFunction(inApp, false);
+ FUNCTION_OVERWRITE_SRTM = new LookupSrtmFunction(inApp, true);
FUNCTION_DOWNLOAD_SRTM = new DownloadSrtmFunction(inApp);
FUNCTION_NEARBY_WIKIPEDIA = new GetWikipediaFunction(inApp);
FUNCTION_SEARCH_WIKIPEDIA = new SearchWikipediaNames(inApp);
*/
public class LookupSrtmFunction extends GenericFunction implements Runnable
{
+ /** Whether to overwrite all altitudes, or only fill in missing data */
+ private boolean _overwriteAlt = false;
/** Progress dialog */
private ProgressDialog _progress = null;
/** Track to process */
* Constructor
* @param inApp App object
*/
- public LookupSrtmFunction(App inApp) {
+ public LookupSrtmFunction(App inApp, boolean overwriteAlt) {
super(inApp);
+ _overwriteAlt = overwriteAlt;
}
/** @return name key */
public String getNameKey() {
- return "function.lookupsrtm";
+ if (_overwriteAlt) {
+ return "function.overwritesrtm";
+ } else {
+ return "function.lookupsrtm";
+ }
}
/**
{
// 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;
- }
+
+ boolean overwriteZeros = overwriteZeros();
// 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 (!_track.getPoint(i).hasAltitude()
- || (overwriteZeros && _track.getPoint(i).getAltitude().getValue() == 0))
+ if (needsAltitude(_track.getPoint(i), overwriteZeros))
{
SrtmTile tile = new SrtmTile(_track.getPoint(i));
boolean alreadyGot = false;
}
}
+ /**
+ * true if we need to set the altitude of this point
+ */
+ private boolean needsAltitude(DataPoint point, boolean overwriteZeros)
+ {
+ if (_overwriteAlt)
+ {
+ return true;
+ }
+ if (!point.hasAltitude())
+ {
+ return true;
+ }
+ if (overwriteZeros && point.getAltitude().getValue() == 0)
+ {
+ return true;
+ }
+ return false;
+ }
+
+ private boolean overwriteZeros()
+ {
+ // nothing to do if we overwrite all altitudes anyway
+ if (_overwriteAlt) {
+ return true;
+ }
+
+ 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;
+ }
+ return overwriteZeros;
+ }
+
/**
* 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, boolean overwriteZeros)
{
- UndoLookupSrtm undo = new UndoLookupSrtm(_app.getTrackInfo());
+ UndoLookupSrtm undo = new UndoLookupSrtm(_app.getTrackInfo(), _overwriteAlt);
int numAltitudesFound = 0;
// Update progress bar
if (_progress != null)
for (int p = 0; p < _track.getNumPoints(); p++)
{
DataPoint point = _track.getPoint(p);
- if (!point.hasAltitude()
- || (inOverwriteZeros && point.getAltitude().getValue() == 0))
+ if (needsAltitude(point, overwriteZeros))
{
if (new SrtmTile(point).equals(tile))
{
private JMenuItem _getGpsiesItem = null;
private JMenuItem _uploadGpsiesItem = null;
private JMenuItem _lookupSrtmItem = null;
+ private JMenuItem _overwriteSrtmItem = null;
private JMenuItem _downloadSrtmItem = null;
private JMenuItem _nearbyWikipediaItem = null;
private JMenuItem _nearbyOsmPoiItem = null;
// SRTM
_lookupSrtmItem = makeMenuItem(FunctionLibrary.FUNCTION_LOOKUP_SRTM, false);
onlineMenu.add(_lookupSrtmItem);
+ _overwriteSrtmItem = makeMenuItem(FunctionLibrary.FUNCTION_OVERWRITE_SRTM, false);
+ onlineMenu.add(_overwriteSrtmItem);
_downloadSrtmItem = makeMenuItem(FunctionLibrary.FUNCTION_DOWNLOAD_SRTM, false);
onlineMenu.add(_downloadSrtmItem);
// Get gpsies tracks
_getGpsiesItem.setEnabled(hasData);
_uploadGpsiesItem.setEnabled(hasData && _track.hasTrackPoints());
_lookupSrtmItem.setEnabled(hasData);
+ _overwriteSrtmItem.setEnabled(hasData);
_nearbyWikipediaItem.setEnabled(hasData);
_nearbyOsmPoiItem.setEnabled(hasData);
_downloadOsmItem.setEnabled(hasData);