From 32ce79b8af94382e055ad73e1bf910e0469a784d Mon Sep 17 00:00:00 2001 From: Denny Sheirer Date: Sun, 22 Sep 2024 09:56:00 -0400 Subject: [PATCH] #1990 Ignores GPS positions with 0/0 latitude and longitude values. (#1991) (cherry picked from commit 55b20c75c0a0b90008bcfc903994b3c4a1b72e86) Co-authored-by: sheirerd --- .../dsheirer/map/PlottableEntityHistory.java | 19 +++--- .../dsheirer/map/PlottableEntityModel.java | 61 ++++++++++--------- .../decode/event/PlottableDecodeEvent.java | 10 +++ 3 files changed, 53 insertions(+), 37 deletions(-) diff --git a/src/main/java/io/github/dsheirer/map/PlottableEntityHistory.java b/src/main/java/io/github/dsheirer/map/PlottableEntityHistory.java index 5f43074c0..c25e4f68f 100644 --- a/src/main/java/io/github/dsheirer/map/PlottableEntityHistory.java +++ b/src/main/java/io/github/dsheirer/map/PlottableEntityHistory.java @@ -87,17 +87,20 @@ public IdentifierCollection getIdentifierCollection() */ public void add(PlottableDecodeEvent event) { - TimestampedGeoPosition mostRecentPosition = getLatestPosition(); - TimestampedGeoPosition latest = new TimestampedGeoPosition(event.getLocation(), event.getTimeStart()); - - if(isUnique(latest, mostRecentPosition)) + if(event.isValidLocation()) { - mCurrentEvent = event; - mLocationHistory.add(0, latest); + TimestampedGeoPosition mostRecentPosition = getLatestPosition(); + TimestampedGeoPosition latest = new TimestampedGeoPosition(event.getLocation(), event.getTimeStart()); - while(mLocationHistory.size() > MAX_LOCATION_HISTORY) + if(isUnique(latest, mostRecentPosition)) { - mLocationHistory.remove(mLocationHistory.size() - 1); + mCurrentEvent = event; + mLocationHistory.add(0, latest); + + while(mLocationHistory.size() > MAX_LOCATION_HISTORY) + { + mLocationHistory.remove(mLocationHistory.size() - 1); + } } } } diff --git a/src/main/java/io/github/dsheirer/map/PlottableEntityModel.java b/src/main/java/io/github/dsheirer/map/PlottableEntityModel.java index 50722888e..1d9e44035 100644 --- a/src/main/java/io/github/dsheirer/map/PlottableEntityModel.java +++ b/src/main/java/io/github/dsheirer/map/PlottableEntityModel.java @@ -101,42 +101,45 @@ public void delete(List tracksToDelete) @Override public void receive(PlottableDecodeEvent plottableDecodeEvent) { - //Add or update the event on the swing event thread - EventQueue.invokeLater(() -> { - Identifier from = plottableDecodeEvent.getIdentifierCollection().getFromIdentifier(); + if(plottableDecodeEvent.isValidLocation()) + { + //Add or update the event on the swing event thread + EventQueue.invokeLater(() -> { + Identifier from = plottableDecodeEvent.getIdentifierCollection().getFromIdentifier(); - if(from != null && from.getForm() != Form.LOCATION) - { - AliasListConfigurationIdentifier aliasList = plottableDecodeEvent.getIdentifierCollection().getAliasListConfiguration(); - String key = (aliasList != null ? aliasList.toString() : KEY_NO_ALIAS_LIST) + from; + if(from != null && from.getForm() != Form.LOCATION) + { + AliasListConfigurationIdentifier aliasList = plottableDecodeEvent.getIdentifierCollection().getAliasListConfiguration(); + String key = (aliasList != null ? aliasList.toString() : KEY_NO_ALIAS_LIST) + from; - PlottableEntityHistory entityHistory = mEntityHistoryMap.get(key); + PlottableEntityHistory entityHistory = mEntityHistoryMap.get(key); - if(entityHistory == null) - { - entityHistory = new PlottableEntityHistory(from, plottableDecodeEvent); - mEntityHistories.add(entityHistory); - mEntityHistoryMap.put(key, entityHistory); - int index = mEntityHistories.indexOf(entityHistory); - fireTableRowsInserted(index, index); + if(entityHistory == null) + { + entityHistory = new PlottableEntityHistory(from, plottableDecodeEvent); + mEntityHistories.add(entityHistory); + mEntityHistoryMap.put(key, entityHistory); + int index = mEntityHistories.indexOf(entityHistory); + fireTableRowsInserted(index, index); + } + else + { + entityHistory.add(plottableDecodeEvent); + int index = mEntityHistories.indexOf(entityHistory); + fireTableRowsUpdated(index, index); + } + + for(IPlottableUpdateListener listener : mPlottableUpdateListeners) + { + listener.addPlottableEntity(entityHistory); + } } else { - entityHistory.add(plottableDecodeEvent); - int index = mEntityHistories.indexOf(entityHistory); - fireTableRowsUpdated(index, index); - } - - for(IPlottableUpdateListener listener : mPlottableUpdateListeners) - { - listener.addPlottableEntity(entityHistory); + LOGGER.warn("Received plottable decode event that does not contain a FROM identifier - cannot plot"); } - } - else - { - LOGGER.warn("Received plottable decode event that does not contain a FROM identifier - cannot plot"); - } - }); + }); + } } @Override diff --git a/src/main/java/io/github/dsheirer/module/decode/event/PlottableDecodeEvent.java b/src/main/java/io/github/dsheirer/module/decode/event/PlottableDecodeEvent.java index 719cf3b7c..aae77a7f1 100644 --- a/src/main/java/io/github/dsheirer/module/decode/event/PlottableDecodeEvent.java +++ b/src/main/java/io/github/dsheirer/module/decode/event/PlottableDecodeEvent.java @@ -62,6 +62,16 @@ public GeoPosition getLocation() return mGeoPosition; } + /** + * Indicates if the location is non-null and either latitude or longitude is not at the zero axis. If the location + * coordinates are zero or both are very small values close to zero, then the location is flagged as invalid. + */ + public boolean isValidLocation() + { + return mGeoPosition != null && + ((Math.abs(mGeoPosition.getLatitude()) > 0.01) || (Math.abs(mGeoPosition.getLongitude()) > 0.01)); + } + /** * Sets the heading for the mobile plottable event * @param heading