Skip to content

Commit

Permalink
Make test resilent against future potential order changes
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 26, 2019
1 parent 63b5d58 commit 270c605
Showing 1 changed file with 81 additions and 64 deletions.
145 changes: 81 additions & 64 deletions tests/src/python/test_qgsdatumtransforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,74 +66,91 @@ def testOperations(self):
# uses a grid file
ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem('EPSG:4283'),
QgsCoordinateReferenceSystem('EPSG:7844'))
self.assertEqual(len(ops), 5)
self.assertTrue(ops[0].name)
self.assertEqual(ops[0].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
self.assertTrue(ops[0].isAvailable)
self.assertEqual(ops[0].accuracy, 0.01)
self.assertEqual(len(ops[0].grids), 0)
self.assertTrue(ops[1].name)
self.assertEqual(ops[1].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
self.assertEqual(ops[1].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
self.assertEqual(len(ops[1].grids), 1)
self.assertEqual(ops[1].grids[0].shortName, 'GDA94_GDA2020_conformal_and_distortion.gsb')
self.assertEqual(ops[1].grids[0].fullName, '')
self.assertEqual(ops[1].grids[0].packageName, 'proj-datumgrid-oceania')
self.assertEqual(ops[1].grids[0].url, 'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip')
self.assertTrue(ops[1].grids[0].directDownload)
self.assertTrue(ops[1].grids[0].openLicense)
self.assertTrue(ops[2].name)
self.assertEqual(ops[2].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
self.assertEqual(ops[2].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
self.assertEqual(len(ops[2].grids), 1)
self.assertEqual(ops[2].grids[0].shortName, 'GDA94_GDA2020_conformal.gsb')
self.assertEqual(ops[2].grids[0].fullName, '')
self.assertEqual(ops[2].grids[0].packageName, 'proj-datumgrid-oceania')
self.assertEqual(ops[2].grids[0].url, 'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip')
self.assertTrue(ops[2].grids[0].directDownload)
self.assertTrue(ops[2].grids[0].openLicense)
self.assertTrue(ops[3].name)
self.assertEqual(ops[3].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_cocos_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
self.assertEqual(ops[3].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
self.assertEqual(len(ops[3].grids), 1)
self.assertEqual(ops[3].grids[0].shortName, 'GDA94_GDA2020_conformal_cocos_island.gsb')
self.assertEqual(ops[3].grids[0].fullName, '')
self.assertTrue(ops[4].name)
self.assertEqual(ops[4].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_christmas_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
self.assertEqual(ops[4].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
self.assertEqual(len(ops[4].grids), 1)
self.assertEqual(ops[4].grids[0].shortName, 'GDA94_GDA2020_conformal_christmas_island.gsb')
self.assertEqual(ops[4].grids[0].fullName, '')
self.assertGreaterEqual(len(ops), 5)

op1_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'][0]
self.assertTrue(ops[op1_index].name)
self.assertEqual(ops[op1_index].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
self.assertTrue(ops[op1_index].isAvailable)
self.assertEqual(ops[op1_index].accuracy, 0.01)
self.assertEqual(len(ops[op1_index].grids), 0)

op2_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'][0]
self.assertTrue(ops[op2_index].name)
self.assertEqual(ops[op2_index].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
self.assertEqual(ops[op2_index].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
self.assertEqual(len(ops[op2_index].grids), 1)
self.assertEqual(ops[op2_index].grids[0].shortName, 'GDA94_GDA2020_conformal_and_distortion.gsb')
self.assertEqual(ops[op2_index].grids[0].fullName, '')
self.assertEqual(ops[op2_index].grids[0].packageName, 'proj-datumgrid-oceania')
self.assertEqual(ops[op2_index].grids[0].url, 'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip')
self.assertTrue(ops[op2_index].grids[0].directDownload)
self.assertTrue(ops[op2_index].grids[0].openLicense)

op3_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'][0]
self.assertTrue(ops[op3_index].name)
self.assertEqual(ops[op3_index].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
self.assertEqual(ops[op3_index].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
self.assertEqual(len(ops[op3_index].grids), 1)
self.assertEqual(ops[op3_index].grids[0].shortName, 'GDA94_GDA2020_conformal.gsb')
self.assertEqual(ops[op3_index].grids[0].fullName, '')
self.assertEqual(ops[op3_index].grids[0].packageName, 'proj-datumgrid-oceania')
self.assertEqual(ops[op3_index].grids[0].url, 'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip')
self.assertTrue(ops[op3_index].grids[0].directDownload)
self.assertTrue(ops[op3_index].grids[0].openLicense)

op4_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_cocos_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'][0]
self.assertTrue(ops[op4_index].name)
self.assertEqual(ops[op4_index].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_cocos_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
self.assertEqual(ops[op4_index].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
self.assertEqual(len(ops[op4_index].grids), 1)
self.assertEqual(ops[op4_index].grids[0].shortName, 'GDA94_GDA2020_conformal_cocos_island.gsb')
self.assertEqual(ops[op4_index].grids[0].fullName, '')

op5_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_christmas_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'][0]
self.assertTrue(ops[op5_index].name)
self.assertEqual(ops[op5_index].proj, '+proj=pipeline +step +proj=axisswap +order=2,1 +step +proj=unitconvert +xy_in=deg +xy_out=rad +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_christmas_island.gsb +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
self.assertEqual(ops[op5_index].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
self.assertEqual(len(ops[op5_index].grids), 1)
self.assertEqual(ops[op5_index].grids[0].shortName, 'GDA94_GDA2020_conformal_christmas_island.gsb')
self.assertEqual(ops[op5_index].grids[0].fullName, '')

# uses a pivot datum (technically a proj test, but this will help me sleep at night ;)
ops = QgsDatumTransform.operations(QgsCoordinateReferenceSystem('EPSG:3111'),
QgsCoordinateReferenceSystem('EPSG:7899'))
self.assertEqual(len(ops), 3)
self.assertTrue(ops[0].name)
self.assertEqual(ops[0].proj, '+proj=pipeline +step +inv +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80')
self.assertTrue(ops[0].isAvailable)
self.assertEqual(ops[0].accuracy, 0.01)
self.assertEqual(len(ops[0].grids), 0)
self.assertTrue(ops[1].name)
self.assertEqual(ops[1].proj, '+proj=pipeline +step +inv +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80')
self.assertEqual(ops[1].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
self.assertEqual(len(ops[1].grids), 1)
self.assertEqual(ops[1].grids[0].shortName, 'GDA94_GDA2020_conformal_and_distortion.gsb')
self.assertEqual(ops[1].grids[0].fullName, '')
self.assertEqual(ops[1].grids[0].packageName, 'proj-datumgrid-oceania')
self.assertEqual(ops[1].grids[0].url, 'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip')
self.assertTrue(ops[1].grids[0].directDownload)
self.assertTrue(ops[1].grids[0].openLicense)
self.assertTrue(ops[2].name)
self.assertEqual(ops[2].proj, '+proj=pipeline +step +inv +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80')
self.assertEqual(ops[2].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
self.assertEqual(len(ops[2].grids), 1)
self.assertEqual(ops[2].grids[0].shortName, 'GDA94_GDA2020_conformal.gsb')
self.assertEqual(ops[2].grids[0].fullName, '')
self.assertEqual(ops[2].grids[0].packageName, 'proj-datumgrid-oceania')
self.assertEqual(ops[2].grids[0].url, 'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip')
self.assertTrue(ops[2].grids[0].directDownload)
self.assertTrue(ops[2].grids[0].openLicense)

self.assertGreaterEqual(len(ops), 3)

op1_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +inv +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'][0]
self.assertTrue(ops[op1_index].name)
self.assertEqual(ops[op1_index].proj, '+proj=pipeline +step +inv +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +step +proj=push +v_3 +step +proj=cart +ellps=GRS80 +step +proj=helmert +x=0.06155 +y=-0.01087 +z=-0.04019 +rx=-0.0394924 +ry=-0.0327221 +rz=-0.0328979 +s=-0.009994 +convention=coordinate_frame +step +inv +proj=cart +ellps=GRS80 +step +proj=pop +v_3 +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80')
self.assertTrue(ops[op1_index].isAvailable)
self.assertEqual(ops[op1_index].accuracy, 0.01)
self.assertEqual(len(ops[op1_index].grids), 0)

op2_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +inv +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'][0]
self.assertTrue(ops[op2_index].name)
self.assertEqual(ops[op2_index].proj, '+proj=pipeline +step +inv +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80')
self.assertEqual(ops[op2_index].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
self.assertEqual(len(ops[op2_index].grids), 1)
self.assertEqual(ops[op2_index].grids[0].shortName, 'GDA94_GDA2020_conformal_and_distortion.gsb')
self.assertEqual(ops[op2_index].grids[0].fullName, '')
self.assertEqual(ops[op2_index].grids[0].packageName, 'proj-datumgrid-oceania')
self.assertEqual(ops[op2_index].grids[0].url, 'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip')
self.assertTrue(ops[op2_index].grids[0].directDownload)
self.assertTrue(ops[op2_index].grids[0].openLicense)

op3_index = [i for i in range(len(ops)) if ops[i].proj == '+proj=pipeline +step +inv +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80'][0]
self.assertTrue(ops[op3_index].name)
self.assertEqual(ops[op3_index].proj, '+proj=pipeline +step +inv +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal.gsb +step +proj=lcc +lat_0=-37 +lon_0=145 +lat_1=-36 +lat_2=-38 +x_0=2500000 +y_0=2500000 +ellps=GRS80')
self.assertEqual(ops[op3_index].accuracy, 0.05) # actually incorrect in EPSG registry, may need updating
self.assertEqual(len(ops[op3_index].grids), 1)
self.assertEqual(ops[op3_index].grids[0].shortName, 'GDA94_GDA2020_conformal.gsb')
self.assertEqual(ops[op3_index].grids[0].fullName, '')
self.assertEqual(ops[op3_index].grids[0].packageName, 'proj-datumgrid-oceania')
self.assertEqual(ops[op3_index].grids[0].url, 'https://download.osgeo.org/proj/proj-datumgrid-oceania-latest.zip')
self.assertTrue(ops[op3_index].grids[0].directDownload)
self.assertTrue(ops[op3_index].grids[0].openLicense)


if __name__ == '__main__':
Expand Down

0 comments on commit 270c605

Please sign in to comment.