当前位置: 首页>>代码示例>>Python>>正文


Python QUrl.fromLocalFile方法代码示例

本文整理汇总了Python中PyQt.QtCore.QUrl.fromLocalFile方法的典型用法代码示例。如果您正苦于以下问题:Python QUrl.fromLocalFile方法的具体用法?Python QUrl.fromLocalFile怎么用?Python QUrl.fromLocalFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt.QtCore.QUrl的用法示例。


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

示例1: setUpClass

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
    def setUpClass(cls):
        """Run before all tests"""
        # Create test layer
        srcpath = os.path.join(TEST_DATA_DIR, 'provider')
        cls.basetestfile = os.path.join(srcpath, 'delimited_wkt.csv')

        url = QUrl.fromLocalFile(cls.basetestfile)
        url.addQueryItem("crs", "epsg:4326")
        url.addQueryItem("type", "csv")
        url.addQueryItem("wktField", "wkt")
        url.addQueryItem("spatialIndex", "no")
        url.addQueryItem("subsetIndex", "no")
        url.addQueryItem("watchFile", "no")

        cls.vl = QgsVectorLayer(url.toString(), u'test', u'delimitedtext')
        assert cls.vl.isValid(), "{} is invalid".format(cls.basetestfile)
        cls.provider = cls.vl.dataProvider()

        cls.basetestpolyfile = os.path.join(srcpath, 'delimited_wkt_poly.csv')

        url = QUrl.fromLocalFile(cls.basetestpolyfile)
        url.addQueryItem("crs", "epsg:4326")
        url.addQueryItem("type", "csv")
        url.addQueryItem("wktField", "wkt")
        url.addQueryItem("spatialIndex", "no")
        url.addQueryItem("subsetIndex", "no")
        url.addQueryItem("watchFile", "no")

        cls.vl_poly = QgsVectorLayer(url.toString(), u'test_polygon', u'delimitedtext')
        assert cls.vl_poly.isValid(), "{} is invalid".format(cls.basetestpolyfile)
        cls.poly_provider = cls.vl_poly.dataProvider()
开发者ID:Clayton-Davis,项目名称:QGIS,代码行数:33,代码来源:test_qgsdelimitedtextprovider.py

示例2: test_refLayers2

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
    def test_refLayers2(self):
        l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
        self.assertEqual(l1.isValid(), True)
        QgsMapLayerRegistry.instance().addMapLayer(l1)

        # referenced layers cannot be stored !
        tmp = QUrl.fromLocalFile(os.path.join(tempfile.gettempdir(), "t.sqlite")).toString()
        l2 = QgsVectorLayer("%s?layer_ref=%s" % (tmp, l1.id()), "tt", "virtual", False)
        self.assertEqual(l2.isValid(), False)
        self.assertEqual("Cannot store referenced layers" in l2.dataProvider().error().message(), True)
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:12,代码来源:test_provider_virtual.py

示例3: test_source_escaping

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
 def test_source_escaping(self):
     # the source contains ':'
     source = QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no"
     d = QgsVirtualLayerDefinition()
     d.addSource("t", source, "delimitedtext")
     l = QgsVectorLayer(d.toString(), "vtab", "virtual", False)
     self.assertEqual(l.isValid(), True)
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:9,代码来源:test_provider_virtual.py

示例4: onHelp

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
 def onHelp(self):
     helpPath = Utils.getHelpPath()
     if helpPath == '':
         url = QUrl("http://www.gdal.org/" + self.helpFileName)
     else:
         url = QUrl.fromLocalFile(helpPath + '/' + self.helpFileName)
     QDesktopServices.openUrl(url)
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:9,代码来源:dialogBase.py

示例5: help

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
    def help(self):
        localDoc = None
        html = self.grass7Name + '.html'
        if system.isWindows():
            # For MS-Windows, use the configured GRASS7 path
            localPath = os.path.join(Grass7Utils.grassPath(), 'docs/html', html)
            if os.path.exists(localPath):
                localDoc = os.path.abspath(localPath)
        elif system.isMac():
            # For MacOSX official package
            localPath = os.path.join('/Applications/GRASS-7.0.app/Contents/MacOS/docs/html', html)
            if os.path.exists(localPath):
                localDoc = os.path.abspath(localPath)
        else:
            # For GNU/Linux distributions
            searchPaths = ['/usr/share/doc/grass-doc/html', '/opt/grass/docs/html',
                           '/usr/share/doc/grass/docs/html']
            for path in searchPaths:
                localPath = os.path.join(path, html)
                if os.path.exists(localPath):
                    localDoc = os.path.abspath(localPath)

        # Found the local documentation
        if localDoc:
            localDoc = QUrl.fromLocalFile(localDoc).toString()
            return False, localDoc

        # Return the URL if local doc is not found
        return False, 'http://grass.osgeo.org/grass70/manuals/' + self.grass7Name + '.html'
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:31,代码来源:Grass7Algorithm.py

