Skip to content
Permalink
Browse files

[DBManager] allow to export table data to supported ogr file formats …

…other than shapefile (fix #12111)
  • Loading branch information
brushtyler committed Sep 21, 2015
1 parent 2a1cacd commit 99211262f35f7c293d00bcd80a315f1917bad0b0
Showing with 75 additions and 41 deletions.
  1. +34 −10 python/plugins/db_manager/dlg_export_vector.py
  2. +41 −31 python/plugins/db_manager/ui/DlgExportVector.ui
@@ -38,8 +38,13 @@ def __init__(self, inLayer, inDb, parent=None):
self.db = inDb
self.setupUi(self)

vectorFilterName = "lastVectorFileFilter" # "lastRasterFileFilter"
self.lastUsedVectorFilterSettingsKey = u"/UI/{0}".format(vectorFilterName)
self.lastUsedVectorDirSettingsKey = u"/UI/{0}Dir".format(vectorFilterName)

# update UI
self.setupWorkingMode()
self.populateFileFilters()
self.populateEncodings()

def setupWorkingMode(self):
@@ -61,18 +66,21 @@ def checkSupports(self):
# self.chkSpatialIndex.setEnabled(allowSpatial and hasGeomType)

def chooseOutputFile(self):
# get last used dir and format
# get last used dir
settings = QSettings()
lastDir = settings.value("/db_manager/lastUsedDir", "")
lastUsedDir = settings.value( self.lastUsedVectorDirSettingsKey, "." );

# get selected filter
selectedFilter = self.cboFileFormat.itemData(self.cboFileFormat.currentIndex())

# ask for a filename
filename = QFileDialog.getSaveFileName(self, self.tr("Choose where to save the file"), lastDir,
self.tr("Shapefiles") + " (*.shp)")
filename = QFileDialog.getSaveFileName(self, self.tr("Choose where to save the file"), lastUsedDir,
selectedFilter)
if filename == "":
return
if filename[-4:] != ".shp":
filename += ".shp"
# store the last used dir and format
settings.setValue("/db_manager/lastUsedDir", QFileInfo(filename).filePath())

# store the last used dir
settings.setValue( self.lastUsedVectorDirSettingsKey, QFileInfo(filename).filePath() )

self.editOutputFile.setText(filename)

@@ -88,10 +96,25 @@ def populateEncodings(self):
idx = 0
self.cboEncoding.setCurrentIndex(idx)

def populateFileFilters(self):
# populate the combo with supported vector file formats
for name, filt in qgis.core.QgsVectorFileWriter.ogrDriverList().iteritems():
self.cboFileFormat.addItem(name, filt)

# set the last used filter
settings = QSettings()
filt = settings.value( self.lastUsedVectorFilterSettingsKey, "ESRI Shapefile" );

idx = self.cboFileFormat.findText(filt)
if idx < 0:
idx = 0
self.cboFileFormat.setCurrentIndex(idx)


def accept(self):
# sanity checks
if self.editOutputFile.text() == "":
QMessageBox.information(self, self.tr("Export to file"), self.tr("Output table name is required"))
QMessageBox.information(self, self.tr("Export to file"), self.tr("Output file name is required"))
return

if self.chkSourceSrid.isEnabled() and self.chkSourceSrid.isChecked():
@@ -117,12 +140,13 @@ def accept(self):
try:
uri = self.editOutputFile.text()
providerName = "ogr"
driverName = "ESRI Shapefile"

options = {}

# set the OGR driver will be used
driverName = self.cboFileFormat.itemData(self.cboFileFormat.currentIndex())
options['driverName'] = driverName

# set the output file encoding
if self.chkEncoding.isEnabled() and self.chkEncoding.isChecked():
enc = self.cboEncoding.currentText()
@@ -7,46 +7,59 @@
<x>0</x>
<y>0</y>
<width>514</width>
<height>185</height>
<height>253</height>
</rect>
</property>
<property name="windowTitle">
<string>Export to vector file</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<item row="1" column="1">
<widget class="QLineEdit" name="editOutputFile">
<property name="text">
<string>Output file</string>
<string notr="true"/>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QLineEdit" name="editOutputFile">
<property name="text">
<string notr="true"/>
<item row="3" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QToolButton" name="btnChooseOutputFile">
<item row="0" column="1" colspan="2">
<widget class="QComboBox" name="cboFileFormat"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_5">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>...</string>
<string>Save as</string>
</property>
</widget>
</item>
<item row="1" column="0" colspan="3">
<item row="2" column="0" colspan="3">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Options</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="chkDropTable">
<property name="text">
<string>Drop existing one</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
@@ -127,23 +140,20 @@
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="chkDropTable">
<property name="text">
<string>Drop existing one</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="2" column="0" colspan="3">
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
<item row="1" column="2">
<widget class="QToolButton" name="btnChooseOutputFile">
<property name="text">
<string>...</string>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Format</string>
</property>
</widget>
</item>

0 comments on commit 9921126

Please sign in to comment.
You can’t perform that action at this time.