Ejemplo n.º 1
0
    def testStepSize(self):
        ml = QgsMeshLayer(
            os.path.join(unitTestDataPath(), '3d', 'elev_mesh.2dm'), 'mdal',
            'mdal')
        self.assertTrue(ml.isValid())
        ml.setCrs(QgsCoordinateReferenceSystem('EPSG:27700'))

        curve = QgsLineString()
        curve.fromWkt(
            'LineString (-348095.18706532847136259 6633687.0235139261931181, -347271.57799367723055184 6633093.13086318597197533, -346140.60267287614988163 6632697.89590711053460836, -345777.013075890194159 6631575.50219972990453243)'
        )
        req = QgsProfileRequest(curve)
        # set a smaller step size then would be automatically calculated
        req.setStepDistance(10)

        # set correct crs for linestring and re-try
        req.setCrs(QgsCoordinateReferenceSystem('EPSG:3857'))
        generator = ml.createProfileGenerator(req)
        self.assertTrue(generator.generateProfile())

        r = generator.takeResults()
        results = r.distanceToHeightMap()
        self.assertEqual(len(results), 216)
        first_point = min(results.keys())
        last_point = max(results.keys())
        self.assertAlmostEqual(results[first_point], 152.87405434310168, 0)
        self.assertAlmostEqual(results[last_point], 98.78085001573021, 0)

        self.assertAlmostEqual(r.zRange().lower(), 80, 2)
        self.assertAlmostEqual(r.zRange().upper(), 152.874, 0)
Ejemplo n.º 2
0
    def testGenerationWithStepSize(self):
        rl = QgsRasterLayer(os.path.join(unitTestDataPath(), '3d', 'dtm.tif'), 'DTM')
        self.assertTrue(rl.isValid())

        curve = QgsLineString()
        curve.fromWkt('LineString (-348095.18706532847136259 6633687.0235139261931181, -347271.57799367723055184 6633093.13086318597197533, -346140.60267287614988163 6632697.89590711053460836, -345777.013075890194159 6631575.50219972990453243)')
        req = QgsProfileRequest(curve)
        req.setStepDistance(10)

        generator = rl.createProfileGenerator(req)
        # not enabled for elevation
        self.assertIsNone(generator)

        rl.elevationProperties().setEnabled(True)

        generator = rl.createProfileGenerator(req)
        self.assertIsNotNone(generator)
        # the request did not have the crs of the linestring set, so the whole linestring falls outside the raster extent
        self.assertFalse(generator.generateProfile())

        # set correct crs for linestring and re-try
        req.setCrs(QgsCoordinateReferenceSystem('EPSG:3857'))
        generator = rl.createProfileGenerator(req)
        self.assertTrue(generator.generateProfile())

        r = generator.takeResults()
        results = r.distanceToHeightMap()
        self.assertEqual(len(results), 341)
        first_point = min(results.keys())
        last_point = max(results.keys())
        self.assertEqual(results[first_point], 154)
        self.assertEqual(results[last_point], 99)

        self.assertEqual(r.zRange().lower(), 74)
        self.assertEqual(r.zRange().upper(), 154)
Ejemplo n.º 3
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)