示例6: openScriptFileExtEditor

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
 def openScriptFileExtEditor(self):
     tabWidget = self.tabEditorWidget.currentWidget()
     path = tabWidget.path
     import subprocess
     try:
         subprocess.Popen([os.environ['EDITOR'], path])
     except KeyError:
         QDesktopServices.openUrl(QUrl.fromLocalFile(path))
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:10,代码来源:console.py

示例7: test_CsvNoGeometry

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
    def test_CsvNoGeometry(self):
        l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
        self.assertEqual(l1.isValid(), True)
        QgsMapLayerRegistry.instance().addMapLayer(l1)

        l2 = QgsVectorLayer("?layer_ref=" + l1.id(), "vtab", "virtual", False)
        self.assertEqual(l2.isValid(), True)

        QgsMapLayerRegistry.instance().removeMapLayer(l1.id())
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:11,代码来源:test_provider_virtual.py

示例8: test_sql

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
    def test_sql(self):
        l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
        self.assertEqual(l1.isValid(), True)
        QgsMapLayerRegistry.instance().addMapLayer(l1)

        l3 = QgsVectorLayer("?query=SELECT * FROM test", "tt", "virtual")

        self.assertEqual(l3.isValid(), True)
        s = sum(f.id() for f in l3.getFeatures())
        self.assertEqual(s, 15)
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:12,代码来源:test_provider_virtual.py

示例9: test_reopen2

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
    def test_reopen2(self):
        source = QUrl.toPercentEncoding(os.path.join(self.testDataDir, "france_parts.shp"))
        tmp = QUrl.fromLocalFile(os.path.join(tempfile.gettempdir(), "t.sqlite")).toString()
        l = QgsVectorLayer("%s?layer=ogr:%s:vtab&nogeometry" % (tmp, source), "vtab2", "virtual", False)
        self.assertEqual(l.isValid(), True)

        l2 = QgsVectorLayer(tmp, "tt", "virtual", False)
        self.assertEqual(l2.isValid(), True)
        self.assertEqual(l2.dataProvider().geometryType(), 100)
        self.assertEqual(l2.dataProvider().featureCount(), 4)
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:12,代码来源:test_provider_virtual.py

示例10: test_DynamicGeometry

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
    def test_DynamicGeometry(self):
        l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/testextpt.txt")).toString() + "?type=csv&delimiter=%7C&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
        self.assertEqual(l1.isValid(), True)
        QgsMapLayerRegistry.instance().addMapLayer(l1)

        query = QUrl.toPercentEncoding("select *,makepoint(x,y) as geom from vtab1")
        l2 = QgsVectorLayer("?layer_ref=%s&query=%s&geometry=geom:point:0&uid=id" % (l1.id(), query), "vtab", "virtual", False)
        self.assertEqual(l2.isValid(), True)

        QgsMapLayerRegistry.instance().removeMapLayer(l1)
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:12,代码来源:test_provider_virtual.py

示例11: test_refLayer

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
    def test_refLayer(self):
        l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
        self.assertEqual(l1.isValid(), True)
        QgsMapLayerRegistry.instance().addMapLayer(l1)

        l2 = QgsVectorLayer("?layer_ref=" + l1.id(), "vtab", "virtual", False)
        self.assertEqual(l2.isValid(), True)

        # now delete the layer
        QgsMapLayerRegistry.instance().removeMapLayer(l1.id())
        # check that it does not crash
        print sum([f.id() for f in l2.getFeatures()])
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:14,代码来源:test_provider_virtual.py

