• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python utilities.unitTestDataPath函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中utilities.unitTestDataPath函数的典型用法代码示例。如果您正苦于以下问题:Python unitTestDataPath函数的具体用法?Python unitTestDataPath怎么用?Python unitTestDataPath使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了unitTestDataPath函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: test_zip_input_file_not_exist

    def test_zip_input_file_not_exist(self):
        f0 = os.path.join(unitTestDataPath(), 'multipoint.shp')
        f1 = os.path.join(unitTestDataPath(), 'fake.shp')
        f2 = os.path.join(unitTestDataPath(), 'joins.qgs')

        rc = QgsZipUtils.zip(tmpPath(), [f0, f1, f2])
        self.assertFalse(rc)
开发者ID:manisandro,项目名称:QGIS,代码行数:7,代码来源:test_qgsziputils.py


示例2: testEmbedding

    def testEmbedding(self):
        """Test embedding large SVGs """
        w = QgsImageSourceLineEdit()
        spy = QSignalSpy(w.sourceChanged)

        w.setSource('source')
        self.assertEqual(w.source(), 'source')
        self.assertEqual(len(spy), 1)
        self.assertEqual(spy[0][0], 'source')

        b64 = 'base64:' + ''.join(['x'] * 1000000)
        w.setSource(b64)
        self.assertEqual(w.source(), b64)
        self.assertEqual(len(spy), 2)
        self.assertEqual(spy[1][0], b64)

        w.setSource(os.path.join(unitTestDataPath(), 'landsat.tif'))
        self.assertEqual(w.source(), os.path.join(unitTestDataPath(), 'landsat.tif'))
        self.assertEqual(len(spy), 3)
        self.assertEqual(spy[2][0], os.path.join(unitTestDataPath(), 'landsat.tif'))

        w.setSource(b64)
        self.assertEqual(w.source(), b64)
        self.assertEqual(len(spy), 4)
        self.assertEqual(spy[3][0], b64)

        w.setSource('')
        self.assertEqual(w.source(), '')
        self.assertEqual(len(spy), 5)
        self.assertEqual(spy[4][0], '')
开发者ID:manisandro,项目名称:QGIS,代码行数:30,代码来源:test_qgsimagesourcelineedit.py


示例3: test_zip_file_empty

    def test_zip_file_empty(self):
        f0 = os.path.join(unitTestDataPath(), 'multipoint.shp')
        f1 = os.path.join(unitTestDataPath(), 'lines.shp')
        f2 = os.path.join(unitTestDataPath(), 'joins.qgs')

        rc = QgsZipUtils.zip("", [f0, f1, f2])
        self.assertFalse(rc)
开发者ID:manisandro,项目名称:QGIS,代码行数:7,代码来源:test_qgsziputils.py


示例4: setUpClass

    def setUpClass(cls):
        """Run before all tests:
        Creates an auth configuration"""
        cls.port = QGIS_SERVER_ENDPOINT_PORT
        # Clean env just to be sure
        env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
        for ev in env_vars:
            try:
                del os.environ[ev]
            except KeyError:
                pass
        cls.testdata_path = unitTestDataPath('qgis_server')
        cls.certsdata_path = os.path.join(unitTestDataPath('auth_system'), 'certs_keys')
        cls.project_path = os.path.join(cls.testdata_path, "test_project.qgs")
        # cls.hostname = 'localhost'
        cls.protocol = 'https'
        cls.hostname = '127.0.0.1'

        cls.setUpAuth()

        server_path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                   'qgis_wrapped_server.py')
        cls.server = subprocess.Popen([sys.executable, server_path],
                                      env=os.environ, stdout=subprocess.PIPE)
        line = cls.server.stdout.readline()
        cls.port = int(re.findall(b':(\d+)', line)[0])
        assert cls.port != 0
        # Wait for the server process to start
        assert waitServer('%s://%s:%s' % (cls.protocol, cls.hostname, cls.port)), "Server is not responding! %s://%s:%s" % (cls.protocol, cls.hostname, cls.port)
