def testWriteReadXmlProj6(self):
        # setup a context
        context = QgsCoordinateTransformContext()

        proj_1 = '+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=intl +step +proj=helmert +x=-18.944 +y=-379.364 +z=-24.063 +rx=-0.04 +ry=0.764 +rz=-6.431 +s=3.657 +convention=coordinate_frame +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        proj_2 = '+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=intl +step +proj=helmert +x=-150 +y=-250 +z=-1 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'

        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem(4204),
                                                       QgsCoordinateReferenceSystem(4326), proj_1))
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem(4205),
                                                       QgsCoordinateReferenceSystem(4326), proj_2))

        self.assertEqual(context.coordinateOperations(),
                         {('EPSG:4204', 'EPSG:4326'): proj_1,
                          ('EPSG:4205', 'EPSG:4326'): proj_2})

        # save to xml
        doc = QDomDocument("testdoc")
        elem = doc.createElement("test")
        context.writeXml(elem, QgsReadWriteContext())

        # restore from xml
        context2 = QgsCoordinateTransformContext()
        context2.readXml(elem, QgsReadWriteContext())

        # check result
        self.assertEqual(context2.coordinateOperations(),
                         {('EPSG:4204', 'EPSG:4326'): proj_1,
                          ('EPSG:4205', 'EPSG:4326'): proj_2})
示例#2
0
    def testCalculateSourceDestProj6(self):
        context = QgsCoordinateTransformContext()

        # empty context
        self.assertEqual(
            context.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283')), '')

        # add specific source/dest pair - should take precedence
        context.addCoordinateOperation(
            QgsCoordinateReferenceSystem('EPSG:28356'),
            QgsCoordinateReferenceSystem('EPSG:4283'), 'proj 1')
        self.assertEqual(
            context.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:28356'),
                QgsCoordinateReferenceSystem('EPSG:4283')), 'proj 1')
        self.assertEqual(
            context.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283')), '')
        self.assertEqual(
            context.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:28356'),
                QgsCoordinateReferenceSystem('EPSG:3111')), '')
        # check that reverse transforms are automatically supported
        self.assertEqual(
            context.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:28356')), 'proj 1')
    def testReadWriteSettingsProj6(self):
        context = QgsCoordinateTransformContext()
        context.readSettings()

        proj_1 = '+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=intl +step +proj=helmert +x=-18.944 +y=-379.364 +z=-24.063 +rx=-0.04 +ry=0.764 +rz=-6.431 +s=3.657 +convention=coordinate_frame +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        proj_2 = '+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=intl +step +proj=helmert +x=-150 +y=-250 +z=-1 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'

        # should be empty
        self.assertEqual(context.coordinateOperations(), {})

        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem(4204),
                                                       QgsCoordinateReferenceSystem(4326), proj_1))
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem(4205),
                                                       QgsCoordinateReferenceSystem(4326), proj_2))

        self.assertEqual(context.coordinateOperations(),
                         {('EPSG:4204', 'EPSG:4326'): proj_1,
                          ('EPSG:4205', 'EPSG:4326'): proj_2})

        # save to settings
        context.writeSettings()

        # restore from settings
        context2 = QgsCoordinateTransformContext()
        self.assertEqual(context2.coordinateOperations(), {})
        context2.readSettings()

        # check result
        self.assertEqual(context2.coordinateOperations(),
                         {('EPSG:4204', 'EPSG:4326'): proj_1,
                          ('EPSG:4205', 'EPSG:4326'): proj_2})
    def testReadWriteSettingsProj6(self):
        context = QgsCoordinateTransformContext()
        context.readSettings()

        proj_1 = '+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=intl +step +proj=helmert +x=-18.944 +y=-379.364 +z=-24.063 +rx=-0.04 +ry=0.764 +rz=-6.431 +s=3.657 +convention=coordinate_frame +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        proj_2 = '+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=intl +step +proj=helmert +x=-150 +y=-250 +z=-1 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'

        # should be empty
        self.assertEqual(context.coordinateOperations(), {})

        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem(4204),
                                                       QgsCoordinateReferenceSystem(4326), proj_1))
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem(4205),
                                                       QgsCoordinateReferenceSystem(4326), proj_2))

        self.assertEqual(context.coordinateOperations(),
                         {('EPSG:4204', 'EPSG:4326'): proj_1,
                          ('EPSG:4205', 'EPSG:4326'): proj_2})

        # save to settings
        context.writeSettings()

        # restore from settings
        context2 = QgsCoordinateTransformContext()
        self.assertEqual(context2.coordinateOperations(), {})
        context2.readSettings()

        # check result
        self.assertEqual(context2.coordinateOperations(),
                         {('EPSG:4204', 'EPSG:4326'): proj_1,
                          ('EPSG:4205', 'EPSG:4326'): proj_2})
    def testWriteReadXmlProj6(self):
        # setup a context
        context = QgsCoordinateTransformContext()

        proj_1 = '+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=intl +step +proj=helmert +x=-18.944 +y=-379.364 +z=-24.063 +rx=-0.04 +ry=0.764 +rz=-6.431 +s=3.657 +convention=coordinate_frame +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        proj_2 = '+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=intl +step +proj=helmert +x=-150 +y=-250 +z=-1 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'

        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem(4204),
                                                       QgsCoordinateReferenceSystem(4326), proj_1))
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem(4205),
                                                       QgsCoordinateReferenceSystem(4326), proj_2))

        self.assertEqual(context.coordinateOperations(),
                         {('EPSG:4204', 'EPSG:4326'): proj_1,
                          ('EPSG:4205', 'EPSG:4326'): proj_2})

        # save to xml
        doc = QDomDocument("testdoc")
        elem = doc.createElement("test")
        context.writeXml(elem, QgsReadWriteContext())

        # restore from xml
        context2 = QgsCoordinateTransformContext()
        context2.readXml(elem, QgsReadWriteContext())

        # check result
        self.assertEqual(context2.coordinateOperations(),
                         {('EPSG:4204', 'EPSG:4326'): proj_1,
                          ('EPSG:4205', 'EPSG:4326'): proj_2})
    def testCalculateSourceDestProj6(self):
        context = QgsCoordinateTransformContext()

        # empty context
        self.assertEqual(context.calculateCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:3111'),
                                                              QgsCoordinateReferenceSystem('EPSG:4283')),
                         '')

        # add specific source/dest pair - should take precedence
        context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:28356'),
                                       QgsCoordinateReferenceSystem('EPSG:4283'),
                                       'proj 1')
        self.assertEqual(context.calculateCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:28356'),
                                                              QgsCoordinateReferenceSystem('EPSG:4283')),
                         'proj 1')
        self.assertEqual(context.calculateCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:3111'),
                                                              QgsCoordinateReferenceSystem('EPSG:4283')),
                         '')
        self.assertEqual(context.calculateCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:28356'),
                                                              QgsCoordinateReferenceSystem('EPSG:3111')),
                         '')
        # check that reverse transforms are automatically supported
        self.assertEqual(context.calculateCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:4283'),
                                                              QgsCoordinateReferenceSystem('EPSG:28356')),
                         'proj 1')
