Skip to content

Commit

Permalink
optional SLD style export added
Browse files Browse the repository at this point in the history
  • Loading branch information
zsiki committed Jul 26, 2017
1 parent 4e412c3 commit 929044e
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 14 deletions.
17 changes: 11 additions & 6 deletions bulkvectorexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ def run(self):
ogr_driver_name = self.dlg.ui.formatBox.currentText()
print"Driver ogr name: " + ogr_driver_name
layers = qgis.utils.iface.mapCanvas().layers()
exportOnlySelected = False
# Thijs Brentjens (https://github.com/thijsbrentjens/) add option for exporting only selected features
if self.dlg.ui.onlySelectedButton.isChecked():
exportOnlySelected = True
exportSld = False
if self.dlg.ui.exportSldButton.isChecked():
exportSld = True
crs = qgis.utils.iface.mapCanvas().mapRenderer().destinationCrs()
for layer in layers:
layerType = layer.type()
if layerType == QgsMapLayer.VectorLayer:
Expand All @@ -105,12 +113,6 @@ def run(self):
print 'Filename: ' + layer_filename
if self.dlg.ui.layerCrsButton.isChecked():
crs = layer.crs()
else:
crs = qgis.utils.iface.mapCanvas().mapRenderer().destinationCrs()
exportOnlySelected=False
# Thijs Brentjens (https://github.com/thijsbrentjens/) add option for exporting only selected features
if self.dlg.ui.onlySelectedButton.isChecked():
exportOnlySelected=True
print "CRS selected: " + crs.description()
# Thijs Brentjens (https://github.com/thijsbrentjens/) add option for exporting only selected features
result2 = qgis.core.QgsVectorFileWriter.writeAsVectorFormat(layer, layer_filename, layer.dataProvider().encoding(), crs, ogr_driver_name, onlySelected=exportOnlySelected)
Expand All @@ -119,3 +121,6 @@ def run(self):
QtGui.QMessageBox.warning(self.dlg, "BulkVectorExport",\
"Failed to export: " + layer.name() + \
" Status: " + str(result2))
if exportSld:
layer.saveSldStyle(layer_filename + '.sld')
print 'SLD: ' + layer_filename
7 changes: 6 additions & 1 deletion ui_bulkvectorexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ def setupUi(self, BulkVectorExportDialog):
self.dirButton.setText(QtGui.QApplication.translate("BulkVectorExportDialog", "...", None, QtGui.QApplication.UnicodeUTF8))
self.dirButton.setObjectName(_fromUtf8("dirButton"))
self.onlySelectedButton = QtGui.QCheckBox(BulkVectorExportDialog)
self.onlySelectedButton.setGeometry(QtCore.QRect(140, 100, 241, 17))
self.onlySelectedButton.setGeometry(QtCore.QRect(140, 90, 241, 17))
self.onlySelectedButton.setText(QtGui.QApplication.translate("BulkVectorExportDialog", "Only selected features", None, QtGui.QApplication.UnicodeUTF8))
self.onlySelectedButton.setChecked(False)
self.onlySelectedButton.setObjectName(_fromUtf8("onlySelectedButton"))
self.exportSldButton = QtGui.QCheckBox(BulkVectorExportDialog)
self.exportSldButton.setGeometry(QtCore.QRect(140, 110, 241, 17))
self.exportSldButton.setText(QtGui.QApplication.translate("BulkVectorExportDialog", "Export SLD style", None, QtGui.QApplication.UnicodeUTF8))
self.exportSldButton.setChecked(False)
self.exportSldButton.setObjectName(_fromUtf8("exportSldButton"))

self.retranslateUi(BulkVectorExportDialog)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), BulkVectorExportDialog.accept)
Expand Down
27 changes: 20 additions & 7 deletions ui_bulkvectorexport.ui
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<property name="geometry">
<rect>
<x>220</x>
<y>100</y>
<y>140</y>
<width>161</width>
<height>32</height>
</rect>
Expand Down Expand Up @@ -110,19 +110,19 @@
<string>Project CRS</string>
</property>
</widget>
<widget class="QCheckBox" name="onlySelected">
<widget class="QCheckBox" name="onlySelected">
<property name="geometry">
<rect>
<x>140</x>
<y>100</y>
<y>90</y>
<width>241</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Only selected features</string>
</property>
</widget>
<property name="text">
<string>Only selected features</string>
</property>
</widget>
<widget class="QPushButton" name="dirButton">
<property name="geometry">
<rect>
Expand All @@ -136,6 +136,19 @@
<string>...</string>
</property>
</widget>
<widget class="QCheckBox" name="sldExport">
<property name="geometry">
<rect>
<x>140</x>
<y>110</y>
<width>241</width>
<height>17</height>
</rect>
</property>
<property name="text">
<string>Export SLD style</string>
</property>
</widget>
</widget>
<resources/>
<connections>
Expand Down

0 comments on commit 929044e

Please sign in to comment.