开发者ID:dmarteau,项目名称:QGIS,代码行数:29,代码来源:test_authmanager_pki_ows.py


示例5: test_zip_ok

    def test_zip_ok(self):
        f0 = os.path.join(unitTestDataPath(), 'multipoint.shp')
        f1 = os.path.join(unitTestDataPath(), 'lines.shp')
        f2 = os.path.join(unitTestDataPath(), 'joins.qgs')

        rc = QgsZipUtils.zip(tmpPath(), [f0, f1, f2])
        self.assertTrue(rc)
开发者ID:manisandro,项目名称:QGIS,代码行数:7,代码来源:test_qgsziputils.py


示例6: setUpClass

 def setUpClass(cls):
     """Run before all tests"""
     cls.port = QGIS_SERVER_WFST_DEFAULT_PORT
     cls.testdata_path = unitTestDataPath('wfs_transactional') + '/'
     # Create tmp folder
     cls.temp_path = tempfile.mkdtemp()
     cls.testdata_path = cls.temp_path + '/' + 'wfs_transactional' + '/'
     copytree(unitTestDataPath('wfs_transactional') + '/',
              cls.temp_path + '/' + 'wfs_transactional')
     cls.project_path = cls.temp_path + '/' + 'wfs_transactional' + '/' + \
         'wfs_transactional.qgs'
     assert os.path.exists(cls.project_path), "Project not found: %s" % \
         cls.project_path
     # Clean env just to be sure
     env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
     for ev in env_vars:
         try:
             del os.environ[ev]
         except KeyError:
             pass
     # Clear all test layers
     for ln in ['test_point', 'test_polygon', 'test_linestring']:
         cls._clearLayer(ln)
     os.environ['QGIS_SERVER_DEFAULT_PORT'] = str(cls.port)
     server_path = os.path.dirname(os.path.realpath(__file__)) + \
         '/qgis_wrapped_server.py'
     cls.server = subprocess.Popen(['python', server_path],
                                   env=os.environ)
     sleep(2)
开发者ID:AM7000000,项目名称:QGIS,代码行数:29,代码来源:test_qgsserver_wfst.py


示例7: setUp

    def setUp(self):
        """Create the server instance"""
        self.testdata_path = unitTestDataPath('qgis_server') + '/'

        d = unitTestDataPath('qgis_server_accesscontrol') + '/'
        self.projectPath = os.path.join(d, "project.qgs")

        # Clean env just to be sure
        env_vars = ['QUERY_STRING', 'QGIS_PROJECT_FILE']
        for ev in env_vars:
            try:
                del os.environ[ev]
            except KeyError:
                pass
        self.server = QgsServer()
开发者ID:dmarteau,项目名称:QGIS,代码行数:15,代码来源:test_qgsserver_modules.py


示例8: test_zip_file_yet_exist

    def test_zip_file_yet_exist(self):
        zip = QTemporaryFile()
        zip.open()
        zip.close()
        os.remove(zip.fileName())

        f0 = os.path.join(unitTestDataPath(), 'multipoint.shp')
        f1 = os.path.join(unitTestDataPath(), 'lines.shp')
        f2 = os.path.join(unitTestDataPath(), 'joins.qgs')

        rc = QgsZipUtils.zip(zip.fileName(), [f0, f1, f2])
        self.assertTrue(rc)

        rc = QgsZipUtils.zip(zip.fileName(), [f0, f1, f2])
        self.assertFalse(rc)
开发者ID:manisandro,项目名称:QGIS,代码行数:15,代码来源:test_qgsziputils.py


示例9: test_zip_unzip_ok

    def test_zip_unzip_ok(self):
        zip = tmpPath()

        f0 = os.path.join(unitTestDataPath(), 'multipoint.shp')
        f1 = os.path.join(unitTestDataPath(), 'lines.shp')
        f2 = os.path.join(unitTestDataPath(), 'joins.qgs')

        rc = QgsZipUtils.zip(zip, [f0, f1, f2])
        self.assertTrue(rc)

        outDir = QTemporaryDir()
        rc, files = QgsZipUtils.unzip(zip, outDir.path())

        self.assertTrue(rc)
        self.assertEqual(len(files), 3)