示例#7
0
    def testContextProj6(self):
        """
        Various tests to ensure that datum transforms are correctly set respecting context
        """
        context = QgsCoordinateTransformContext()
        context.addCoordinateOperation(
            QgsCoordinateReferenceSystem('EPSG:28356'),
            QgsCoordinateReferenceSystem('EPSG:4283'), 'proj')

        transform = QgsCoordinateTransform(
            QgsCoordinateReferenceSystem('EPSG:28354'),
            QgsCoordinateReferenceSystem('EPSG:28353'), context)
        self.assertEqual(
            list(transform.context().coordinateOperations().keys()),
            [('EPSG:28356', 'EPSG:4283')])

        # should be no coordinate operation
        self.assertEqual(transform.coordinateOperation(), '')

        # matching source
        transform = QgsCoordinateTransform(
            QgsCoordinateReferenceSystem('EPSG:28356'),
            QgsCoordinateReferenceSystem('EPSG:28353'), context)
        self.assertEqual(transform.coordinateOperation(), '')
        # matching dest
        transform = QgsCoordinateTransform(
            QgsCoordinateReferenceSystem('EPSG:28354'),
            QgsCoordinateReferenceSystem('EPSG:4283'), context)
        self.assertEqual(transform.coordinateOperation(), '')
        # matching src/dest pair
        transform = QgsCoordinateTransform(
            QgsCoordinateReferenceSystem('EPSG:28356'),
            QgsCoordinateReferenceSystem('EPSG:4283'), context)
        self.assertEqual(transform.coordinateOperation(), 'proj')

        # test manual overwriting
        transform.setCoordinateOperation('proj2')
        self.assertEqual(transform.coordinateOperation(), 'proj2')

        # test that auto operation setting occurs when updating src/dest crs
        transform.setSourceCrs(QgsCoordinateReferenceSystem('EPSG:28356'))
        self.assertEqual(transform.coordinateOperation(), 'proj')
        transform.setCoordinateOperation('proj2')

        transform.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:4283'))
        self.assertEqual(transform.coordinateOperation(), 'proj')
        transform.setCoordinateOperation('proj2')

        # delayed context set
        transform = QgsCoordinateTransform()
        self.assertEqual(transform.coordinateOperation(), '')
        transform.setSourceCrs(QgsCoordinateReferenceSystem('EPSG:28356'))
        transform.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:4283'))
        self.assertEqual(transform.coordinateOperation(), '')
        transform.setContext(context)
        self.assertEqual(transform.coordinateOperation(), 'proj')
        self.assertEqual(
            list(transform.context().coordinateOperations().keys()),
            [('EPSG:28356', 'EPSG:4283')])
