本文整理汇总了Python中PyQt.QtCore.QUrl.toPercentEncoding方法的典型用法代码示例。如果您正苦于以下问题:Python QUrl.toPercentEncoding方法的具体用法?Python QUrl.toPercentEncoding怎么用?Python QUrl.toPercentEncoding使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt.QtCore.QUrl
的用法示例。
在下文中一共展示了QUrl.toPercentEncoding方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_rowid
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [as 别名]
def test_rowid(self):
source = QUrl.toPercentEncoding(os.path.join(self.testDataDir, "france_parts.shp"))
query = QUrl.toPercentEncoding("select rowid as uid, * from vtab limit 1 offset 3")
l = QgsVectorLayer("?layer=ogr:%s:vtab&query=%s" % (source, query), "vtab2", "virtual", False)
# the last line must have a fixed rowid (not an autoincrement)
for f in l.getFeatures():
lid = f.attributes()[0]
self.assertEqual(lid, 3)
示例2: test_filter_rect
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [as 别名]
def test_filter_rect(self):
source = QUrl.toPercentEncoding(os.path.join(self.testDataDir, "france_parts.shp"))
query = QUrl.toPercentEncoding("select * from vtab where _search_frame_=BuildMbr(-2.10,49.38,-1.3,49.99,4326)")
l2 = QgsVectorLayer("?layer=ogr:%s:vtab&query=%s&uid=objectid" % (source, query), "vtab2", "virtual", False)
self.assertEqual(l2.isValid(), True)
self.assertEqual(l2.dataProvider().featureCount(), 1)
a = [fit.attributes()[4] for fit in l2.getFeatures()]
self.assertEqual(a, [u"Basse-Normandie"])
示例3: test_sql2
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [as 别名]
def test_sql2(self):
l2 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "france_parts", "ogr", False)
self.assertEqual(l2.isValid(), True)
QgsMapLayerRegistry.instance().addMapLayer(l2)
query = QUrl.toPercentEncoding("SELECT * FROM france_parts")
l4 = QgsVectorLayer("?query=%s" % query, "tt", "virtual")
self.assertEqual(l4.isValid(), True)
self.assertEqual(l4.dataProvider().geometryType(), 3)
self.assertEqual(l4.dataProvider().crs().postgisSrid(), 4326)
n = 0
r = QgsFeatureRequest(QgsRectangle(-1.677, 49.624, -0.816, 49.086))
for f in l4.getFeatures(r):
self.assertEqual(f.geometry() is not None, True)
self.assertEqual(f.attributes()[0], 2661)
n += 1
self.assertEqual(n, 1)
# use uid
query = QUrl.toPercentEncoding("SELECT * FROM france_parts")
l5 = QgsVectorLayer("?query=%s&geometry=geometry:polygon:4326&uid=ObjectId" % query, "tt", "virtual")
self.assertEqual(l5.isValid(), True)
idSum = sum(f.id() for f in l5.getFeatures())
self.assertEqual(idSum, 10659)
r = QgsFeatureRequest(2661)
idSum2 = sum(f.id() for f in l5.getFeatures(r))
self.assertEqual(idSum2, 2661)
r = QgsFeatureRequest()
r.setFilterFids([2661, 2664])
self.assertEqual(sum(f.id() for f in l5.getFeatures(r)), 2661 + 2664)
# test attribute subset
r = QgsFeatureRequest()
r.setFlags(QgsFeatureRequest.SubsetOfAttributes)
r.setSubsetOfAttributes([1])
s = [(f.id(), f.attributes()[1]) for f in l5.getFeatures(r)]
self.assertEqual(sum(map(lambda x: x[0], s)), 10659)
self.assertEqual(sum(map(lambda x: x[1], s)), 3064.0)
# test NoGeometry
# by request flag
r = QgsFeatureRequest()
r.setFlags(QgsFeatureRequest.NoGeometry)
self.assertEqual(all([f.geometry() is None for f in l5.getFeatures(r)]), True)
# test subset
self.assertEqual(l5.dataProvider().featureCount(), 4)
l5.setSubsetString("ObjectId = 2661")
idSum2 = sum(f.id() for f in l5.getFeatures(r))
self.assertEqual(idSum2, 2661)
self.assertEqual(l5.dataProvider().featureCount(), 1)
示例4: test_reopen4
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [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)
示例5: test_sql3b
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [as 别名]
def test_sql3b(self):
query = QUrl.toPercentEncoding("SELECT GeomFromText('POINT(0 0)') as geom")
l4 = QgsVectorLayer("?query=%s&geometry=geom" % query, "tt", "virtual", False)
self.assertEqual(l4.isValid(), True)
self.assertEqual(l4.dataProvider().geometryType(), 1)
# forced geometry type
query = QUrl.toPercentEncoding("SELECT GeomFromText('POINT(0 0)') as geom")
l4 = QgsVectorLayer("?query=%s&geometry=geom:point:0" % query, "tt", "virtual", False)
self.assertEqual(l4.isValid(), True)
self.assertEqual(l4.dataProvider().geometryType(), 1)
query = QUrl.toPercentEncoding("SELECT CastToPoint(GeomFromText('POINT(0 0)')) as geom")
l4 = QgsVectorLayer("?query=%s" % query, "tt", "virtual", False)
self.assertEqual(l4.isValid(), True)
self.assertEqual(l4.dataProvider().geometryType(), 1)
示例6: test_embeddedLayer
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [as 别名]
def test_embeddedLayer(self):
source = QUrl.toPercentEncoding(os.path.join(self.testDataDir, "france_parts.shp"))
l = QgsVectorLayer("?layer=ogr:%s" % source, "vtab", "virtual", False)
self.assertEqual(l.isValid(), True)
l = QgsVectorLayer("?layer=ogr:%s:nn" % source, "vtab", "virtual", False)
self.assertEqual(l.isValid(), True)
示例7: test_sql_field_types
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [as 别名]
def test_sql_field_types(self):
query = QUrl.toPercentEncoding("SELECT 42 as t, 'ok'||'ok' as t2, GeomFromText('') as t3, 3.14*2 as t4")
l4 = QgsVectorLayer("?query=%s" % query, "tt", "virtual", False)
self.assertEqual(l4.isValid(), True)
self.assertEqual(l4.dataProvider().fields().at(0).name(), "t")
self.assertEqual(l4.dataProvider().fields().at(0).type(), QVariant.Int)
self.assertEqual(l4.dataProvider().fields().at(1).name(), "t2")
self.assertEqual(l4.dataProvider().fields().at(1).type(), QVariant.String)
self.assertEqual(l4.dataProvider().fields().at(2).name(), "t3")
self.assertEqual(l4.dataProvider().fields().at(2).type(), QVariant.String)
self.assertEqual(l4.dataProvider().fields().at(3).name(), "t4")
self.assertEqual(l4.dataProvider().fields().at(3).type(), QVariant.Double)
# with type annotations
query = QUrl.toPercentEncoding("SELECT '42.0' as t /*:real*/, 3 as t2/*:text */, GeomFromText('') as t3 /*:multiPoInT:4326 */, 3.14*2 as t4/*:int*/")
l4 = QgsVectorLayer("?query=%s" % query, "tt", "virtual", False)
self.assertEqual(l4.isValid(), True)
self.assertEqual(l4.dataProvider().fields().at(0).name(), "t")
self.assertEqual(l4.dataProvider().fields().at(0).type(), QVariant.Double)
self.assertEqual(l4.dataProvider().fields().at(1).name(), "t2")
self.assertEqual(l4.dataProvider().fields().at(1).type(), QVariant.String)
self.assertEqual(l4.dataProvider().fields().at(2).name(), "t4")
self.assertEqual(l4.dataProvider().fields().at(2).type(), QVariant.Int)
self.assertEqual(l4.dataProvider().geometryType(), 4) # multipoint
# test value types (!= from declared column types)
for f in l4.getFeatures():
self.assertEqual(f.attributes()[0], "42.0")
self.assertEqual(f.attributes()[1], 3)
self.assertEqual(f.attributes()[2], 6.28)
# with type annotations and url options
query = QUrl.toPercentEncoding("SELECT 1 as id /*:int*/, geomfromtext('point(0 0)',4326) as geometry/*:point:4326*/")
l4 = QgsVectorLayer("?query=%s&geometry=geometry" % query, "tt", "virtual", False)
self.assertEqual(l4.isValid(), True)
self.assertEqual(l4.dataProvider().geometryType(), 1) # point
# with type annotations and url options (2)
query = QUrl.toPercentEncoding("SELECT 1 as id /*:int*/, 3.14 as f, geomfromtext('point(0 0)',4326) as geometry/*:point:4326*/")
l4 = QgsVectorLayer("?query=%s&geometry=geometry&field=id:text" % query, "tt", "virtual", False)
self.assertEqual(l4.isValid(), True)
self.assertEqual(l4.dataProvider().fields().at(0).name(), "id")
self.assertEqual(l4.dataProvider().fields().at(0).type(), QVariant.String)
self.assertEqual(l4.dataProvider().fields().at(1).name(), "f")
self.assertEqual(l4.dataProvider().fields().at(1).type(), QVariant.Double)
self.assertEqual(l4.dataProvider().geometryType(), 1) # point
示例8: test_sql4
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [as 别名]
def test_sql4(self):
l2 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "france_parts", "ogr", False)
self.assertEqual(l2.isValid(), True)
QgsMapLayerRegistry.instance().addMapLayer(l2)
query = QUrl.toPercentEncoding("SELECT OBJECTId from france_parts")
l4 = QgsVectorLayer("?query=%s" % query, "tt", "virtual", False)
self.assertEqual(l4.isValid(), True)
s = sum(f.attributes()[0] for f in l4.getFeatures())
self.assertEqual(s, 10659)
示例9: test_reopen2
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [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)
示例10: test_recursiveLayer
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [as 别名]
def test_recursiveLayer(self):
source = QUrl.toPercentEncoding(os.path.join(self.testDataDir, "france_parts.shp"))
l = QgsVectorLayer("?layer=ogr:%s" % source, "vtab", "virtual", False)
self.assertEqual(l.isValid(), True)
QgsMapLayerRegistry.instance().addMapLayer(l)
l2 = QgsVectorLayer("?layer_ref=" + l.id(), "vtab2", "virtual", False)
self.assertEqual(l2.isValid(), True)
QgsMapLayerRegistry.instance().removeMapLayer(l.id())
示例11: test_QueryUrlEncoding
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [as 别名]
def test_QueryUrlEncoding(self):
l1 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "france_parts", "ogr", False)
self.assertEqual(l1.isValid(), True)
QgsMapLayerRegistry.instance().addMapLayer(l1)
query = str(QUrl.toPercentEncoding("SELECT * FROM vtab1"))
l2 = QgsVectorLayer("?layer_ref=%s&query=%s&uid=ObjectId&nogeometry" % (l1.id(), query), "vtab", "virtual", False)
self.assertEqual(l2.isValid(), True)
QgsMapLayerRegistry.instance().removeMapLayer(l1.id())
示例12: test_DynamicGeometry
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [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)
示例13: test_sql3
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [as 别名]
def test_sql3(self):
l2 = QgsVectorLayer(os.path.join(self.testDataDir, "france_parts.shp"), "france_parts", "ogr", False)
self.assertEqual(l2.isValid(), True)
QgsMapLayerRegistry.instance().addMapLayer(l2)
# unnamed column
query = QUrl.toPercentEncoding("SELECT count(*)")
l4 = QgsVectorLayer("?query=%s" % query, "tt", "virtual", False)
self.assertEqual(l4.isValid(), True)
self.assertEqual(l4.dataProvider().fields().at(0).name(), "count(*)")
self.assertEqual(l4.dataProvider().fields().at(0).type(), QVariant.Int)
示例14: toSqlLayer
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [as 别名]
def toSqlLayer(self, sql, geomCol, uniqueCol, layerName="QueryLayer", layerType=None, avoidSelectById=False, _filter=""):
q = QUrl.toPercentEncoding(sql)
s = "?query=%s" % q
if uniqueCol is not None:
s += "&uid=" + uniqueCol
if geomCol is not None:
s += "&geometry=" + geomCol
vl = QgsVectorLayer(s, layerName, "virtual")
if _filter:
vl.setSubsetString(_filter)
return vl
示例15: test_geometry_conversion
# 需要导入模块: from PyQt.QtCore import QUrl [as 别名]
# 或者: from PyQt.QtCore.QUrl import toPercentEncoding [as 别名]
def test_geometry_conversion(self):
query = QUrl.toPercentEncoding("select geomfromtext('multipoint((0 0),(1 1))') as geom")
l = QgsVectorLayer("?query=%s&geometry=geom:multipoint:0" % query, "tt", "virtual", False)
self.assertEqual(l.isValid(), True)
for f in l.getFeatures():
self.assertEqual(f.geometry().exportToWkt().lower().startswith("multipoint"), True)
self.assertEqual("),(" in f.geometry().exportToWkt(), True) # has two points
query = QUrl.toPercentEncoding("select geomfromtext('multipolygon(((0 0,1 0,1 1,0 1,0 0)),((0 1,1 1,1 2,0 2,0 1)))') as geom")
l = QgsVectorLayer("?query=%s&geometry=geom:multipolygon:0" % query, "tt", "virtual", False)
self.assertEqual(l.isValid(), True)
for f in l.getFeatures():
self.assertEqual(f.geometry().exportToWkt().lower().startswith("multipolygon"), True)
self.assertEqual(")),((" in f.geometry().exportToWkt(), True) # has two polygons
query = QUrl.toPercentEncoding("select geomfromtext('multilinestring((0 0,1 0,1 1,0 1,0 0),(0 1,1 1,1 2,0 2,0 1))') as geom")
l = QgsVectorLayer("?query=%s&geometry=geom:multilinestring:0" % query, "tt", "virtual", False)
self.assertEqual(l.isValid(), True)
for f in l.getFeatures():
self.assertEqual(f.geometry().exportToWkt().lower().startswith("multilinestring"), True)
self.assertEqual("),(" in f.geometry().exportToWkt(), True) # has two linestrings