开发者ID:manisandro,项目名称:QGIS,代码行数:15,代码来源:test_qgsziputils.py


示例10: testOneBandRaster

    def testOneBandRaster(self):
        path = os.path.join(unitTestDataPath('raster'),
                            'band1_float32_noct_epsg4326.tif')
        info = QFileInfo(path)
        base_name = info.baseName()
        layer = QgsRasterLayer(path, base_name)
        self.assertTrue(layer)

        combo = QgsRasterBandComboBox()
        combo.setLayer(layer)
        self.assertEqual(combo.layer(), layer)
        self.assertEqual(combo.currentBand(), 1)
        self.assertEqual(combo.count(), 1)

        combo.setShowNotSetOption(True)
        self.assertEqual(combo.currentBand(), 1)
        self.assertEqual(combo.count(), 2)
        combo.setBand(-1)
        self.assertEqual(combo.currentBand(), -1)
        combo.setBand(1)
        self.assertEqual(combo.currentBand(), 1)

        combo.setShowNotSetOption(False)
        self.assertEqual(combo.currentBand(), 1)
        self.assertEqual(combo.count(), 1)
开发者ID:nirvn,项目名称:QGIS,代码行数:25,代码来源:test_qgsrasterbandcombobox.py


示例11: testQgsSVGFillSymbolLayer

    def testQgsSVGFillSymbolLayer(self):
        """
        Create a new style from a .sld file and match test
        """
        mTestName = 'QgsSVGFillSymbolLayer'
        mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))

        mDoc = QDomDocument(mTestName)
        mFile = QFile(mFilePath)
        mFile.open(QIODevice.ReadOnly)
        mDoc.setContent(mFile, True)
        mFile.close()
        mSymbolLayer = QgsSVGFillSymbolLayer.createFromSld(
            mDoc.elementsByTagName('PolygonSymbolizer').item(0).toElement())

        mExpectedValue = type(QgsSVGFillSymbolLayer(""))
        mValue = type(mSymbolLayer)
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 'accommodation_camping.svg'
        mValue = os.path.basename(mSymbolLayer.svgFilePath())
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 6
        mValue = mSymbolLayer.patternWidth()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage
开发者ID:mj10777,项目名称:QGIS,代码行数:29,代码来源:test_qgssymbollayer.py


示例12: testQgsSvgMarkerSymbolLayer

    def testQgsSvgMarkerSymbolLayer(self):
        """
        Create a new style from a .sld file and match test
        """
        mTestName = 'QgsSvgMarkerSymbolLayer'
        mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))

        mDoc = QDomDocument(mTestName)
        mFile = QFile(mFilePath)
        mFile.open(QIODevice.ReadOnly)
        mDoc.setContent(mFile, True)
        mFile.close()
        mSymbolLayer = QgsSvgMarkerSymbolLayer.createFromSld(mDoc.elementsByTagName('PointSymbolizer').item(0).toElement())

        mExpectedValue = type(QgsSvgMarkerSymbolLayer(""))
        mValue = type(mSymbolLayer)
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 'skull.svg'
        mValue = os.path.basename(mSymbolLayer.path())
        print(("VALUE", mSymbolLayer.path()))
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 12
        mValue = mSymbolLayer.size()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = 45
        mValue = mSymbolLayer.angle()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue, mValue)
        assert mExpectedValue == mValue, mMessage
开发者ID:mj10777,项目名称:QGIS,代码行数:34,代码来源:test_qgssymbollayer.py


