Skip to content
Permalink
Browse files

[FEATURE] Extend import geotagged photos to include exif_orientation

Fixes #34868
  • Loading branch information
pellegoeg committed Nov 15, 2020
1 parent cbe7912 commit cf92f32cfe4d5ff60d22cf248c81441cafce079c
@@ -149,6 +149,42 @@ QVariant QgsImportPhotosAlgorithm::extractDirectionFromMetadata( const QVariantM
return direction;
}

QVariant QgsImportPhotosAlgorithm::extractOrientationFromMetadata( const QVariantMap &metadata )
{
QVariant orientation;
if ( metadata.contains( QStringLiteral( "EXIF_Orientation" ) ) )
{
switch ( metadata.value( QStringLiteral( "EXIF_Orientation" ) ).toInt() )
{
case 1:
orientation = 0;
break;
case 2:
orientation = 0;
break;
case 3:
orientation = 180;
break;
case 4:
orientation = 180;
break;
case 5:
orientation = 90;
break;
case 6:
orientation = 90;
break;
case 7:
orientation = 270;
break;
case 8:
orientation = 270;
break;
}
}
return orientation;
}

QVariant QgsImportPhotosAlgorithm::extractTimestampFromMetadata( const QVariantMap &metadata )
{
QVariant ts;
@@ -269,6 +305,7 @@ QVariantMap QgsImportPhotosAlgorithm::processAlgorithm( const QVariantMap &param
outFields.append( QgsField( QStringLiteral( "directory" ), QVariant::String ) );
outFields.append( QgsField( QStringLiteral( "altitude" ), QVariant::Double ) );
outFields.append( QgsField( QStringLiteral( "direction" ), QVariant::Double ) );
outFields.append( QgsField( QStringLiteral( "rotation" ), QVariant::Int ) );
outFields.append( QgsField( QStringLiteral( "longitude" ), QVariant::String ) );
outFields.append( QgsField( QStringLiteral( "latitude" ), QVariant::String ) );
outFields.append( QgsField( QStringLiteral( "timestamp" ), QVariant::DateTime ) );
@@ -366,6 +403,7 @@ QVariantMap QgsImportPhotosAlgorithm::processAlgorithm( const QVariantMap &param
attributes
<< altitude
<< extractDirectionFromMetadata( metadata )
<< extractOrientationFromMetadata( metadata )
<< tag.x()
<< tag.y()
<< extractTimestampFromMetadata( metadata );
@@ -56,6 +56,7 @@ class ANALYSIS_EXPORT QgsImportPhotosAlgorithm : public QgsProcessingAlgorithm
static bool extractGeoTagFromMetadata( const QVariantMap &metadata, QgsPointXY &tag );
static QVariant extractAltitudeFromMetadata( const QVariantMap &metadata );
static QVariant extractDirectionFromMetadata( const QVariantMap &metadata );
static QVariant extractOrientationFromMetadata( const QVariantMap &metadata );
static QVariant extractTimestampFromMetadata( const QVariantMap &metadata );

friend class TestQgsProcessingAlgs;
@@ -592,6 +592,11 @@ void TestQgsProcessingAlgs::parseGeoTags()
md.insert( QStringLiteral( "EXIF_GPSImgDirection" ), 15 );
QCOMPARE( QgsImportPhotosAlgorithm::extractDirectionFromMetadata( md ).toDouble(), 15.0 );

// extractOrientationFromMetadata
QVERIFY( !QgsImportPhotosAlgorithm::extractOrientationFromMetadata( md ).isValid() );
md.insert( QStringLiteral( "EXIF_Orientation" ), 3 );
QCOMPARE( QgsImportPhotosAlgorithm::extractOrientationFromMetadata( md ).toInt(), 180 );

// extractTimestampFromMetadata
QVERIFY( !QgsImportPhotosAlgorithm::extractTimestampFromMetadata( md ).isValid() );
md.insert( QStringLiteral( "EXIF_DateTimeOriginal" ), QStringLiteral( "xx" ) );

0 comments on commit cf92f32

Please sign in to comment.
You can’t perform that action at this time.