示例#8
0
 def create_transform_context(self):
     context = QgsCoordinateTransformContext()
     # ensure grids are never used, so that we have a common transformation result
     context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:27700'),
                                    QgsCoordinateReferenceSystem('EPSG:4326'),
                                    '+proj=pipeline +step +inv +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1')
     context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:27700'),
                                    QgsCoordinateReferenceSystem('EPSG:3857'),
                                    '+proj=pipeline +step +inv +proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84')
     return context
    def testEqualOperatorProj6(self):
        context1 = QgsCoordinateTransformContext()
        context2 = QgsCoordinateTransformContext()
        self.assertTrue(context1 == context2)

        context1.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:3111'),
                                        QgsCoordinateReferenceSystem('EPSG:4283'), 'p1')
        self.assertFalse(context1 == context2)

        context2.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:3111'),
                                        QgsCoordinateReferenceSystem('EPSG:4283'), 'p1')
        self.assertTrue(context1 == context2)
    def testEqualOperatorProj6(self):
        context1 = QgsCoordinateTransformContext()
        context2 = QgsCoordinateTransformContext()
        self.assertTrue(context1 == context2)

        context1.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:3111'),
                                        QgsCoordinateReferenceSystem('EPSG:4283'), 'p1')
        self.assertFalse(context1 == context2)

        context2.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:3111'),
                                        QgsCoordinateReferenceSystem('EPSG:4283'), 'p1')
        self.assertTrue(context1 == context2)
    def testContextProj6(self):
        """
        Various tests to ensure that datum transforms are correctly set respecting context
        """
        context = QgsCoordinateTransformContext()
        context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:28356'),
                                       QgsCoordinateReferenceSystem('EPSG:4283'),
                                       'proj')

        transform = QgsCoordinateTransform(QgsCoordinateReferenceSystem('EPSG:28354'), QgsCoordinateReferenceSystem('EPSG:28353'), context)
        self.assertEqual(list(transform.context().coordinateOperations().keys()), [('EPSG:28356', 'EPSG:4283')])

        # should be no coordinate operation
        self.assertEqual(transform.coordinateOperation(), '')

        # matching source
        transform = QgsCoordinateTransform(QgsCoordinateReferenceSystem('EPSG:28356'), QgsCoordinateReferenceSystem('EPSG:28353'), context)
        self.assertEqual(transform.coordinateOperation(), '')
        # matching dest
        transform = QgsCoordinateTransform(QgsCoordinateReferenceSystem('EPSG:28354'),
                                           QgsCoordinateReferenceSystem('EPSG:4283'), context)
        self.assertEqual(transform.coordinateOperation(), '')
        # matching src/dest pair
        transform = QgsCoordinateTransform(QgsCoordinateReferenceSystem('EPSG:28356'),
                                           QgsCoordinateReferenceSystem('EPSG:4283'), context)
        self.assertEqual(transform.coordinateOperation(), 'proj')

        # test manual overwriting
        transform.setCoordinateOperation('proj2')
        self.assertEqual(transform.coordinateOperation(), 'proj2')

        # test that auto operation setting occurs when updating src/dest crs
        transform.setSourceCrs(QgsCoordinateReferenceSystem('EPSG:28356'))
        self.assertEqual(transform.coordinateOperation(), 'proj')
        transform.setCoordinateOperation('proj2')

        transform.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:4283'))
        self.assertEqual(transform.coordinateOperation(), 'proj')
        transform.setCoordinateOperation('proj2')

        # delayed context set
        transform = QgsCoordinateTransform()
        self.assertEqual(transform.coordinateOperation(), '')
        transform.setSourceCrs(QgsCoordinateReferenceSystem('EPSG:28356'))
        transform.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:4283'))
        self.assertEqual(transform.coordinateOperation(), '')
        transform.setContext(context)
        self.assertEqual(transform.coordinateOperation(), 'proj')
        self.assertEqual(list(transform.context().coordinateOperations().keys()), [('EPSG:28356', 'EPSG:4283')])