示例13: testSelectByIds

    def testSelectByIds(self):
        """ Test selecting by ID"""
        layer = QgsVectorLayer(os.path.join(unitTestDataPath(), 'points.shp'), 'Points', 'ogr')

        # SetSelection
        layer.selectByIds([1, 3, 5, 7], QgsVectorLayer.SetSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([1, 3, 5, 7]))
        # check that existing selection is cleared
        layer.selectByIds([2, 4, 6], QgsVectorLayer.SetSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 4, 6]))

        # AddToSelection
        layer.selectByIds([3, 5], QgsVectorLayer.AddToSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 3, 4, 5, 6]))
        layer.selectByIds([1], QgsVectorLayer.AddToSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([1, 2, 3, 4, 5, 6]))

        # IntersectSelection
        layer.selectByIds([1, 3, 5, 6], QgsVectorLayer.IntersectSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([1, 3, 5, 6]))
        layer.selectByIds([1, 2, 5, 6], QgsVectorLayer.IntersectSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([1, 5, 6]))

        # RemoveFromSelection
        layer.selectByIds([2, 6, 7], QgsVectorLayer.RemoveFromSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([1, 5]))
        layer.selectByIds([1, 5], QgsVectorLayer.RemoveFromSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([]))
开发者ID:AM7000000,项目名称:QGIS,代码行数:28,代码来源:test_qgsvectorlayer.py


示例14: testSelectByRect

    def testSelectByRect(self):
        """ Test selecting by rectangle """
        layer = QgsVectorLayer(os.path.join(unitTestDataPath(), 'points.shp'), 'Points', 'ogr')

        # SetSelection
        layer.selectByRect(QgsRectangle(-112, 30, -94, 45), QgsVectorLayer.SetSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 3, 7, 10, 11, 15]))
        # check that existing selection is cleared
        layer.selectByRect(QgsRectangle(-112, 30, -94, 37), QgsVectorLayer.SetSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 3, 10, 15]))
        # SetSelection no matching
        layer.selectByRect(QgsRectangle(112, 30, 115, 45), QgsVectorLayer.SetSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([]))

        # AddToSelection
        layer.selectByRect(QgsRectangle(-112, 30, -94, 37), QgsVectorLayer.AddToSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 3, 10, 15]))
        layer.selectByRect(QgsRectangle(-112, 37, -94, 45), QgsVectorLayer.AddToSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 3, 7, 10, 11, 15]))

        # IntersectSelection
        layer.selectByRect(QgsRectangle(-112, 30, -94, 37), QgsVectorLayer.IntersectSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 3, 10, 15]))
        layer.selectByIds([2, 10, 13])
        layer.selectByRect(QgsRectangle(-112, 30, -94, 37), QgsVectorLayer.IntersectSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([2, 10]))

        # RemoveFromSelection
        layer.selectByRect(QgsRectangle(-112, 30, -94, 45), QgsVectorLayer.SetSelection)
        layer.selectByRect(QgsRectangle(-112, 30, -94, 37), QgsVectorLayer.RemoveFromSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([7, 11]))
        layer.selectByRect(QgsRectangle(-112, 30, -94, 45), QgsVectorLayer.RemoveFromSelection)
        self.assertEqual(set(layer.selectedFeaturesIds()), set([]))
开发者ID:AM7000000,项目名称:QGIS,代码行数:33,代码来源:test_qgsvectorlayer.py


示例15: testSetDataSource

    def testSetDataSource(self):
        """Test change data source"""

        temp_dir = QTemporaryDir()
        options = QgsDataProvider.ProviderOptions()
        myPath = os.path.join(unitTestDataPath('raster'),
                              'band1_float32_noct_epsg4326.tif')
        myFileInfo = QFileInfo(myPath)
        myBaseName = myFileInfo.baseName()
        layer = QgsRasterLayer(myPath, myBaseName)
        renderer = QgsSingleBandGrayRenderer(layer.dataProvider(), 2)

        image = layer.previewAsImage(QSize(400, 400))
        self.assertFalse(image.isNull())
        self.assertTrue(image.save(os.path.join(temp_dir.path(), 'expected.png'), "PNG"))

        layer.setDataSource(myPath.replace('4326.tif', '4326-BAD_SOURCE.tif'), 'bad_layer', 'gdal', options)
        self.assertFalse(layer.isValid())
        image = layer.previewAsImage(QSize(400, 400))
        self.assertTrue(image.isNull())

        layer.setDataSource(myPath.replace('4326-BAD_SOURCE.tif', '4326.tif'), 'bad_layer', 'gdal', options)
        self.assertTrue(layer.isValid())
        image = layer.previewAsImage(QSize(400, 400))
        self.assertFalse(image.isNull())
        self.assertTrue(image.save(os.path.join(temp_dir.path(), 'actual.png'), "PNG"))

        self.assertTrue(filecmp.cmp(os.path.join(temp_dir.path(), 'actual.png'), os.path.join(temp_dir.path(), 'expected.png')), False)
