def testCopyConstructor(self): """ Test the copy constructor """ c1 = QgsRenderContext() c1.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysText) c1.setMapExtent(QgsRectangle(1, 2, 3, 4)) c1.setZRange(QgsDoubleRange(1, 10)) c2 = QgsRenderContext(c1) self.assertEqual(c2.textRenderFormat(), QgsRenderContext.TextFormatAlwaysText) self.assertEqual(c2.mapExtent(), QgsRectangle(1, 2, 3, 4)) self.assertEqual(c2.zRange(), QgsDoubleRange(1, 10)) c1.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysOutlines) c2 = QgsRenderContext(c1) self.assertEqual(c2.textRenderFormat(), QgsRenderContext.TextFormatAlwaysOutlines) c1.setIsTemporal(True) c1.setTemporalRange(QgsDateTimeRange(QDateTime(2020, 1, 1, 0, 0), QDateTime(2010, 12, 31, 23, 59))) c2 = QgsRenderContext(c1) self.assertEqual(c2.isTemporal(), True) self.assertEqual(c2.temporalRange(), QgsDateTimeRange(QDateTime(2020, 1, 1, 0, 0), QDateTime(2010, 12, 31, 23, 59)))
def testFromMapSettings(self): """ test QgsRenderContext.fromMapSettings() """ ms = QgsMapSettings() ms.setOutputSize(QSize(1000, 1000)) ms.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:3111')) ms.setExtent(QgsRectangle(10000, 20000, 30000, 40000)) ms.setFlag(QgsMapSettings.Antialiasing, True) ms.setFlag(QgsMapSettings.LosslessImageRendering, True) ms.setFlag(QgsMapSettings.Render3DMap, True) ms.setZRange(QgsDoubleRange(1, 10)) ms.setOutputSize(QSize(100, 100)) ms.setDevicePixelRatio(2) ms.setOutputImageFormat(QImage.Format_Alpha8) ms.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysText) rc = QgsRenderContext.fromMapSettings(ms) self.assertEqual(rc.textRenderFormat(), QgsRenderContext.TextFormatAlwaysText) self.assertTrue(rc.testFlag(QgsRenderContext.Antialiasing)) self.assertTrue(rc.testFlag(QgsRenderContext.LosslessImageRendering)) self.assertTrue(rc.testFlag(QgsRenderContext.Render3DMap)) self.assertEqual(ms.zRange(), QgsDoubleRange(1, 10)) self.assertEqual(rc.symbologyReferenceScale(), -1) self.assertEqual(rc.outputSize(), QSize(100, 100)) self.assertEqual(rc.devicePixelRatio(), 2) self.assertEqual(rc.deviceOutputSize(), QSize(200, 200)) self.assertEqual(rc.imageFormat(), QImage.Format_Alpha8) # should have an valid mapToPixel self.assertTrue(rc.mapToPixel().isValid()) ms.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysOutlines) ms.setZRange(QgsDoubleRange()) rc = QgsRenderContext.fromMapSettings(ms) self.assertEqual(rc.textRenderFormat(), QgsRenderContext.TextFormatAlwaysOutlines) self.assertTrue(ms.zRange().isInfinite()) self.assertEqual(rc.mapExtent(), QgsRectangle(10000, 20000, 30000, 40000)) ms.setIsTemporal(True) rc = QgsRenderContext.fromMapSettings(ms) self.assertEqual(rc.isTemporal(), True) ms.setTemporalRange( QgsDateTimeRange(QDateTime(2020, 1, 1, 0, 0), QDateTime(2010, 12, 31, 23, 59))) rc = QgsRenderContext.fromMapSettings(ms) self.assertEqual( rc.temporalRange(), QgsDateTimeRange(QDateTime(2020, 1, 1, 0, 0), QDateTime(2010, 12, 31, 23, 59))) ms.setDpiTarget(111.1) rc = QgsRenderContext.fromMapSettings(ms) self.assertEqual(rc.dpiTarget(), 111.1)
def testDoubleRange(self): self.assertEqual( QgsDoubleRange(1, 10).__repr__(), "<QgsDoubleRange: [1, 10]>") self.assertEqual( QgsDoubleRange(1, 10, False).__repr__(), "<QgsDoubleRange: (1, 10]>") self.assertEqual( QgsDoubleRange(1, 10, True, False).__repr__(), "<QgsDoubleRange: [1, 10)>")
def testRenderZRange(self): layer = QgsPointCloudLayer( unitTestDataPath() + '/point_clouds/ept/sunshine-coast/ept.json', 'test', 'ept') self.assertTrue(layer.isValid()) renderer = QgsPointCloudClassifiedRenderer() renderer.setAttribute('Classification') layer.setRenderer(renderer) layer.renderer().setPointSize(2) layer.renderer().setPointSizeUnit(QgsUnitTypes.RenderMillimeters) mapsettings = QgsMapSettings() mapsettings.setOutputSize(QSize(400, 400)) mapsettings.setOutputDpi(96) mapsettings.setDestinationCrs(layer.crs()) mapsettings.setExtent(QgsRectangle(498061, 7050991, 498069, 7050999)) mapsettings.setLayers([layer]) mapsettings.setZRange(QgsDoubleRange(74.7, 75)) renderchecker = QgsMultiRenderChecker() renderchecker.setMapSettings(mapsettings) renderchecker.setControlPathPrefix('pointcloudrenderer') renderchecker.setControlName('expected_classified_zfilter') result = renderchecker.runTest('expected_classified_zfilter') TestQgsPointCloudClassifiedRenderer.report += renderchecker.report() self.assertTrue(result)
def testRenderZRange(self): layer = QgsPointCloudLayer( unitTestDataPath() + '/point_clouds/ept/sunshine-coast/ept.json', 'test', 'ept') self.assertTrue(layer.isValid()) renderer = QgsPointCloudAttributeByRampRenderer() renderer.setAttribute('Intensity') renderer.setMinimum(200) renderer.setMaximum(1000) ramp = QgsStyle.defaultStyle().colorRamp("Viridis") shader = QgsColorRampShader(200, 1000, ramp) shader.classifyColorRamp() renderer.setColorRampShader(shader) layer.setRenderer(renderer) layer.renderer().setPointSize(2) layer.renderer().setPointSizeUnit(QgsUnitTypes.RenderMillimeters) mapsettings = QgsMapSettings() mapsettings.setOutputSize(QSize(400, 400)) mapsettings.setOutputDpi(96) mapsettings.setDestinationCrs(layer.crs()) mapsettings.setExtent(QgsRectangle(498061, 7050991, 498069, 7050999)) mapsettings.setLayers([layer]) mapsettings.setZRange(QgsDoubleRange(74.7, 75)) renderchecker = QgsMultiRenderChecker() renderchecker.setMapSettings(mapsettings) renderchecker.setControlPathPrefix('pointcloudrenderer') renderchecker.setControlName('expected_ramp_zfilter') result = renderchecker.runTest('expected_ramp_zfilter') TestQgsPointCloudAttributeByRampRenderer.report += renderchecker.report( ) self.assertTrue(result)
def testRenderZRange(self): layer = QgsPointCloudLayer( unitTestDataPath() + '/point_clouds/ept/rgb/ept.json', 'test', 'ept') self.assertTrue(layer.isValid()) layer.renderer().setPointSize(2) layer.renderer().setPointSizeUnit(QgsUnitTypes.RenderMillimeters) mapsettings = QgsMapSettings() mapsettings.setOutputSize(QSize(400, 400)) mapsettings.setOutputDpi(96) mapsettings.setDestinationCrs(layer.crs()) mapsettings.setExtent( QgsRectangle(497753.5, 7050887.5, 497754.6, 7050888.6)) mapsettings.setLayers([layer]) mapsettings.setZRange(QgsDoubleRange(1.1, 1.2)) renderchecker = QgsMultiRenderChecker() renderchecker.setMapSettings(mapsettings) renderchecker.setControlPathPrefix('pointcloudrenderer') renderchecker.setControlName('expected_zfilter') result = renderchecker.runTest('expected_zfilter') TestQgsPointCloudRgbRenderer.report += renderchecker.report() self.assertTrue(result)
def testGettersSetters(self): """ Basic getter/setter tests """ c = QgsRenderContext() c.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysText) self.assertEqual(c.textRenderFormat(), QgsRenderContext.TextFormatAlwaysText) c.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysOutlines) self.assertEqual(c.textRenderFormat(), QgsRenderContext.TextFormatAlwaysOutlines) c.setMapExtent(QgsRectangle(1, 2, 3, 4)) self.assertEqual(c.mapExtent(), QgsRectangle(1, 2, 3, 4)) self.assertTrue(c.zRange().isInfinite()) c.setZRange(QgsDoubleRange(1, 10)) self.assertEqual(c.zRange(), QgsDoubleRange(1, 10))
def testGettersSetters(self): """ Basic getter/setter tests """ c = QgsRenderContext() c.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysText) self.assertEqual(c.textRenderFormat(), QgsRenderContext.TextFormatAlwaysText) c.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysOutlines) self.assertEqual(c.textRenderFormat(), QgsRenderContext.TextFormatAlwaysOutlines) c.setMapExtent(QgsRectangle(1, 2, 3, 4)) self.assertEqual(c.mapExtent(), QgsRectangle(1, 2, 3, 4)) self.assertTrue(c.zRange().isInfinite()) c.setZRange(QgsDoubleRange(1, 10)) self.assertEqual(c.zRange(), QgsDoubleRange(1, 10)) self.assertEqual(c.symbologyReferenceScale(), -1) c.setSymbologyReferenceScale(1000) self.assertEqual(c.symbologyReferenceScale(), 1000) self.assertTrue(c.outputSize().isEmpty()) c.setOutputSize(QSize(100, 200)) self.assertEqual(c.outputSize(), QSize(100, 200)) self.assertEqual(c.devicePixelRatio(), 1) c.setDevicePixelRatio(2) self.assertEqual(c.devicePixelRatio(), 2) self.assertEqual(c.deviceOutputSize(), QSize(200, 400)) c.setImageFormat(QImage.Format_Alpha8) self.assertEqual(c.imageFormat(), QImage.Format_Alpha8) # should have an invalid mapToPixel by default self.assertFalse(c.mapToPixel().isValid()) self.assertEqual(c.frameRate(), -1) c.setFrameRate(30) self.assertEqual(c.frameRate(), 30) self.assertEqual(c.currentFrame(), -1) c.setCurrentFrame(6) self.assertEqual(c.currentFrame(), 6)
def testCopyConstructor(self): """ Test the copy constructor """ c1 = QgsRenderContext() c1.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysText) c1.setMapExtent(QgsRectangle(1, 2, 3, 4)) c1.setZRange(QgsDoubleRange(1, 10)) c1.setSymbologyReferenceScale(1000) c1.setOutputSize(QSize(100, 200)) c1.setImageFormat(QImage.Format_Alpha8) c1.setDevicePixelRatio(2) c1.setFrameRate(30) c1.setCurrentFrame(6) c2 = QgsRenderContext(c1) self.assertEqual(c2.textRenderFormat(), QgsRenderContext.TextFormatAlwaysText) self.assertEqual(c2.mapExtent(), QgsRectangle(1, 2, 3, 4)) self.assertEqual(c2.zRange(), QgsDoubleRange(1, 10)) self.assertEqual(c2.symbologyReferenceScale(), 1000) self.assertEqual(c2.outputSize(), QSize(100, 200)) self.assertEqual(c2.imageFormat(), QImage.Format_Alpha8) self.assertEqual(c2.devicePixelRatio(), 2) self.assertEqual(c2.deviceOutputSize(), QSize(200, 400)) self.assertEqual(c2.frameRate(), 30) self.assertEqual(c2.currentFrame(), 6) c1.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysOutlines) c2 = QgsRenderContext(c1) self.assertEqual(c2.textRenderFormat(), QgsRenderContext.TextFormatAlwaysOutlines) c1.setIsTemporal(True) c1.setTemporalRange( QgsDateTimeRange(QDateTime(2020, 1, 1, 0, 0), QDateTime(2010, 12, 31, 23, 59))) c2 = QgsRenderContext(c1) self.assertEqual(c2.isTemporal(), True) self.assertEqual( c2.temporalRange(), QgsDateTimeRange(QDateTime(2020, 1, 1, 0, 0), QDateTime(2010, 12, 31, 23, 59)))
def testFromMapSettings(self): """ test QgsRenderContext.fromMapSettings() """ ms = QgsMapSettings() ms.setOutputSize(QSize(1000, 1000)) ms.setDestinationCrs(QgsCoordinateReferenceSystem('EPSG:3111')) ms.setExtent(QgsRectangle(10000, 20000, 30000, 40000)) ms.setFlag(QgsMapSettings.Antialiasing, True) ms.setFlag(QgsMapSettings.LosslessImageRendering, True) ms.setFlag(QgsMapSettings.Render3DMap, True) ms.setZRange(QgsDoubleRange(1, 10)) ms.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysText) rc = QgsRenderContext.fromMapSettings(ms) self.assertEqual(rc.textRenderFormat(), QgsRenderContext.TextFormatAlwaysText) self.assertTrue(rc.testFlag(QgsRenderContext.Antialiasing)) self.assertTrue(rc.testFlag(QgsRenderContext.LosslessImageRendering)) self.assertTrue(rc.testFlag(QgsRenderContext.Render3DMap)) self.assertEqual(ms.zRange(), QgsDoubleRange(1, 10)) ms.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysOutlines) ms.setZRange(QgsDoubleRange()) rc = QgsRenderContext.fromMapSettings(ms) self.assertEqual(rc.textRenderFormat(), QgsRenderContext.TextFormatAlwaysOutlines) self.assertTrue(ms.zRange().isInfinite()) self.assertEqual(rc.mapExtent(), QgsRectangle(10000, 20000, 30000, 40000)) ms.setIsTemporal(True) rc = QgsRenderContext.fromMapSettings(ms) self.assertEqual(rc.isTemporal(), True) ms.setTemporalRange( QgsDateTimeRange(QDateTime(2020, 1, 1, 0, 0), QDateTime(2010, 12, 31, 23, 59))) rc = QgsRenderContext.fromMapSettings(ms) self.assertEqual( rc.temporalRange(), QgsDateTimeRange(QDateTime(2020, 1, 1, 0, 0), QDateTime(2010, 12, 31, 23, 59)))
def testGettersSetters(self): """ Basic getter/setter tests """ c = QgsRenderContext() c.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysText) self.assertEqual(c.textRenderFormat(), QgsRenderContext.TextFormatAlwaysText) c.setTextRenderFormat(QgsRenderContext.TextFormatAlwaysOutlines) self.assertEqual(c.textRenderFormat(), QgsRenderContext.TextFormatAlwaysOutlines) c.setMapExtent(QgsRectangle(1, 2, 3, 4)) self.assertEqual(c.mapExtent(), QgsRectangle(1, 2, 3, 4)) self.assertTrue(c.zRange().isInfinite()) c.setZRange(QgsDoubleRange(1, 10)) self.assertEqual(c.zRange(), QgsDoubleRange(1, 10)) self.assertEqual(c.symbologyReferenceScale(), -1) c.setSymbologyReferenceScale(1000) self.assertEqual(c.symbologyReferenceScale(), 1000) # should have an invalid mapToPixel by default self.assertFalse(c.mapToPixel().isValid())
def testUsedAttributes(self): renderer = QgsPointCloudRgbRenderer() renderer.setBlueAttribute('b') renderer.setGreenAttribute('g') renderer.setRedAttribute('r') rc = QgsRenderContext() prc = QgsPointCloudRenderContext(rc, QgsVector3D(), QgsVector3D()) self.assertEqual(renderer.usedAttributes(prc), {'r', 'g', 'b'}) # if context is filtering by z, we also need the z attribute rc.setZRange(QgsDoubleRange(1, 10)) prc = QgsPointCloudRenderContext(rc, QgsVector3D(), QgsVector3D()) self.assertEqual(renderer.usedAttributes(prc), {'r', 'g', 'b', 'Z'})
def testEquality(self): self.assertEqual(QgsDoubleRange(1, 10), QgsDoubleRange(1, 10)) self.assertNotEqual(QgsDoubleRange(1, 10), QgsDoubleRange(1, 11)) self.assertNotEqual(QgsDoubleRange(1, 10), QgsDoubleRange(2, 10)) self.assertNotEqual(QgsDoubleRange(1, 10, False), QgsDoubleRange(1, 10)) self.assertNotEqual(QgsDoubleRange(1, 10, True, False), QgsDoubleRange(1, 10))
def testGetters(self): range = QgsDoubleRange(1.0, 11.0) self.assertEqual(range.lower(), 1) self.assertEqual(range.upper(), 11) self.assertTrue(range.includeLower()) self.assertTrue(range.includeUpper()) range = QgsDoubleRange(-1.0, 3.0, False, False) self.assertEqual(range.lower(), -1) self.assertEqual(range.upper(), 3) self.assertFalse(range.includeLower()) self.assertFalse(range.includeUpper())
def testIdentify(self): pcl = QgsPointCloudLayer( os.path.join(unitTestDataPath(), 'point_clouds', 'ept', 'lone-star-laszip', 'ept.json'), 'test', 'ept') self.assertTrue(pcl.isValid()) pcl.elevationProperties().setMaximumScreenError(30) pcl.elevationProperties().setMaximumScreenErrorUnit( QgsUnitTypes.RenderMillimeters) curve = QgsLineString() curve.fromWkt( 'LineString (515387.94696552358800545 4918366.65919817332178354, 515389.15378401038469747 4918366.63842081092298031)' ) req = QgsProfileRequest(curve) req.setCrs(pcl.crs()) req.setTolerance(0.05) context = QgsProfileGenerationContext() context.setMapUnitsPerDistancePixel(0.50) generator = pcl.createProfileGenerator(req) generator.generateProfile(context) r = generator.takeResults() # try identifying some points context = QgsProfileIdentifyContext() context.maximumPointDistanceDelta = 0 context.maximumPointElevationDelta = 0 res = r.identify(QgsProfilePoint(0.27, 2335), context) self.assertFalse(res) context.maximumPointDistanceDelta = 1 context.maximumPointElevationDelta = 1 res = r.identify(QgsProfilePoint(0.27, 2335), context) self.assertEqual(len(res), 1) self.assertEqual(res[0].layer(), pcl) self.assertCountEqual(res[0].results(), [{ 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1612, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.2245, 'Y': 4918366.61, 'Z': 2335.04575 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 199, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.60825, 'Y': 4918366.628, 'Z': 2334.60175 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1678, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.27575, 'Y': 4918366.6325, 'Z': 2334.728 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1605, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.25025, 'Y': 4918366.62825, 'Z': 2334.7095 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1633, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.28575, 'Y': 4918366.66725, 'Z': 2334.7065 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1547, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.238, 'Y': 4918366.6555, 'Z': 2335.0755 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1603, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.26675, 'Y': 4918366.685, 'Z': 2334.69125 }]) context.maximumPointDistanceDelta = 0 context.maximumPointElevationDelta = 0 res = r.identify(QgsDoubleRange(0.2, 0.3), QgsDoubleRange(2330, 2360), context) self.assertEqual(len(res), 1) self.assertEqual(res[0].layer(), pcl) self.assertCountEqual(res[0].results(), [{ 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 565, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.21275, 'Y': 4918366.65675, 'Z': 2332.19075 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1357, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.17375, 'Y': 4918366.679, 'Z': 2332.56025 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1612, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.2245, 'Y': 4918366.61, 'Z': 2335.04575 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1452, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.1985, 'Y': 4918366.61025, 'Z': 2332.38325 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 501, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.2145, 'Y': 4918366.66275, 'Z': 2332.16675 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1197, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.22125, 'Y': 4918366.68675, 'Z': 2332.2715 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 202, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.16825, 'Y': 4918366.6625, 'Z': 2332.73325 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 922, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.165, 'Y': 4918366.65025, 'Z': 2332.6565 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 955, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.1715, 'Y': 4918366.673, 'Z': 2332.6835 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1195, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.1785, 'Y': 4918366.6955, 'Z': 2332.6125 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1432, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.15825, 'Y': 4918366.62575, 'Z': 2332.501 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1413, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.1615, 'Y': 4918366.63675, 'Z': 2332.453 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1547, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.238, 'Y': 4918366.6555, 'Z': 2335.0755 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1259, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.20925, 'Y': 4918366.646, 'Z': 2332.29025 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1369, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.1895, 'Y': 4918366.662, 'Z': 2332.38325 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1394, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.2015, 'Y': 4918366.703, 'Z': 2332.36625 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 688, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.166, 'Y': 4918366.654, 'Z': 2332.7065 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1399, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.17225, 'Y': 4918366.60575, 'Z': 2332.57475 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1024, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.17475, 'Y': 4918366.683, 'Z': 2332.636 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1274, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.1585, 'Y': 4918366.62625, 'Z': 2332.5265 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1443, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.15875, 'Y': 4918366.62725, 'Z': 2332.4765 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1332, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.18, 'Y': 4918366.69875, 'Z': 2332.43775 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1295, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.1725, 'Y': 4918366.67475, 'Z': 2332.5855 }])
def testIdentify(self): pcl = QgsPointCloudLayer( os.path.join(unitTestDataPath(), 'point_clouds', 'ept', 'lone-star-laszip', 'ept.json'), 'test', 'ept') self.assertTrue(pcl.isValid()) pcl.elevationProperties().setMaximumScreenError(30) pcl.elevationProperties().setMaximumScreenErrorUnit( QgsUnitTypes.RenderMillimeters) curve = QgsLineString() curve.fromWkt( 'LineString (515387.94696552358800545 4918366.65919817332178354, 515389.15378401038469747 4918366.63842081092298031)' ) req = QgsProfileRequest(curve) req.setCrs(pcl.crs()) req.setTolerance(0.05) context = QgsProfileGenerationContext() context.setMapUnitsPerDistancePixel(0.50) generator = pcl.createProfileGenerator(req) generator.generateProfile(context) r = generator.takeResults() # try identifying some points context = QgsProfileIdentifyContext() context.maximumPointDistanceDelta = 0 context.maximumPointElevationDelta = 0 res = r.identify(QgsProfilePoint(0.27, 2335), context) self.assertFalse(res) context.maximumPointDistanceDelta = 1 context.maximumPointElevationDelta = 1 res = r.identify(QgsProfilePoint(0.27, 2335), context) self.assertEqual(len(res), 1) self.assertEqual(res[0].layer(), pcl) self.assertEqual(res[0].results(), [{ 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1612, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.2245, 'Y': 4918366.61, 'Z': 2335.04575 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 199, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.60825, 'Y': 4918366.628, 'Z': 2334.60175 }]) context.maximumPointDistanceDelta = 0 context.maximumPointElevationDelta = 0 res = r.identify(QgsDoubleRange(0.2, 0.3), QgsDoubleRange(2330, 2360), context) self.assertEqual(len(res), 1) self.assertEqual(res[0].layer(), pcl) self.assertCountEqual(res[0].results(), [{ 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 565, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.21275, 'Y': 4918366.65675, 'Z': 2332.19075 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1357, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.17375, 'Y': 4918366.679, 'Z': 2332.56025 }, { 'Classification': 0, 'EdgeOfFlightLine': 0, 'GpsTime': 0.0, 'Intensity': 1612, 'NumberOfReturns': 1, 'OriginId': 3, 'PointSourceId': 0, 'ReturnNumber': 1, 'ScanAngleRank': 0.0, 'ScanDirectionFlag': 1, 'UserData': 0, 'X': 515388.2245, 'Y': 4918366.61, 'Z': 2335.04575 }])
def testProfileGeneration(self): pcl = QgsPointCloudLayer( os.path.join(unitTestDataPath(), 'point_clouds', 'ept', 'lone-star-laszip', 'ept.json'), 'test', 'ept') self.assertTrue(pcl.isValid()) pcl.elevationProperties().setMaximumScreenError(30) pcl.elevationProperties().setMaximumScreenErrorUnit( QgsUnitTypes.RenderMillimeters) curve = QgsLineString() curve.fromWkt( 'LineString (515387.94696552358800545 4918366.65919817332178354, 515389.15378401038469747 4918366.63842081092298031)' ) req = QgsProfileRequest(curve) req.setCrs(pcl.crs()) # zero tolerance => no points generator = pcl.createProfileGenerator(req) self.assertTrue(generator.generateProfile()) results = generator.takeResults() self.assertFalse(results.distanceToHeightMap()) req.setTolerance(0.05) generator = pcl.createProfileGenerator(req) context = QgsProfileGenerationContext() context.setMapUnitsPerDistancePixel(0.50) self.assertTrue(generator.generateProfile(context)) results = generator.takeResults() self.assertEqual( self.round_dict(results.distanceToHeightMap(), 1), { 0.0: 2325.2, 0.2: 2332.6, 0.3: 2325.1, 0.6: 2331.4, 0.7: 2330.5, 0.9: 2332.7, 1.0: 2325.3, 1.1: 2325.6 }) print([g.asWkt(1) for g in results.asGeometries()]) self.assertCountEqual([g.asWkt(1) for g in results.asGeometries()], [ 'PointZ (515389.1 4918366.7 2326.1)', 'PointZ (515389.1 4918366.6 2325.6)', 'PointZ (515389 4918366.6 2325.3)', 'PointZ (515388.2 4918366.6 2325.2)', 'PointZ (515388.3 4918366.7 2325.1)', 'PointZ (515387.9 4918366.7 2325.2)', 'PointZ (515388.7 4918366.6 2330.5)', 'PointZ (515388.6 4918366.6 2331.2)', 'PointZ (515388.9 4918366.6 2332.7)', 'PointZ (515388.9 4918366.7 2332.7)', 'PointZ (515388.6 4918366.6 2331.4)', 'PointZ (515388.2 4918366.7 2332.2)', 'PointZ (515388.2 4918366.7 2332.6)', 'PointZ (515388.2 4918366.6 2335)', 'PointZ (515388.6 4918366.6 2334.6)' ]) self.assertAlmostEqual(results.zRange().lower(), 2325.1325, 2) self.assertAlmostEqual(results.zRange().upper(), 2335.04575, 2) # ensure maximum error is considered context.setMapUnitsPerDistancePixel(0.0001) self.assertTrue(generator.generateProfile(context)) results = generator.takeResults() self.assertEqual( self.round_dict(results.distanceToHeightMap(), 2), { 0.0: 2325.17, 0.01: 2325.14, 0.02: 2325.18, 0.03: 2325.14, 0.08: 2325.16, 0.11: 2325.16, 0.12: 2325.14, 0.14: 2325.16, 0.15: 2325.14, 0.18: 2325.15, 0.19: 2325.15, 0.21: 2332.45, 0.22: 2332.68, 0.23: 2332.44, 0.24: 2332.38, 0.25: 2332.37, 0.26: 2325.16, 0.27: 2332.27, 0.28: 2335.05, 0.29: 2335.08, 0.3: 2334.71, 0.31: 2325.13, 0.32: 2325.14, 0.33: 2325.14, 0.34: 2325.13, 0.36: 2325.14, 0.39: 2325.14, 0.41: 2325.13, 0.42: 2325.14, 0.44: 2325.14, 0.46: 2325.14, 0.49: 2325.14, 0.53: 2325.14, 0.56: 2325.16, 0.57: 2325.16, 0.61: 2325.17, 0.62: 2331.38, 0.63: 2330.44, 0.64: 2331.31, 0.65: 2331.41, 0.66: 2331.33, 0.67: 2331.13, 0.68: 2331.14, 0.69: 2331.01, 0.7: 2331.0, 0.71: 2330.52, 0.72: 2330.61, 0.92: 2332.72, 1.0: 2325.29, 1.01: 2325.25, 1.02: 2325.27, 1.03: 2325.39, 1.04: 2325.36, 1.05: 2325.24, 1.07: 2325.41, 1.08: 2325.38, 1.09: 2325.23, 1.1: 2325.21, 1.11: 2325.3, 1.12: 2325.28, 1.13: 2325.24, 1.15: 2326.11, 1.16: 2325.22, 1.17: 2325.82, 1.18: 2325.49, 1.19: 2325.55, 1.2: 2325.58, 1.21: 2325.62 }) # ensure distance/elevation ranges are respected context.setDistanceRange(QgsDoubleRange(0.3, 0.7)) self.assertTrue(generator.generateProfile(context)) results = generator.takeResults() self.assertEqual( self.round_dict(results.distanceToHeightMap(), 2), { 0.3: 2334.71, 0.31: 2325.13, 0.32: 2325.14, 0.33: 2325.14, 0.34: 2325.13, 0.36: 2325.14, 0.39: 2325.14, 0.41: 2325.13, 0.42: 2325.14, 0.44: 2325.14, 0.46: 2325.14, 0.49: 2325.14, 0.53: 2325.14, 0.56: 2325.16, 0.57: 2325.16, 0.61: 2325.17, 0.62: 2331.38, 0.63: 2330.44, 0.64: 2331.31, 0.65: 2331.41, 0.66: 2331.33, 0.67: 2331.13, 0.68: 2331.14, 0.69: 2331.01, 0.7: 2330.97 }) context.setElevationRange(QgsDoubleRange(2325, 2326)) self.assertTrue(generator.generateProfile(context)) results = generator.takeResults() self.assertEqual( self.round_dict(results.distanceToHeightMap(), 2), { 0.31: 2325.13, 0.32: 2325.14, 0.33: 2325.14, 0.34: 2325.13, 0.36: 2325.14, 0.39: 2325.14, 0.41: 2325.13, 0.42: 2325.14, 0.44: 2325.14, 0.46: 2325.14, 0.49: 2325.14, 0.53: 2325.14, 0.56: 2325.16, 0.57: 2325.16, 0.61: 2325.17, 0.64: 2325.18, 0.68: 2325.19 })
def testIsInfinite(self): range = QgsDoubleRange() self.assertTrue(range.isInfinite()) range2 = QgsDoubleRange(range.lower(), 5) self.assertFalse(range2.isInfinite()) range2 = QgsDoubleRange(5, range.upper()) self.assertFalse(range2.isInfinite())