示例#12
0
    def testBasic(self):
        req = QgsProfileRequest(QgsLineString([[1, 2], [3, 4]]))
        self.assertEqual(req.profileCurve().asWkt(), 'LineString (1 2, 3 4)')

        req.setCrs(QgsCoordinateReferenceSystem('EPSG:3857')).setTolerance(
            5).setStepDistance(15)
        self.assertEqual(req.crs().authid(), 'EPSG:3857')
        self.assertEqual(req.tolerance(), 5)
        self.assertEqual(req.stepDistance(), 15)

        proj_string = '+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=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        transform_context = QgsCoordinateTransformContext()
        transform_context.addCoordinateOperation(
            QgsCoordinateReferenceSystem('EPSG:3111'),
            QgsCoordinateReferenceSystem('EPSG:4283'), proj_string)
        req.setTransformContext(transform_context)
        self.assertEqual(
            req.transformContext().calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283')), proj_string)

        exp_context = QgsExpressionContext()
        context_scope = QgsExpressionContextScope()
        context_scope.setVariable('test_var', 5, True)
        exp_context.appendScope(context_scope)
        req.setExpressionContext(exp_context)

        self.assertEqual(req.expressionContext().variable('test_var'), 5)

        terrain = QgsFlatTerrainProvider()
        terrain.setOffset(5)
        req.setTerrainProvider(terrain)
        self.assertEqual(req.terrainProvider().offset(), 5)

        copy = QgsProfileRequest(req)
        self.assertEqual(copy.profileCurve().asWkt(), 'LineString (1 2, 3 4)')
        self.assertEqual(copy.crs().authid(), 'EPSG:3857')
        self.assertEqual(copy.tolerance(), 5)
        self.assertEqual(copy.stepDistance(), 15)
        self.assertEqual(
            copy.transformContext().calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283')), proj_string)
        self.assertIsInstance(copy.terrainProvider(), QgsFlatTerrainProvider)
        self.assertEqual(copy.terrainProvider().offset(), 5)
        self.assertEqual(copy.expressionContext().variable('test_var'), 5)
示例#13
0
文件: utils.py 项目: gem/oq-irmt-qgis
def save_layer_as(orig_layer, dest_path, save_format, crs=None):
    if crs is None:
        crs = orig_layer.crs()
    old_lc_numeric = locale.getlocale(locale.LC_NUMERIC)
    locale.setlocale(locale.LC_NUMERIC, 'C')
    if Qgis.QGIS_VERSION_INT < 31003:
        writer_error = QgsVectorFileWriter.writeAsVectorFormat(
            orig_layer, dest_path, 'utf-8', crs, save_format)
    else:
        options = QgsVectorFileWriter.SaveVectorOptions()
        options.fileEncoding = 'utf8'
        options.driverName = save_format
        ctc = QgsCoordinateTransformContext()
        if crs is not None:
            ctc.addCoordinateOperation(orig_layer.crs(), crs, 'proj')
        writer_error = QgsVectorFileWriter.writeAsVectorFormatV2(
            orig_layer, dest_path, ctc, options)
    locale.setlocale(locale.LC_NUMERIC, old_lc_numeric)
    return writer_error
示例#14
0
    def testOperations(self):
        w = QgsCoordinateOperationWidget()
        self.assertFalse(w.hasSelection())
        spy = QSignalSpy(w.operationChanged)
        w.setSourceCrs(QgsCoordinateReferenceSystem('EPSG:26745'))
        self.assertEqual(len(spy), 0)
        w.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:3857'))
        self.assertEqual(len(spy), 1)
        self.assertTrue(w.hasSelection())
        self.assertGreaterEqual(len(w.availableOperations()), 3)

        self.assertEqual(
            w.defaultOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=159 +z=175 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=159 +z=175 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertTrue(w.selectedOperation().isAvailable)

        op = QgsCoordinateOperationWidget.OperationDetails()
        op.proj = '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        op.allowFallback = True
        w.setSelectedOperation(op)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertTrue(w.selectedOperation().allowFallback)
        self.assertEqual(len(spy), 2)
        w.setSelectedOperation(op)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertTrue(w.selectedOperation().allowFallback)
        self.assertEqual(len(spy), 2)

        op.proj = '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=159 +z=175 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        op.allowFallback = False
        w.setSelectedOperation(op)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=159 +z=175 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertFalse(w.selectedOperation().allowFallback)
        self.assertEqual(len(spy), 3)

        op.allowFallback = True
        w.setSelectedOperation(op)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=159 +z=175 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertTrue(w.selectedOperation().allowFallback)
        self.assertEqual(len(spy), 4)

        context = QgsCoordinateTransformContext()
        op.proj = '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        w.setSelectedOperation(op)
        w.setSelectedOperationUsingContext(context)
        # should go to default, because there's nothing in the context matching these crs
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=159 +z=175 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertEqual(len(spy), 6)

        # put something in the context
        context.addCoordinateOperation(
            w.sourceCrs(), w.destinationCrs(),
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        w.setSelectedOperationUsingContext(context)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertTrue(w.selectedOperation().allowFallback)
        self.assertEqual(len(spy), 7)

        context.addCoordinateOperation(
            w.sourceCrs(), w.destinationCrs(),
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84',
            False)
        w.setSelectedOperationUsingContext(context)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +proj=unitconvert +xy_in=us-ft +xy_out=m +step +inv +proj=lcc +lat_0=33.5 +lon_0=-118 +lat_1=35.4666666666667 +lat_2=34.0333333333333 +x_0=609601.219202438 +y_0=0 +ellps=clrk66 +step +proj=push +v_3 +step +proj=cart +ellps=clrk66 +step +proj=helmert +x=-8 +y=160 +z=176 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=webmerc +lat_0=0 +lon_0=0 +x_0=0 +y_0=0 +ellps=WGS84'
        )
        self.assertFalse(w.selectedOperation().allowFallback)
        self.assertEqual(len(spy), 8)
    def testSourceDestinationDatumTransformsProj6(self):
        context = QgsCoordinateTransformContext()
        self.assertEqual(context.sourceDestinationDatumTransforms(), {})
        proj_string = '+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=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'), QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:3111'),
                                                       QgsCoordinateReferenceSystem('EPSG:4283'), proj_string))
        self.assertTrue(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'), QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'), QgsCoordinateReferenceSystem('EPSG:4326')))
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3113'), QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string})
        proj_string_2 = '+proj=pipeline +step +inv +proj=utm +zone=56 +south +ellps=GRS80 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:28356'),
                                                       QgsCoordinateReferenceSystem(4283), proj_string_2))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2})
        proj_string_3 = '+proj=pipeline +step +inv +proj=utm +zone=56 +south +ellps=GRS80 +step +proj=utm +zone=57 +south +ellps=GRS80'
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:28356'),
                                                       QgsCoordinateReferenceSystem(28357), proj_string_3))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): proj_string_3})
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:28356'),
                                                       QgsCoordinateReferenceSystem('EPSG:28357'),
                                                       'some other proj string'))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): 'some other proj string'})

        # invalid additions
        self.assertFalse(context.addCoordinateOperation(QgsCoordinateReferenceSystem(),
                                                        QgsCoordinateReferenceSystem('EPSG:28357'), 'bad proj'))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): 'some other proj string'})
        self.assertFalse(context.addCoordinateOperation(QgsCoordinateReferenceSystem('EPSG:3111'),
                                                        QgsCoordinateReferenceSystem(), 'bad proj'))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): 'some other proj string'})

        # indicate no transform required
        self.assertTrue(context.addCoordinateOperation(QgsCoordinateReferenceSystem(28357),
                                                       QgsCoordinateReferenceSystem(28356), ''))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): 'some other proj string',
                                                          ('EPSG:28357', 'EPSG:28356'): ''})

        # remove non-existing
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3113), QgsCoordinateReferenceSystem(3111))
        self.assertEqual(context.coordinateOperations(), {('EPSG:3111', 'EPSG:4283'): proj_string,
                                                          ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): 'some other proj string',
                                                          ('EPSG:28357', 'EPSG:28356'): ''})

        # remove existing
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3111),
                                          QgsCoordinateReferenceSystem(4283))
        self.assertEqual(context.coordinateOperations(), {('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28356', 'EPSG:28357'): 'some other proj string',
                                                          ('EPSG:28357', 'EPSG:28356'): ''})
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(28356),
                                          QgsCoordinateReferenceSystem(28357))
        self.assertEqual(context.coordinateOperations(), {('EPSG:28356', 'EPSG:4283'): proj_string_2,
                                                          ('EPSG:28357', 'EPSG:28356'): ''})

        context.clear()
        self.assertEqual(context.coordinateOperations(), {})