开发者ID:m-kuhn,项目名称:QGIS,代码行数:28,代码来源:test_qgsrasterlayer.py


示例16: testQgsCentroidFillSymbolLayerV2

    def testQgsCentroidFillSymbolLayerV2(self):
        '''
        Create a new style from a .sld file and match test
        '''
        mTestName = 'QgsCentroidFillSymbolLayerV2'
        mFilePath = QDir.toNativeSeparators('%s/symbol_layer/%s.sld' % (unitTestDataPath(), mTestName))

        mDoc = QDomDocument(mTestName)
        mFile = QFile(mFilePath)
        mFile.open(QIODevice.ReadOnly)
        mDoc.setContent(mFile,True)
        mFile.close()
        mSymbolLayer = QgsCentroidFillSymbolLayerV2.createFromSld(
            mDoc.elementsByTagName('PointSymbolizer').item(0).toElement())

        mExpectedValue = type(QgsCentroidFillSymbolLayerV2())
        mValue = type(mSymbolLayer)
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue,mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = u'regular_star'
        mValue = mSymbolLayer.subSymbol().symbolLayer(0).name()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue,mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = u'#55aaff'
        mValue = mSymbolLayer.subSymbol().symbolLayer(0).color().name()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue,mValue)
        assert mExpectedValue == mValue, mMessage

        mExpectedValue = u'#00ff00'
        mValue = mSymbolLayer.subSymbol().symbolLayer(0).borderColor().name()
        mMessage = 'Expected "%s" got "%s"' % (mExpectedValue,mValue)
        assert mExpectedValue == mValue, mMessage
开发者ID:ChowZenki,项目名称:QGIS,代码行数:34,代码来源:test_qgssymbollayerv2.py


示例17: testFormUi

    def testFormUi(self):
        layer = self.createLayer()
        config = layer.editFormConfig()

        config.setLayout(QgsEditFormConfig.GeneratedLayout)
        self.assertEqual(config.layout(), QgsEditFormConfig.GeneratedLayout)

        uiLocal = os.path.join(
            unitTestDataPath(), '/qgis_local_server/layer_attribute_form.ui')
        config.setUiForm(uiLocal)
        self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout)

        config.setLayout(QgsEditFormConfig.GeneratedLayout)
        self.assertEqual(config.layout(), QgsEditFormConfig.GeneratedLayout)

        uiUrl = 'http://localhost:' + \
            str(self.port) + '/qgis_local_server/layer_attribute_form.ui'
        config.setUiForm(uiUrl)
        self.assertEqual(config.layout(), QgsEditFormConfig.UiFileLayout)
        content = QgsApplication.networkContentFetcherRegistry().fetch(uiUrl)
        self.assertTrue(content is not None)
        while True:
            if content.status() in (QgsFetchedContent.Finished, QgsFetchedContent.Failed):
                break
            app.processEvents()
        self.assertEqual(content.status(), QgsFetchedContent.Finished)
开发者ID:manisandro,项目名称:QGIS,代码行数:26,代码来源:test_qgseditformconfig.py


