tw: drop invalid GPS data
Signed-off-by: Varun Patil <varunpatil@ucla.edu>pull/579/head
parent
9ab896989f
commit
5438223b29
|
@ -86,6 +86,7 @@ class TimelineWrite
|
||||||
|
|
||||||
// Process location data
|
// Process location data
|
||||||
// This also modifies the exif array in-place to set the LocationTZID
|
// This also modifies the exif array in-place to set the LocationTZID
|
||||||
|
// and drop the GPS data if it is not valid
|
||||||
[$lat, $lon, $mapCluster] = $this->processExifLocation($fileId, $exif, $prevRow);
|
[$lat, $lon, $mapCluster] = $this->processExifLocation($fileId, $exif, $prevRow);
|
||||||
|
|
||||||
// Get date parameters (after setting timezone offset)
|
// Get date parameters (after setting timezone offset)
|
||||||
|
|
|
@ -8,6 +8,9 @@ use OCP\DB\QueryBuilder\IQueryBuilder;
|
||||||
use OCP\IDBConnection;
|
use OCP\IDBConnection;
|
||||||
use Psr\Log\LoggerInterface;
|
use Psr\Log\LoggerInterface;
|
||||||
|
|
||||||
|
const LAT_KEY = 'GPSLatitude';
|
||||||
|
const LON_KEY = 'GPSLongitude';
|
||||||
|
|
||||||
trait TimelineWritePlaces
|
trait TimelineWritePlaces
|
||||||
{
|
{
|
||||||
protected IDBConnection $connection;
|
protected IDBConnection $connection;
|
||||||
|
@ -27,8 +30,7 @@ trait TimelineWritePlaces
|
||||||
protected function processExifLocation(int $fileId, array &$exif, $prevRow): array
|
protected function processExifLocation(int $fileId, array &$exif, $prevRow): array
|
||||||
{
|
{
|
||||||
// Store location data
|
// Store location data
|
||||||
$lat = \array_key_exists('GPSLatitude', $exif) ? (float) $exif['GPSLatitude'] : null;
|
[$lat, $lon] = self::readCoord($exif);
|
||||||
$lon = \array_key_exists('GPSLongitude', $exif) ? (float) $exif['GPSLongitude'] : null;
|
|
||||||
$oldLat = $prevRow ? (float) $prevRow['lat'] : null;
|
$oldLat = $prevRow ? (float) $prevRow['lat'] : null;
|
||||||
$oldLon = $prevRow ? (float) $prevRow['lon'] : null;
|
$oldLon = $prevRow ? (float) $prevRow['lon'] : null;
|
||||||
$mapCluster = $prevRow ? (int) $prevRow['mapcluster'] : -1;
|
$mapCluster = $prevRow ? (int) $prevRow['mapcluster'] : -1;
|
||||||
|
@ -165,4 +167,30 @@ trait TimelineWritePlaces
|
||||||
$exif['LocationTZID'] = $tzName;
|
$exif['LocationTZID'] = $tzName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read coordinates from array and round to 6 decimal places.
|
||||||
|
*
|
||||||
|
* Modifies the array to remove invalid coordinates.
|
||||||
|
*/
|
||||||
|
private static function readCoord(array &$exif)
|
||||||
|
{
|
||||||
|
$lat = array_key_exists(LAT_KEY, $exif) ? round((float) $exif[LAT_KEY], 6) : null;
|
||||||
|
$lon = array_key_exists(LON_KEY, $exif) ? round((float) $exif[LON_KEY], 6) : null;
|
||||||
|
|
||||||
|
// Make sure we have valid coordinates
|
||||||
|
if (null === $lat || null === $lon || abs($lat) > 90 || abs($lon) > 180 || ($lat < 0.00001 && $lon < 0.00001)) {
|
||||||
|
$lat = $lon = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove invalid coordinates
|
||||||
|
if (null === $lat && array_key_exists(LAT_KEY, $exif)) {
|
||||||
|
unset($exif[LAT_KEY]);
|
||||||
|
}
|
||||||
|
if (null === $lon && array_key_exists(LON_KEY, $exif)) {
|
||||||
|
unset($exif[LON_KEY]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return [$lat, $lon];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -131,12 +131,6 @@ class Exif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ignore zero lat lng
|
|
||||||
if (\array_key_exists('GPSLatitude', $exif) && abs((float) $exif['GPSLatitude']) < 0.0001
|
|
||||||
&& \array_key_exists('GPSLongitude', $exif) && abs((float) $exif['GPSLongitude']) < 0.0001) {
|
|
||||||
unset($exif['GPSLatitude'], $exif['GPSLongitude']);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $exif;
|
return $exif;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue