mirror of
https://github.com/qgis/QGIS.git
synced 2025-04-16 00:03:12 -04:00
[processing] Change save as spatialite option to save as GeoPackage
Since it's much more useful. Also add a prompt for layer name, so that you can save the results of an algorithm into an existing geopackage without wiping existing layers.
This commit is contained in:
parent
abcdd48580
commit
aca22663d0
0
python/plugins/processing/algs/qgis/GeometryByExpression.py
Normal file → Executable file
0
python/plugins/processing/algs/qgis/GeometryByExpression.py
Normal file → Executable file
32
python/plugins/processing/gui/DestinationSelectionPanel.py
Normal file → Executable file
32
python/plugins/processing/gui/DestinationSelectionPanel.py
Normal file → Executable file
@ -31,7 +31,7 @@ import os
|
|||||||
|
|
||||||
from qgis.PyQt import uic
|
from qgis.PyQt import uic
|
||||||
from qgis.PyQt.QtCore import QCoreApplication, QDir
|
from qgis.PyQt.QtCore import QCoreApplication, QDir
|
||||||
from qgis.PyQt.QtWidgets import QDialog, QMenu, QAction, QFileDialog
|
from qgis.PyQt.QtWidgets import QDialog, QMenu, QAction, QFileDialog, QInputDialog
|
||||||
from qgis.PyQt.QtGui import QCursor
|
from qgis.PyQt.QtGui import QCursor
|
||||||
from qgis.gui import QgsEncodingSelectionDialog
|
from qgis.gui import QgsEncodingSelectionDialog
|
||||||
from qgis.core import (QgsDataSourceUri,
|
from qgis.core import (QgsDataSourceUri,
|
||||||
@ -125,10 +125,10 @@ class DestinationSelectionPanel(BASE, WIDGET):
|
|||||||
|
|
||||||
if isinstance(self.parameter, QgsProcessingParameterFeatureSink) \
|
if isinstance(self.parameter, QgsProcessingParameterFeatureSink) \
|
||||||
and self.alg.provider().supportsNonFileBasedOutput():
|
and self.alg.provider().supportsNonFileBasedOutput():
|
||||||
actionSaveToSpatialite = QAction(
|
actionSaveToGpkg = QAction(
|
||||||
self.tr('Save to SpatiaLite table...'), self.btnSelect)
|
self.tr('Save to GeoPackage...'), self.btnSelect)
|
||||||
actionSaveToSpatialite.triggered.connect(self.saveToSpatialite)
|
actionSaveToGpkg.triggered.connect(self.saveToGeopackage)
|
||||||
popupMenu.addAction(actionSaveToSpatialite)
|
popupMenu.addAction(actionSaveToGpkg)
|
||||||
actionSaveToPostGIS = QAction(
|
actionSaveToPostGIS = QAction(
|
||||||
self.tr('Save to PostGIS table...'), self.btnSelect)
|
self.tr('Save to PostGIS table...'), self.btnSelect)
|
||||||
actionSaveToPostGIS.triggered.connect(self.saveToPostGIS)
|
actionSaveToPostGIS.triggered.connect(self.saveToPostGIS)
|
||||||
@ -177,8 +177,8 @@ class DestinationSelectionPanel(BASE, WIDGET):
|
|||||||
QgsCredentials.instance().put(connInfo, user, passwd)
|
QgsCredentials.instance().put(connInfo, user, passwd)
|
||||||
self.leText.setText("postgis:" + uri.uri())
|
self.leText.setText("postgis:" + uri.uri())
|
||||||
|
|
||||||
def saveToSpatialite(self):
|
def saveToGeopackage(self):
|
||||||
file_filter = self.tr('SpatiaLite files (*.sqlite)', 'OutputFile')
|
file_filter = self.tr('GeoPackage files (*.gpkg);;All files (*.*)', 'OutputFile')
|
||||||
|
|
||||||
settings = QgsSettings()
|
settings = QgsSettings()
|
||||||
if settings.contains('/Processing/LastOutputPath'):
|
if settings.contains('/Processing/LastOutputPath'):
|
||||||
@ -186,21 +186,25 @@ class DestinationSelectionPanel(BASE, WIDGET):
|
|||||||
else:
|
else:
|
||||||
path = ProcessingConfig.getSetting(ProcessingConfig.OUTPUT_FOLDER)
|
path = ProcessingConfig.getSetting(ProcessingConfig.OUTPUT_FOLDER)
|
||||||
|
|
||||||
filename, filter = QFileDialog.getSaveFileName(self, self.tr("Save file"), path,
|
filename, filter = QFileDialog.getSaveFileName(self, self.tr("Save to GeoPackage"), path,
|
||||||
file_filter, options=QFileDialog.DontConfirmOverwrite)
|
file_filter, options=QFileDialog.DontConfirmOverwrite)
|
||||||
|
|
||||||
if filename is not None:
|
if filename is None:
|
||||||
|
return
|
||||||
|
|
||||||
|
layer_name, ok = QInputDialog.getText(self, self.tr('Save to GeoPackage'), self.tr('Layer name'), text=self.parameter.name().lower())
|
||||||
|
if ok:
|
||||||
self.use_temporary = False
|
self.use_temporary = False
|
||||||
if not filename.lower().endswith('.sqlite'):
|
if not filename.lower().endswith('.gpkg'):
|
||||||
filename += '.sqlite'
|
filename += '.gpkg'
|
||||||
settings.setValue('/Processing/LastOutputPath',
|
settings.setValue('/Processing/LastOutputPath',
|
||||||
os.path.dirname(filename))
|
os.path.dirname(filename))
|
||||||
|
|
||||||
uri = QgsDataSourceUri()
|
uri = QgsDataSourceUri()
|
||||||
uri.setDatabase(filename)
|
uri.setDatabase(filename)
|
||||||
uri.setDataSource('', self.parameter.name().lower(),
|
uri.setDataSource('', layer_name,
|
||||||
'the_geom' if isinstance(self.parameter, QgsProcessingParameterFeatureSink) and self.parameter.hasGeometry() else None)
|
'geom' if isinstance(self.parameter, QgsProcessingParameterFeatureSink) and self.parameter.hasGeometry() else None)
|
||||||
self.leText.setText("spatialite:" + uri.uri())
|
self.leText.setText("ogr:" + uri.uri())
|
||||||
|
|
||||||
def selectFile(self):
|
def selectFile(self):
|
||||||
file_filter = getFileFilter(self.parameter)
|
file_filter = getFileFilter(self.parameter)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user