示例18: test_FeatureCount

 def test_FeatureCount(self):
     myPath = os.path.join(unitTestDataPath(), 'lines.shp')
     myLayer = QgsVectorLayer(myPath, 'Lines', 'ogr')
     myCount = myLayer.featureCount()
     myExpectedCount = 6
     myMessage = '\nExpected: %s\nGot: %s' % (myCount, myExpectedCount)
     assert myCount == myExpectedCount, myMessage
开发者ID:ACorradini,项目名称:QGIS,代码行数:7,代码来源:test_qgsvectorlayer.py


示例19: testSimplifyIssue4189

    def testSimplifyIssue4189(self):
        """Test we can simplify a complex geometry.

        Note: there is a ticket related to this issue here:
        http://hub.qgis.org/issues/4189

        Backstory: Ole Nielson pointed out an issue to me
        (Tim Sutton) where simplify ftools was dropping
        features. This test replicates that issues.

        Interestingly we could replicate the issue in PostGIS too:
         - doing straight simplify returned no feature
         - transforming to UTM49, then simplify with e.g. 200 threshold is ok
         - as above with 500 threshold drops the feature

         pgsql2shp -f /tmp/dissolve500.shp gis 'select *,
           transform(simplify(transform(geom,32649),500), 4326) as
           simplegeom from dissolve;'
        """
        myWKTFile = file(os.path.join(unitTestDataPath('wkt'),
                                       'simplify_error.wkt'), 'rt')
        myWKT = myWKTFile.readline()
        myWKTFile.close()
        print myWKT
        myGeometry = QgsGeometry().fromWkt(myWKT)
        assert myGeometry is not None
        myStartLength = len(myWKT)
        myTolerance = 0.00001
        mySimpleGeometry = myGeometry.simplify(myTolerance)
        myEndLength = len(mySimpleGeometry.exportToWkt())
        myMessage = 'Before simplify: %i\nAfter simplify: %i\n : Tolerance %e' % (
            myStartLength, myEndLength, myTolerance)
        myMinimumLength = len('POLYGON(())')
        assert myEndLength > myMinimumLength, myMessage
开发者ID:alexgleith,项目名称:Quantum-GIS,代码行数:34,代码来源:test_qgsgeometry.py


示例20: testPalettedColorTableToClassData

    def testPalettedColorTableToClassData(self):
        entries = [QgsColorRampShader.ColorRampItem(5, QColor(255, 0, 0), 'item1'),
                   QgsColorRampShader.ColorRampItem(3, QColor(0, 255, 0), 'item2'),
                   QgsColorRampShader.ColorRampItem(6, QColor(0, 0, 255), 'item3'),
                   ]
        classes = QgsPalettedRasterRenderer.colorTableToClassData(entries)
        self.assertEqual(classes[0].value, 5)
        self.assertEqual(classes[1].value, 3)
        self.assertEqual(classes[2].value, 6)
        self.assertEqual(classes[0].label, 'item1')
        self.assertEqual(classes[1].label, 'item2')
        self.assertEqual(classes[2].label, 'item3')
        self.assertEqual(classes[0].color.name(), '#ff0000')
        self.assertEqual(classes[1].color.name(), '#00ff00')
        self.assertEqual(classes[2].color.name(), '#0000ff')

        # test #13263
        path = os.path.join(unitTestDataPath('raster'),
                            'hub13263.vrt')
        info = QFileInfo(path)
        base_name = info.baseName()
        layer = QgsRasterLayer(path, base_name)
        self.assertTrue(layer.isValid(), 'Raster not loaded: {}'.format(path))
        classes = QgsPalettedRasterRenderer.colorTableToClassData(layer.dataProvider().colorTable(1))
        self.assertEqual(len(classes), 4)
        classes = QgsPalettedRasterRenderer.colorTableToClassData(layer.dataProvider().colorTable(15))
        self.assertEqual(len(classes), 256)
开发者ID:m-kuhn,项目名称:QGIS,代码行数:27,代码来源:test_qgsrasterlayer.py



注:本文中的utilities.unitTestDataPath函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python utilities.valid_string函数代码示例发布时间:2022-05-26
下一篇:
Python utilities.svgSymbolsPath函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap