-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlayers_by_field.py
104 lines (82 loc) · 4.27 KB
/
layers_by_field.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
############################################
#
# Split layers by field.
# Developed by James Stott
# 14/06/2013
# Based on the code of the Split Shapefile plugin.
#
###############################################
# -*- coding: utf-8 -*-
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from qgis.core import *
from qgis.gui import *
import os
#from __init__ import mVersion
import resources
import layers_by_field_dialog
import inspect
from os import path
class layers_by_field( object ):
def __init__( self, iface ):
self.iface = iface
try:
self.QgisVersion = unicode( QGis.QGIS_VERSION_INT )
except:
self.QgisVersion = unicode( QGis.qgisVersion )[ 0 ]
# For i18n support
userPluginPath = QFileInfo( QgsApplication.qgisUserDbFilePath() ).path() + "/python/plugins/layers_by_field"
systemPluginPath = QgsApplication.prefixPath() + "/python/plugins/layers_by_field"
overrideLocale = QSettings().value( "locale/overrideFlag", False)#.toBool()
if not overrideLocale:
locale = QLocale.system().name()[0:2]
#locale = QSettings().value("locale/userLocale")[0:2]
else:
localeFullName = QSettings().value( "locale/userLocale", "" )#.toString()
locale = QSettings().value("locale/userLocale")[0:2]
if QFileInfo( userPluginPath ).exists():
translationPath = userPluginPath + "/i18n/layers_by_field_" + locale + ".qm"
else:
translationPath = systemPluginPath + "/i18n/layers_by_field_" + locale + ".qm"
self.localePath = translationPath
if QFileInfo( self.localePath ).exists():
self.translator = QTranslator()
self.translator.load( self.localePath )
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
def initGui(self):
self.actionRun = QAction(QIcon(":/plugins/layers_by_field/icon.png"), QCoreApplication.translate('SplitLayersByField','Split Layers By Field'), self.iface.mainWindow())
self.actionRun.setStatusTip(QCoreApplication.translate('SplitLayersByField',"Split Layers By Field adds a layer for each unique value in a text field"))
self.actionRun.setWhatsThis( QCoreApplication.translate('SplitLayersByField',"Split Layers By Field"))
self.actionAbout = QAction(QIcon(":/plugins/layers_by_field/help.png"), \
QCoreApplication.translate('SplitLayersByField',"Help"), self.iface.mainWindow())
self.actionAbout.setWhatsThis(QCoreApplication.translate('SplitLayersByField',"Split Layers By Field Help"))
self.actionRun.triggered.connect(self.run)
self.actionAbout.triggered.connect(self.about)
if hasattr( self.iface, "addPluginToVectorMenu" ):
self.iface.addPluginToVectorMenu(QCoreApplication.translate('menu_items', "Split Layers By Field"), self.actionRun)
self.iface.addPluginToVectorMenu(QCoreApplication.translate('menu_items', "Split Layers By Field"), self.actionAbout )
else:
self.iface.addPluginToMenu(QCoreApplication.translate('menu_items', "Split Layers By Field"), self.actionRun)
self.iface.addPluginToMenu(QCoreApplication.translate('menu_items', "Split Layers By Field"), self.actionAbout )
def unload(self):
if hasattr( self.iface, "addPluginToVectorMenu" ):
self.iface.removePluginVectorMenu(QCoreApplication.translate('menu_items', "Split Layers By Field"),self.actionRun)
self.iface.removePluginVectorMenu(QCoreApplication.translate('menu_items', "Split Layers By Field"), self.actionAbout )
else:
self.iface.removePluginMenu(QCoreApplication.translate('menu_items', "Split Layers By Field"),self.actionRun)
self.iface.removePluginMenu(QCoreApplication.translate('menu_items', "Split Layers By Field"), self.actionAbout )
def about( self ):
file = inspect.getsourcefile(layers_by_field)
file = 'file://' + path.join(path.dirname(file),'help/index.html')
file = file.replace("\\","/")
self.iface.openURL(file, False)
def run(self):
if QgsMapLayerRegistry.instance().count() >= 1:
self.dlg = layers_by_field_dialog.layers_by_field_dialog(self.iface)
self.dlg.show()
result = self.dlg.exec_()
if result ==1:
pass
else:
QMessageBox.information( self.iface.mainWindow(),"Info", QCoreApplication.translate("info_message","There are no layers loaded"))