示例#16
0
    def testEquality(self):
        """
        Test equality operator
        """
        req = QgsProfileRequest(None)
        req2 = QgsProfileRequest(None)
        self.assertEqual(req, req2)

        req.setProfileCurve(QgsLineString([[1, 2], [3, 4]]))
        self.assertNotEqual(req, req2)

        req2.setProfileCurve(QgsLineString([[1, 2], [3, 5]]))
        self.assertNotEqual(req, req2)

        req.setProfileCurve(None)
        self.assertNotEqual(req, req2)

        req.setProfileCurve(QgsLineString([[1, 2], [3, 5]]))
        self.assertEqual(req, req2)

        req.setCrs(QgsCoordinateReferenceSystem('EPSG:3857'))
        self.assertNotEqual(req, req2)
        req2.setCrs(QgsCoordinateReferenceSystem('EPSG:3857'))
        self.assertEqual(req, req2)

        proj_string = '+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=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        transform_context = QgsCoordinateTransformContext()
        transform_context.addCoordinateOperation(
            QgsCoordinateReferenceSystem('EPSG:3111'),
            QgsCoordinateReferenceSystem('EPSG:4283'), proj_string)

        req.setTransformContext(transform_context)
        self.assertNotEqual(req, req2)
        req2.setTransformContext(transform_context)
        self.assertEqual(req, req2)

        req.setTolerance(5)
        self.assertNotEqual(req, req2)
        req2.setTolerance(5)
        self.assertEqual(req, req2)

        req.setStepDistance(15)
        self.assertNotEqual(req, req2)
        req2.setStepDistance(15)
        self.assertEqual(req, req2)

        terrain = QgsFlatTerrainProvider()
        terrain.setOffset(5)
        req.setTerrainProvider(terrain)
        self.assertNotEqual(req, req2)

        req2.setTerrainProvider(QgsMeshTerrainProvider())
        self.assertNotEqual(req, req2)

        req.setTerrainProvider(None)
        self.assertNotEqual(req, req2)

        req.setTerrainProvider(QgsFlatTerrainProvider())
        self.assertNotEqual(req, req2)

        req.setTerrainProvider(QgsMeshTerrainProvider())
        self.assertEqual(req, req2)