示例12: delimitedTextData

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
    def delimitedTextData(self, testname, filename, requests, verbose, **params):
        # Retrieve the data for a delimited text url
        # Create a layer for the specified file and query parameters
        # and return the data for the layer (fields, data)

        filepath = os.path.join(unitTestDataPath("delimitedtext"), filename)
        url = QUrl.fromLocalFile(filepath)
        if not requests:
            requests = [{}]
        for k in params.keys():
            url.addQueryItem(k, params[k])
        urlstr = url.toString()
        log = []
        with MessageLogger('DelimitedText') as logger:
            if verbose:
                print(testname)
            layer = QgsVectorLayer(urlstr, 'test', 'delimitedtext')
            uri = unicode(layer.dataProvider().dataSourceUri())
            if verbose:
                print(uri)
            basename = os.path.basename(filepath)
            if not basename.startswith('test'):
                basename = 'file'
            uri = re.sub(r'^file\:\/\/[^\?]*', 'file://' + basename, uri)
            fields = []
            fieldTypes = []
            data = {}
            if layer.isValid():
                for nr, r in enumerate(requests):
                    if verbose:
                        print("Processing request", nr + 1, repr(r))
                    if callable(r):
                        r(layer)
                        if verbose:
                            print("Request function executed")
                    if callable(r):
                        continue
                    rfields, rtypes, rdata = self.layerData(layer, r, nr * 1000)
                    if len(rfields) > len(fields):
                        fields = rfields
                        fieldTypes = rtypes
                    data.update(rdata)
                    if not rdata:
                        log.append("Request " + str(nr) + " did not return any data")
                    if verbose:
                        print("Request returned", len(rdata.keys()), "features")
            for msg in logger.messages():
                filelogname = 'temp_file' if 'tmp' in filename.lower() else filename
                msg = re.sub(r'file\s+.*' + re.escape(filename), 'file ' + filelogname, msg)
                msg = msg.replace(filepath, filelogname)
                log.append(msg)
            return dict(fields=fields, fieldTypes=fieldTypes, data=data, log=log, uri=uri, geometryType=layer.geometryType())
开发者ID:MrBenjaminLeb,项目名称:QGIS,代码行数:54,代码来源:test_qgsdelimitedtextprovider.py

示例13: test_refLayers

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
    def test_refLayers(self):
        l1 = QgsVectorLayer(QUrl.fromLocalFile(os.path.join(self.testDataDir, "delimitedtext/test.csv")).toString() + "?type=csv&geomType=none&subsetIndex=no&watchFile=no", "test", "delimitedtext", False)
        self.assertEqual(l1.isValid(), True)
        QgsMapLayerRegistry.instance().addMapLayer(l1)

        # cf qgis bug #12266
        for i in range(10):
            q = QUrl.toPercentEncoding("select * from t" + str(i))
            l2 = QgsVectorLayer("?layer_ref=%s:t%d&query=%s&uid=id" % (l1.id(), i, q), "vtab", "virtual", False)
            QgsMapLayerRegistry.instance().addMapLayer(l2)
            self.assertEqual(l2.isValid(), True)
            s = sum([f.id() for f in l2.dataProvider().getFeatures()])  # NOQA
            self.assertEqual(sum([f.id() for f in l2.getFeatures()]), 21)
            QgsMapLayerRegistry.instance().removeMapLayer(l2.id())
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:16,代码来源:test_provider_virtual.py

示例14: test_reopen4

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
    def test_reopen4(self):
        source = QUrl.toPercentEncoding(os.path.join(self.testDataDir, "france_parts.shp"))
        tmp = QUrl.fromLocalFile(os.path.join(tempfile.gettempdir(), "t.sqlite")).toString()
        query = QUrl.toPercentEncoding("SELECT * FROM vtab")
        l = QgsVectorLayer("%s?layer=ogr:%s:vtab&query=%s&uid=objectid&nogeometry" % (tmp, source, query), "vtab2", "virtual", False)
        self.assertEqual(l.isValid(), True)

        l2 = QgsVectorLayer(tmp, "tt", "virtual", False)
        self.assertEqual(l2.isValid(), True)
        self.assertEqual(l2.dataProvider().geometryType(), 100)
        self.assertEqual(l2.dataProvider().featureCount(), 4)
        sumid = sum([f.id() for f in l2.getFeatures()])
        self.assertEqual(sumid, 10659)
        suma = sum([f.attributes()[1] for f in l2.getFeatures()])
        self.assertEqual(suma, 3064.0)
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:17,代码来源:test_provider_virtual.py

示例15: _get_cursor_columns

# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import fromLocalFile [as 别名]
    def _get_cursor_columns(self, c):
        tf = QTemporaryFile()
        tf.open()
        tmp = tf.fileName()
        tf.close()

        q = QUrl.toPercentEncoding(c.sql)
        p = QgsVectorLayer("%s?query=%s" % (QUrl.fromLocalFile(tmp).toString(), q), "vv", "virtual")
        if not p.isValid():
            return []
        f = [f.name() for f in p.fields()]
        if p.geometryType() != QGis.WKBNoGeometry:
            gn = getQueryGeometryName(tmp)
            if gn:
                f += [gn]
        return f
开发者ID:Antoviscomi,项目名称:QGIS,代码行数:18,代码来源:connector.py


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