Skip to content

Commit

Permalink
Unit test for georeferencing output
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 19, 2019
1 parent 71ccfed commit 79f796e
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions tests/src/core/testqgsgeopdfexport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class TestQgsGeoPdfExport : public QObject
void testCollectingFeatures();
void testComposition();
void testMetadata();
void testGeoref();

private:

Expand Down Expand Up @@ -311,5 +312,59 @@ void TestQgsGeoPdfExport::testMetadata()

}

void TestQgsGeoPdfExport::testGeoref()
{
if ( !QgsAbstractGeoPdfExporter::geoPDFCreationAvailable() )
{
QSKIP( "This test requires GeoPDF creation abilities", SkipSingle );
}

TestGeoPdfExporter geoPdfExporter;
// test creation of the composition xml with georeferencing

QList< QgsAbstractGeoPdfExporter::ComponentLayerDetail > renderedLayers;
QgsAbstractGeoPdfExporter::ExportDetails details;
QString composition = geoPdfExporter.createCompositionXml( renderedLayers, details );
QgsDebugMsg( composition );
QDomDocument doc;
doc.setContent( composition );
QCOMPARE( doc.elementsByTagName( QStringLiteral( "Georeferencing" ) ).count(), 0 );

// with points
QgsAbstractGeoPdfExporter::GeoReferencedSection section;
section.crs = QgsCoordinateReferenceSystem( QStringLiteral( "EPSG:4283" ) );
section.pageBoundsMm = QgsRectangle( 0, 0, 253.2, 222.25 );
section.controlPoints.append( QgsAbstractGeoPdfExporter::ControlPoint( QgsPointXY( 0, 0 ), QgsPointXY( -122.4, 53.6 ) ) );
section.controlPoints.append( QgsAbstractGeoPdfExporter::ControlPoint( QgsPointXY( 253.2, 0 ), QgsPointXY( -78, 53.6 ) ) );
section.controlPoints.append( QgsAbstractGeoPdfExporter::ControlPoint( QgsPointXY( 253.2, 222.25 ), QgsPointXY( -78, 14.6 ) ) );
section.controlPoints.append( QgsAbstractGeoPdfExporter::ControlPoint( QgsPointXY( 0, 222.25 ), QgsPointXY( -122.4, 14.6 ) ) );
details.georeferencedSections << section;

composition = geoPdfExporter.createCompositionXml( renderedLayers, details );
QgsDebugMsg( composition );
doc.setContent( composition );
QCOMPARE( doc.elementsByTagName( QStringLiteral( "SRS" ) ).at( 0 ).toElement().text(), QStringLiteral( "EPSG:4283" ) );
QCOMPARE( doc.elementsByTagName( QStringLiteral( "BoundingBox" ) ).at( 0 ).toElement().attribute( QStringLiteral( "x1" ) ), QStringLiteral( "0" ) );
QCOMPARE( doc.elementsByTagName( QStringLiteral( "BoundingBox" ) ).at( 0 ).toElement().attribute( QStringLiteral( "x2" ) ), QStringLiteral( "717.732" ) );
QCOMPARE( doc.elementsByTagName( QStringLiteral( "BoundingBox" ) ).at( 0 ).toElement().attribute( QStringLiteral( "y1" ) ), QStringLiteral( "0" ) );
QCOMPARE( doc.elementsByTagName( QStringLiteral( "BoundingBox" ) ).at( 0 ).toElement().attribute( QStringLiteral( "y2" ) ), QStringLiteral( "630" ) );

QDomNodeList cps = doc.elementsByTagName( QStringLiteral( "ControlPoint" ) );
QCOMPARE( cps.count(), 4 );
QDomElement cp1;
for ( int i = 0; i < 4; ++i )
{
if ( cps.at( i ).toElement().attribute( QStringLiteral( "GeoX" ) ) == QStringLiteral( "-122.4" )
&& cps.at( i ).toElement().attribute( QStringLiteral( "GeoY" ) ) == QStringLiteral( "53.6" ) )
{
cp1 = cps.at( i ).toElement();
break;
}
}
QVERIFY( !cp1.isNull() );
QCOMPARE( cp1.attribute( QStringLiteral( "x" ) ), QStringLiteral( "0" ) );
QCOMPARE( cp1.attribute( QStringLiteral( "y" ) ), QStringLiteral( "-2.83465" ) );
}

QGSTEST_MAIN( TestQgsGeoPdfExport )
#include "testqgsgeopdfexport.moc"

0 comments on commit 79f796e

Please sign in to comment.