示例#17
0
    def testOperations(self):
        w = QgsCoordinateOperationWidget()
        self.assertFalse(w.hasSelection())
        spy = QSignalSpy(w.operationChanged)
        w.setSourceCrs(QgsCoordinateReferenceSystem('EPSG:28355'))
        self.assertEqual(len(spy), 0)
        w.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:7855'))
        self.assertEqual(len(spy), 1)
        self.assertTrue(w.hasSelection())
        self.assertEqual(len(w.availableOperations()), 3)

        self.assertEqual(
            w.defaultOperation().proj,
            '+proj=pipeline +step +inv +proj=utm +zone=55 +south +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=utm +zone=55 +south +ellps=GRS80'
        )
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +inv +proj=utm +zone=55 +south +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=utm +zone=55 +south +ellps=GRS80'
        )
        self.assertTrue(w.selectedOperation().isAvailable)

        op = QgsCoordinateOperationWidget.OperationDetails()
        op.proj = '+proj=pipeline +step +inv +proj=utm +zone=55 +south +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=utm +zone=55 +south +ellps=GRS80'
        w.setSelectedOperation(op)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +inv +proj=utm +zone=55 +south +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=utm +zone=55 +south +ellps=GRS80'
        )
        self.assertEqual(len(spy), 2)
        w.setSelectedOperation(op)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +inv +proj=utm +zone=55 +south +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=utm +zone=55 +south +ellps=GRS80'
        )
        self.assertEqual(len(spy), 2)

        op.proj = '+proj=pipeline +step +inv +proj=utm +zone=55 +south +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=utm +zone=55 +south +ellps=GRS80'
        w.setSelectedOperation(op)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +inv +proj=utm +zone=55 +south +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=utm +zone=55 +south +ellps=GRS80'
        )
        self.assertEqual(len(spy), 3)

        context = QgsCoordinateTransformContext()
        op.proj = '+proj=pipeline +step +inv +proj=utm +zone=55 +south +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=utm +zone=55 +south +ellps=GRS80'
        w.setSelectedOperation(op)
        w.setSelectedOperationUsingContext(context)
        # should go to default, because there's nothing in the context matching these crs
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +inv +proj=utm +zone=55 +south +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=utm +zone=55 +south +ellps=GRS80'
        )
        self.assertEqual(len(spy), 5)

        # put something in the context
        context.addCoordinateOperation(
            w.sourceCrs(), w.destinationCrs(),
            '+proj=pipeline +step +inv +proj=utm +zone=55 +south +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=utm +zone=55 +south +ellps=GRS80'
        )
        w.setSelectedOperationUsingContext(context)
        self.assertEqual(
            w.selectedOperation().proj,
            '+proj=pipeline +step +inv +proj=utm +zone=55 +south +ellps=GRS80 +step +proj=hgridshift +grids=GDA94_GDA2020_conformal_and_distortion.gsb +step +proj=utm +zone=55 +south +ellps=GRS80'
        )
        self.assertEqual(len(spy), 6)
