本文整理匯總了Python中db_manager.db_plugins.postgis.connector.PostGisDBConnector.getVectorTables方法的典型用法代碼示例。如果您正苦於以下問題:Python PostGisDBConnector.getVectorTables方法的具體用法?Python PostGisDBConnector.getVectorTables怎麽用?Python PostGisDBConnector.getVectorTables使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類db_manager.db_plugins.postgis.connector.PostGisDBConnector
的用法示例。
在下文中一共展示了PostGisDBConnector.getVectorTables方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: postgis_path_to_uri
# 需要導入模塊: from db_manager.db_plugins.postgis.connector import PostGisDBConnector [as 別名]
# 或者: from db_manager.db_plugins.postgis.connector.PostGisDBConnector import getVectorTables [as 別名]
def postgis_path_to_uri(path):
"""Convert layer path from QgsBrowserModel to full QgsDataSourceURI.
:param path: The layer path from QgsBrowserModel
:type path: string
:returns: layer uri.
:rtype: QgsDataSourceURI
"""
connection_name = path.split('/')[1]
schema = path.split('/')[2]
table_name = path.split('/')[3]
settings = QSettings()
key = "/PostgreSQL/connections/" + connection_name
service = settings.value(key + "/service")
host = settings.value(key + "/host")
port = settings.value(key + "/port")
if not port:
port = "5432"
db = settings.value(key + "/database")
use_estimated_metadata = settings.value(
key + "/estimatedMetadata", False, type=bool)
sslmode = settings.value(
key + "/sslmode", QgsDataSourceURI.SSLprefer, type=int)
username = ""
password = ""
if settings.value(key + "/saveUsername") == "true":
username = settings.value(key + "/username")
if settings.value(key + "/savePassword") == "true":
password = settings.value(key + "/password")
# Old save setting
if settings.contains(key + "/save"):
username = settings.value(key + "/username")
if settings.value(key + "/save") == "true":
password = settings.value(key + "/password")
uri = QgsDataSourceURI()
if service:
uri.setConnection(service, db, username, password, sslmode)
else:
uri.setConnection(host, port, db, username, password, sslmode)
uri.setUseEstimatedMetadata(use_estimated_metadata)
# Obtain the geometry column name
connector = PostGisDBConnector(uri)
tables = connector.getVectorTables(schema)
tables = [table for table in tables if table[1] == table_name]
if not tables:
return None
table = tables[0]
geom_col = table[8]
uri.setDataSource(schema, table_name, geom_col)
return uri