mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-04 00:30:59 -05:00
[db_manager] Detect CRS in advanced add layer
This commit is contained in:
parent
2555e6420c
commit
f3dd5150c7
@ -52,7 +52,8 @@ from qgis.core import (
|
||||
QgsVectorLayer,
|
||||
QgsRasterLayer,
|
||||
QgsProject,
|
||||
QgsMessageLog
|
||||
QgsMessageLog,
|
||||
QgsCoordinateReferenceSystem
|
||||
)
|
||||
|
||||
from qgis.gui import (
|
||||
@ -745,6 +746,11 @@ class Table(DbItemObject):
|
||||
uri.setDataSource(schema, self.name, geomCol if geomCol else None, None, uniqueCol.name if uniqueCol else "")
|
||||
return uri
|
||||
|
||||
def crs(self):
|
||||
"""Returns the CRS of this table or an invalid CRS if this is not a spatial table
|
||||
This should be overwritten by any additional db plugins"""
|
||||
return QgsCoordinateReferenceSystem()
|
||||
|
||||
def mimeUri(self):
|
||||
layerType = "raster" if self.type == Table.RasterType else "vector"
|
||||
return u"%s:%s:%s:%s" % (layerType, self.database().dbplugin().providerName(), self.name, self.uri().uri(False))
|
||||
@ -1144,6 +1150,7 @@ class VectorTable(Table):
|
||||
layout.addRow(zCheckBox)
|
||||
layout.addRow(mCheckBox)
|
||||
crsSelector = QgsProjectionSelectionWidget()
|
||||
crsSelector.setCrs(self.crs())
|
||||
layout.addRow(self.tr('CRS'), crsSelector)
|
||||
|
||||
def selectedGeometryType():
|
||||
|
@ -27,7 +27,7 @@ from builtins import range
|
||||
from functools import cmp_to_key
|
||||
|
||||
from qgis.PyQt.QtCore import QRegExp, QFile, QCoreApplication
|
||||
from qgis.core import Qgis, QgsCredentials, QgsDataSourceUri
|
||||
from qgis.core import Qgis, QgsCredentials, QgsDataSourceUri, QgsCoordinateReferenceSystem
|
||||
|
||||
from ..connector import DBConnector
|
||||
from ..plugin import ConnectionError, DbError, Table
|
||||
@ -642,6 +642,23 @@ class PostGisDBConnector(DBConnector):
|
||||
self._close_cursor(c)
|
||||
return res[0] if res is not None else None
|
||||
|
||||
def getCrs(self, srid):
|
||||
if not self.has_spatial:
|
||||
return QgsCoordinateReferenceSystem()
|
||||
|
||||
try:
|
||||
c = self._execute(None, "SELECT proj4text FROM spatial_ref_sys WHERE srid = '%d'" % srid)
|
||||
except DbError:
|
||||
return QgsCoordinateReferenceSystem()
|
||||
res = self._fetchone(c)
|
||||
self._close_cursor(c)
|
||||
if res is None:
|
||||
return QgsCoordinateReferenceSystem()
|
||||
|
||||
proj4text = res[0]
|
||||
crs = QgsCoordinateReferenceSystem.fromProj4(proj4text)
|
||||
return crs
|
||||
|
||||
def getSpatialRefInfo(self, srid):
|
||||
if not self.has_spatial:
|
||||
return
|
||||
|
@ -269,6 +269,9 @@ class PGTable(Table):
|
||||
|
||||
return PGTableInfo(self)
|
||||
|
||||
def crs(self):
|
||||
return self.database().connector.getCrs(self.srid)
|
||||
|
||||
def tableDataModel(self, parent):
|
||||
from .data_model import PGTableDataModel
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user