示例#18
0
    def testSourceDestinationDatumTransformsProj6(self):
        context = QgsCoordinateTransformContext()
        self.assertEqual(context.sourceDestinationDatumTransforms(), {})
        proj_string = '+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=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                 QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertFalse(
            context.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertFalse(
            context.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')))
        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283'), proj_string))
        self.assertTrue(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                 QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3111'),
                                 QgsCoordinateReferenceSystem('EPSG:4326')))
        self.assertFalse(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:3113'),
                                 QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertEqual(context.coordinateOperations(),
                         {('EPSG:3111', 'EPSG:4283'): proj_string})
        self.assertTrue(
            context.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')))
        self.assertTrue(
            context.allowFallbackTransform(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283')))
        self.assertTrue(
            context.allowFallbackTransform(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')))

        self.assertTrue(
            context.hasTransform(QgsCoordinateReferenceSystem('EPSG:4283'),
                                 QgsCoordinateReferenceSystem('EPSG:3111')))

        self.assertEqual(
            context.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283')), proj_string)
        self.assertFalse(
            context.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem('EPSG:4283')))
        # ideally not equal, but for now it's all we can do, and return True for mustReverseCoordinateOperation here
        self.assertEqual(
            context.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')), proj_string)
        self.assertTrue(
            context.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')))
        self.assertTrue(
            context.allowFallbackTransform(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')))

        proj_string_2 = 'dummy'
        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111'), proj_string_2,
                False))
        self.assertEqual(
            context.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')), proj_string_2)
        self.assertFalse(
            context.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3111')))
        context.removeCoordinateOperation(
            QgsCoordinateReferenceSystem('EPSG:4283'),
            QgsCoordinateReferenceSystem('EPSG:3111'))

        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3113'), proj_string_2,
                False))
        self.assertFalse(
            context.allowFallbackTransform(
                QgsCoordinateReferenceSystem('EPSG:4283'),
                QgsCoordinateReferenceSystem('EPSG:3113')))
        self.assertFalse(
            context.allowFallbackTransform(
                QgsCoordinateReferenceSystem('EPSG:3113'),
                QgsCoordinateReferenceSystem('EPSG:4283')))

        context.removeCoordinateOperation(
            QgsCoordinateReferenceSystem('EPSG:4283'),
            QgsCoordinateReferenceSystem('EPSG:3113'))

        proj_string_2 = '+proj=pipeline +step +inv +proj=utm +zone=56 +south +ellps=GRS80 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:28356'),
                QgsCoordinateReferenceSystem(4283), proj_string_2))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2
            })
        proj_string_3 = '+proj=pipeline +step +inv +proj=utm +zone=56 +south +ellps=GRS80 +step +proj=utm +zone=57 +south +ellps=GRS80'
        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:28356'),
                QgsCoordinateReferenceSystem(28357), proj_string_3))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): proj_string_3
            })
        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:28356'),
                QgsCoordinateReferenceSystem('EPSG:28357'),
                'some other proj string'))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): 'some other proj string'
            })

        # invalid additions
        self.assertFalse(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem(),
                QgsCoordinateReferenceSystem('EPSG:28357'), 'bad proj'))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): 'some other proj string'
            })
        self.assertFalse(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:3111'),
                QgsCoordinateReferenceSystem(), 'bad proj'))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): 'some other proj string'
            })

        # indicate no transform required
        self.assertTrue(
            context.addCoordinateOperation(QgsCoordinateReferenceSystem(28357),
                                           QgsCoordinateReferenceSystem(28356),
                                           ''))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): 'some other proj string',
                ('EPSG:28357', 'EPSG:28356'): ''
            })

        # remove non-existing
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3113),
                                          QgsCoordinateReferenceSystem(3111))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:3111', 'EPSG:4283'): proj_string,
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): 'some other proj string',
                ('EPSG:28357', 'EPSG:28356'): ''
            })

        # remove existing
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(3111),
                                          QgsCoordinateReferenceSystem(4283))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28356', 'EPSG:28357'): 'some other proj string',
                ('EPSG:28357', 'EPSG:28356'): ''
            })
        context.removeCoordinateOperation(QgsCoordinateReferenceSystem(28356),
                                          QgsCoordinateReferenceSystem(28357))
        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:28356', 'EPSG:4283'): proj_string_2,
                ('EPSG:28357', 'EPSG:28356'): ''
            })

        context.clear()
        self.assertEqual(context.coordinateOperations(), {})
    def testWriteReadXmlProj6(self):
        # setup a context
        context = QgsCoordinateTransformContext()

        proj_1 = '+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=intl +step +proj=helmert +x=-18.944 +y=-379.364 +z=-24.063 +rx=-0.04 +ry=0.764 +rz=-6.431 +s=3.657 +convention=coordinate_frame +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        proj_2 = '+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=intl +step +proj=helmert +x=-150 +y=-250 +z=-1 +step +inv +proj=cart +ellps=WGS84 +step +proj=pop +v_3 +step +proj=unitconvert +xy_in=rad +xy_out=deg +step +proj=axisswap +order=2,1'
        proj_3 = '+proj=pipeline +step +proj=axisswap +order=2,1'

        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4204'),
                QgsCoordinateReferenceSystem('EPSG:4326'), proj_1, True))
        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4205'),
                QgsCoordinateReferenceSystem('EPSG:4326'), proj_2, False))

        # also insert a crs with no authid available
        self.assertTrue(
            context.addCoordinateOperation(
                QgsCoordinateReferenceSystem.fromProj(
                    "+proj=longlat +a=6378137 +rf=298.25722356300003 +no_defs"
                ), QgsCoordinateReferenceSystem('EPSG:4326'), proj_3, False))

        self.assertEqual(
            context.coordinateOperations(), {
                ('EPSG:4204', 'EPSG:4326'): proj_1,
                ('EPSG:4205', 'EPSG:4326'): proj_2,
                ('', 'EPSG:4326'): proj_3
            })

        # save to xml
        doc = QDomDocument("testdoc")
        elem = doc.createElement("test")
        context.writeXml(elem, QgsReadWriteContext())

        # restore from xml
        context2 = QgsCoordinateTransformContext()
        context2.readXml(elem, QgsReadWriteContext())

        # check result
        self.assertEqual(
            context2.coordinateOperations(), {
                ('EPSG:4204', 'EPSG:4326'): proj_1,
                ('EPSG:4205', 'EPSG:4326'): proj_2,
                ('', 'EPSG:4326'): proj_3
            })
        self.assertEqual(
            context2.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem.fromProj(
                    "+proj=longlat +a=6378137 +rf=298.25722356300003 +no_defs"
                ), QgsCoordinateReferenceSystem('EPSG:4326')),
            '+proj=pipeline +step +proj=axisswap +order=2,1')
        self.assertFalse(
            context2.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem.fromProj(
                    "+proj=longlat +a=6378137 +rf=298.25722356300003 +no_defs"
                ), QgsCoordinateReferenceSystem('EPSG:4326')))
        self.assertEqual(
            context2.calculateCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4326'),
                QgsCoordinateReferenceSystem.fromProj(
                    "+proj=longlat +a=6378137 +rf=298.25722356300003 +no_defs")
            ), '+proj=pipeline +step +proj=axisswap +order=2,1')
        self.assertTrue(
            context2.mustReverseCoordinateOperation(
                QgsCoordinateReferenceSystem('EPSG:4326'),
                QgsCoordinateReferenceSystem.fromProj(
                    "+proj=longlat +a=6378137 +rf=298.25722356300003 +no_defs")
            ))
        self.assertTrue(
            context2.allowFallbackTransform(
                QgsCoordinateReferenceSystem('EPSG:4204'),
                QgsCoordinateReferenceSystem('EPSG:4326')))
        self.assertFalse(
            context2.allowFallbackTransform(
                QgsCoordinateReferenceSystem('EPSG:4205'),
                QgsCoordinateReferenceSystem('EPSG:4326')))