本文整理汇总了Python中qgis.core.QgsDataSourceUri.param方法的典型用法代码示例。如果您正苦于以下问题:Python QgsDataSourceUri.param方法的具体用法?Python QgsDataSourceUri.param怎么用?Python QgsDataSourceUri.param使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.core.QgsDataSourceUri
的用法示例。
在下文中一共展示了QgsDataSourceUri.param方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _clearSslTempCertsIfAny
# 需要导入模块: from qgis.core import QgsDataSourceUri [as 别名]
# 或者: from qgis.core.QgsDataSourceUri import param [as 别名]
def _clearSslTempCertsIfAny(self, connectionInfo):
# remove certs (if any) of the connectionInfo
expandedUri = QgsDataSourceUri(connectionInfo)
def removeCert(certFile):
certFile = certFile.replace("'", "")
file = QFile(certFile)
# set permission to allow removing on Win.
# On linux and Mac if file is set with QFile::>ReadUser
# does not create problem removing certs
if not file.setPermissions(QFile.WriteOwner):
raise Exception('Cannot change permissions on {}: error code: {}'.format(file.fileName(), file.error()))
if not file.remove():
raise Exception('Cannot remove {}: error code: {}'.format(file.fileName(), file.error()))
sslCertFile = expandedUri.param("sslcert")
if sslCertFile:
removeCert(sslCertFile)
sslKeyFile = expandedUri.param("sslkey")
if sslKeyFile:
removeCert(sslKeyFile)
sslCAFile = expandedUri.param("sslrootcert")
if sslCAFile:
removeCert(sslCAFile)
示例2: testWfsSettings
# 需要导入模块: from qgis.core import QgsDataSourceUri [as 别名]
# 或者: from qgis.core.QgsDataSourceUri import param [as 别名]
def testWfsSettings(self):
uri = QgsDataSourceUri()
QgsOwsConnection.addWfsConnectionSettings(uri, 'qgis/connections-wfs/test/')
self.assertEqual(uri.param('version'), '1.1.0')
self.assertEqual(uri.param('maxNumFeatures'), '47')
self.assertEqual(uri.param('IgnoreAxisOrientation'), '1')
self.assertEqual(uri.param('InvertAxisOrientation'), '1')
示例3: getWFSScriptTag
# 需要导入模块: from qgis.core import QgsDataSourceUri [as 别名]
# 或者: from qgis.core.QgsDataSourceUri import param [as 别名]
def getWFSScriptTag(layer, layerName):
layerSource = layer.source()
if ("retrictToRequestBBOX" in layerSource or
"restrictToRequestBBOX" in layerSource):
provider = layer.dataProvider()
uri = QgsDataSourceUri(provider.dataSourceUri())
wfsURL = uri.param("url")
wfsTypename = uri.param("typename")
wfsSRS = uri.param("srsname")
layerSource = wfsURL
layerSource += "?SERVICE=WFS&VERSION=1.0.0&"
layerSource += "REQUEST=GetFeature&TYPENAME="
layerSource += wfsTypename
layerSource += "&SRSNAME="
layerSource += wfsSRS
scriptTag = re.sub(r'SRSNAME\=EPSG\:\d+', 'SRSNAME=EPSG:4326', layerSource)
scriptTag += "&outputFormat=text%2Fjavascript&format_options=callback%3A"
scriptTag += "get" + layerName + "Json"
return scriptTag
示例4: writeScriptIncludes
# 需要导入模块: from qgis.core import QgsDataSourceUri [as 别名]
# 或者: from qgis.core.QgsDataSourceUri import param [as 别名]
def writeScriptIncludes(layers, json, matchCRS):
geojsonVars = ""
wfsVars = ""
styleVars = ""
for count, (layer, encode2json) in enumerate(zip(layers, json)):
vts = layer.customProperty("VectorTilesReader/vector_tile_url")
sln = safeName(layer.name()) + "_" + unicode(count)
if layer.type() == layer.VectorLayer:
if layer.providerType() != "WFS" or encode2json:
if vts is None:
geojsonVars += ('<script src="layers/%s"></script>' %
(sln + ".js"))
else:
layerSource = layer.source()
if ("retrictToRequestBBOX" in layerSource or
"restrictToRequestBBOX" in layerSource):
provider = layer.dataProvider()
uri = QgsDataSourceUri(provider.dataSourceUri())
wfsURL = uri.param("url")
wfsTypename = uri.param("typename")
wfsSRS = uri.param("srsname")
layerSource = wfsURL
layerSource += "?SERVICE=WFS&VERSION=1.0.0&"
layerSource += "REQUEST=GetFeature&TYPENAME="
layerSource += wfsTypename
layerSource += "&SRSNAME="
layerSource += wfsSRS
if not matchCRS:
layerSource = re.sub(r'SRSNAME\=EPSG\:\d+',
'SRSNAME=EPSG:3857',
layerSource)
layerSource += "&outputFormat=text%2Fjavascript&"
layerSource += "format_options=callback%3A"
layerSource += "get" + sln + "Json"
wfsVars += ('<script src="%s"></script>' % layerSource)
if vts is not None:
sln = safeName(vts)
styleVars += ('<script src="styles/%s_style.js">'
'</script>' % sln)
return (geojsonVars, wfsVars, styleVars)
示例5: testWmsSettings
# 需要导入模块: from qgis.core import QgsDataSourceUri [as 别名]
# 或者: from qgis.core.QgsDataSourceUri import param [as 别名]
def testWmsSettings(self):
uri = QgsDataSourceUri()
QgsOwsConnection.addWmsWcsConnectionSettings(uri, 'qgis/connections-wms/test/')
self.assertEqual(uri.param('referer'), 'my_ref')
self.assertEqual(uri.param('IgnoreGetMapUrl'), '1')
self.assertEqual(uri.param('IgnoreGetFeatureInfoUrl'), '1')
self.assertEqual(uri.param('SmoothPixmapTransform'), '1')
self.assertEqual(uri.param('dpiMode'), '4')
self.assertEqual(uri.param('IgnoreAxisOrientation'), '1')
self.assertEqual(uri.param('InvertAxisOrientation'), '1')
示例6: __init__
# 需要导入模块: from qgis.core import QgsDataSourceUri [as 别名]
# 或者: from qgis.core.QgsDataSourceUri import param [as 别名]
def __init__(self, host=None, port=None, dbname=None, user=None,
passwd=None, service=None, uri=None):
# Regular expression for identifiers without need to quote them
self.re_ident_ok = re.compile(r"^\w+$")
port = str(port)
if uri:
self.uri = uri
else:
self.uri = QgsDataSourceUri()
if service:
self.uri.setConnection(service, dbname, user, passwd)
else:
self.uri.setConnection(host, port, dbname, user, passwd)
conninfo = self.uri.connectionInfo(False)
err = None
for i in range(4):
expandedConnInfo = self.uri.connectionInfo(True)
try:
self.con = psycopg2.connect(expandedConnInfo)
if err is not None:
QgsCredentials.instance().put(conninfo,
self.uri.username(),
self.uri.password())
break
except psycopg2.OperationalError as e:
if i == 3:
raise QgsProcessingException(str(e))
err = str(e)
user = self.uri.username()
password = self.uri.password()
(ok, user, password) = QgsCredentials.instance().get(conninfo,
user,
password,
err)
if not ok:
raise QgsProcessingException(QCoreApplication.translate("PostGIS", 'Action canceled by user'))
if user:
self.uri.setUsername(user)
if password:
self.uri.setPassword(password)
finally:
# remove certs (if any) of the expanded connectionInfo
expandedUri = QgsDataSourceUri(expandedConnInfo)
sslCertFile = expandedUri.param("sslcert")
if sslCertFile:
sslCertFile = sslCertFile.replace("'", "")
os.remove(sslCertFile)
sslKeyFile = expandedUri.param("sslkey")
if sslKeyFile:
sslKeyFile = sslKeyFile.replace("'", "")
os.remove(sslKeyFile)
sslCAFile = expandedUri.param("sslrootcert")
if sslCAFile:
sslCAFile = sslCAFile.replace("'", "")
os.remove(sslCAFile)
self.has_postgis = self.check_postgis()
示例7: __init__
# 需要导入模块: from qgis.core import QgsDataSourceUri [as 别名]
# 或者: from qgis.core.QgsDataSourceUri import param [as 别名]
def __init__(self, uri):
DBConnector.__init__(self, uri)
self.host = uri.host() or os.environ.get('PGHOST')
self.port = uri.port() or os.environ.get('PGPORT')
username = uri.username() or os.environ.get('PGUSER')
password = uri.password() or os.environ.get('PGPASSWORD')
# Do not get db and user names from the env if service is used
if uri.service() is None:
if username is None:
username = os.environ.get('USER')
self.dbname = uri.database() or os.environ.get('PGDATABASE') or username
uri.setDatabase(self.dbname)
expandedConnInfo = self._connectionInfo()
try:
self.connection = psycopg2.connect(expandedConnInfo.encode('utf-8'))
except self.connection_error_types() as e:
err = unicode(e)
uri = self.uri()
conninfo = uri.connectionInfo(False)
for i in range(3):
(ok, username, password) = QgsCredentials.instance().get(conninfo, username, password, err)
if not ok:
raise ConnectionError(e)
if username:
uri.setUsername(username)
if password:
uri.setPassword(password)
newExpandedConnInfo = uri.connectionInfo(True)
try:
self.connection = psycopg2.connect(newExpandedConnInfo.encode('utf-8'))
QgsCredentials.instance().put(conninfo, username, password)
except self.connection_error_types() as e:
if i == 2:
raise ConnectionError(e)
err = unicode(e)
finally:
# remove certs (if any) of the expanded connectionInfo
expandedUri = QgsDataSourceUri(newExpandedConnInfo)
sslCertFile = expandedUri.param("sslcert")
if sslCertFile:
sslCertFile = sslCertFile.replace("'", "")
os.remove(sslCertFile)
sslKeyFile = expandedUri.param("sslkey")
if sslKeyFile:
sslKeyFile = sslKeyFile.replace("'", "")
os.remove(sslKeyFile)
sslCAFile = expandedUri.param("sslrootcert")
if sslCAFile:
sslCAFile = sslCAFile.replace("'", "")
os.remove(sslCAFile)
finally:
# remove certs (if any) of the expanded connectionInfo
expandedUri = QgsDataSourceUri(expandedConnInfo)
sslCertFile = expandedUri.param("sslcert")
if sslCertFile:
sslCertFile = sslCertFile.replace("'", "")
os.remove(sslCertFile)
sslKeyFile = expandedUri.param("sslkey")
if sslKeyFile:
sslKeyFile = sslKeyFile.replace("'", "")
os.remove(sslKeyFile)
sslCAFile = expandedUri.param("sslrootcert")
if sslCAFile:
sslCAFile = sslCAFile.replace("'", "")
os.remove(sslCAFile)
self.connection.set_isolation_level(psycopg2.extensions.ISOLATION_LEVEL_AUTOCOMMIT)
c = self._execute(None, u"SELECT current_user,current_database()")
self.user, self.dbname = self._fetchone(c)
self._close_cursor(c)
self._checkSpatial()
self._checkRaster()
self._checkGeometryColumnsTable()
self._checkRasterColumnsTable()