Example #1
0
 def _sectionLineGeometry(self, item):
     if item and item.isValid():
         sln = ItemFeature(item, 'sln')
         request = sln.featureRequest()
         features = layers.getAllFeaturesRequest(request, self.collection('plan').layer('lines'))
         for feature in features:
             return QgsGeometry(feature.geometry())
     return QgsGeometry()
Example #2
0
    def configure(self):
        wizard = ProjectWizard(self._plugin.iface.mainWindow())

        ok = wizard.exec_()

        if ok:

            if wizard.newProject():
                if Project.exists():
                    Project.write()
                Project.clear()
                projectFolderPath = os.path.join(wizard.projectFolder(), 'project')
                if not QDir(projectFolderPath).mkpath('.'):
                    return False
                projectFilePath = os.path.join(projectFolderPath, wizard.projectFilename() + '.qgs')
                Project.setFileName(projectFilePath)

            Settings.setProjectCode(wizard.project().projectCode())
            Settings.setProjectName(wizard.project().projectName())
            Settings.setSiteCode(wizard.project().siteCode())
            if not Project.title():
                Project.setTitle(wizard.project().projectCode() + ' - ' + wizard.project().projectName())

            self._initialised = Project.write()
            if self._initialised:

                # We always want the site collection
                self._addCollection('site')
                self.collection('site').loadCollection()
                # Add the Site Location if entered
                location = wizard.projectLocation()
                if not location.isEmpty():
                    siteCode = wizard.project().siteCode() if wizard.project().siteCode() else wizard.project().projectCode()
                    item = Item(siteCode, 'site', siteCode)
                    source = Source('other', item)
                    audit = Audit(Settings.userFullName(), utils.timestamp())
                    itemFeature = ItemFeature(item, 'loc', None, source, 'New Project Wizard', audit)
                    layer = self.collection('site').layer('points')
                    feature = QgsFeature(layer.pendingFields(), 0)
                    feature.setGeometry(QgsGeometry(location))
                    attributes = itemFeature.toFeature(feature)
                    layers.addFeatures([feature], layer)

                # Temp load of other collection, later do on demand
                self._addCollection('plan')
                self.collection('plan').loadCollection()
                self._addCollection('section')
                self.collection('section').loadCollection()
                self._addCollection('grid')
                self.collection('grid').loadCollection()

                # self._configureDrawing('context')
                # self._configureDrawing('plan')
                # self._configureDrawing('section')

                Settings.setProjectConfigured()

        return ok
Example #3
0
 def _getFeature(self, layer, item, category=''):
     req = None
     if category:
         sch = ItemFeature(item, 'sch')
         req = sch.featureRequest()
     else:
         req = item.featureRequest()
     try:
         return layer.getFeatures(req).next()
     except StopIteration:
         return None
     return None
    def __init__(self, parent=None):
        super(ItemFeatureWidget, self).__init__(parent)
        self.setupUi(self)

        self._itemFeature = ItemFeature()
        self._actions = {}
        self._mapTools = {}
        self._currentMapTool = None
        self._collection = None
        self._iface = None
        self._definitiveCategories = set()
        self._colMax = 6
        self._pointTool = 0
        self._lineTool = 0
        self._polygonTool = 0
 def __init__(self, fileInfo=None):
     self.layer = ''
     self.row = -1
     self.fid = -1
     self.feature = ItemFeature()
     self.field = ''
     self.message = ''
     self.ignore = False
Example #6
0
 def _sectionItemList(self, siteCode):
     # TODO in 2.14 use addOrderBy()
     request = utils.featureRequest(utils.eqClause('site', siteCode) + ' and ' + utils.eqClause('class', 'sec'))
     features = layers.getAllFeaturesRequest(request, self.collection('plan').layer('lines'))
     lst = []
     for feature in features:
         lst.append(ItemFeature(feature))
     lst.sort()
     return lst
    def __init__(self, parent=None):
        super(ItemFeatureWidget, self).__init__(parent)
        self.setupUi(self)

        self._itemFeature = ItemFeature()
        self._actions = {}
        self._mapTools = {}
        self._currentMapTool = None
        self._collection = None
        self._iface = None
        self._definitiveCategories = set()
        self._colMax = 6
        self._pointTool = 0
        self._lineTool = 0
        self._polygonTool = 0
Example #8
0
 def fromFeature(self, feature):
     self.fromItemFeature(ItemFeature(feature))
Example #9
0
 def itemFeature(self):
     return ItemFeature(item=self.item(), source=self.source(), comment=self.comment(), creator=self.editor())
class ItemFeatureWidget(QWidget, Ui_ItemFeatureWidget):

    featureChanged = pyqtSignal()
    autoToolSelected = pyqtSignal()

    def __init__(self, parent=None):
        super(ItemFeatureWidget, self).__init__(parent)
        self.setupUi(self)

        self._itemFeature = ItemFeature()
        self._actions = {}
        self._mapTools = {}
        self._currentMapTool = None
        self._collection = None
        self._iface = None
        self._definitiveCategories = set()
        self._colMax = 6
        self._pointTool = 0
        self._lineTool = 0
        self._polygonTool = 0

    def initGui(self, iface, collection):
        self._iface = iface
        for key in sorted(Config.classCodes.keys()):
            classCode = Config.classCodes[key]
            if classCode['collection']:
                self.classCombo.addItem(classCode['label'], classCode['class'])

        self._addStandardTool(
            FeatureType.Point,
            ':/plugins/ark/plan/editPoints.svg',
            u'Points Node Tool',
            self._editPointsLayer
        )
        self._addStandardTool(
            FeatureType.Point,
            ':/plugins/ark/plan/selectPoints.svg',
            u'Points Select Tool',
            self._selectPointsLayer
        )

        self._addStandardTool(
            FeatureType.Line,
            ':/plugins/ark/plan/editLines.svg',
            u'Lines Node Tool',
            self._editLinesLayer
        )
        self._addStandardTool(
            FeatureType.Line,
            ':/plugins/ark/plan/selectLines.svg',
            u'Lines Select Tool',
            self._selectLinesLayer
        )

        self._addStandardTool(
            FeatureType.Polygon,
            ':/plugins/ark/plan/editPolygons.svg',
            u'Polygons Node Tool',
            self._editPolygonsLayer
        )
        self._addStandardTool(
            FeatureType.Polygon,
            ':/plugins/ark/plan/selectPolygons.svg',
            u'Polygons Select Tool',
            self._selectPolygonsLayer
        )
        # TODO Make generic somehow
        if collection == 'plan':
            self._addStandardTool(
                FeatureType.Polygon,
                ':/plugins/ark/plan/addPolygons.svg',
                u'Auto-Schematic Tool',
                self._autoSchematicSelected
            )

        self._addToolSpacer(self.pointToolLayout)
        self._pointTool = self._colMax
        self._addToolSpacer(self.lineToolLayout)
        self._lineTool = self._colMax
        self._addToolSpacer(self.polygonToolLayout)
        self._polygonTool = self._colMax

        for feature in Config.featureCollections[collection]:
            category = Config.featureCategories[feature['category']]
            if 'query' not in category:
                category['query'] = None
            self._addDrawingTool(
                feature['class'], feature['category'], category['name'], QIcon(), category['type'], category['query']
            )
            if category['definitive'] is True:
                self._definitiveCategories.add(feature['category'])

        self.idEdit.editingFinished.connect(self.featureChanged)
        self.idEdit.editingFinished.connect(self._itemIdChanged)
        self.labelEdit.editingFinished.connect(self.featureChanged)
        self.labelEdit.editingFinished.connect(self._labelChanged)
        self.commentEdit.editingFinished.connect(self.featureChanged)
        self.commentEdit.editingFinished.connect(self._commentChanged)

        self._itemFeature.changed.connect(self._updateMapToolAttributes)

    def unloadGui(self):
        for action in self._actions.values():
            if action.isChecked():
                action.setChecked(False)

    def loadProject(self, plugin, collection):
        self._collection = plugin.project().collection(collection)
        for category in self._mapTools:
            geometryType = self._mapTools[category].geometryType()
            layer = None
            if geometryType == QGis.Point:
                layer = self._collection.buffer('points')
            elif geometryType == QGis.Polygon:
                layer = self._collection.buffer('polygons')
            elif geometryType == QGis.Line:
                layer = self._collection.buffer('lines')
            self._mapTools[category].setLayer(layer)

    def closeProject(self):
        pass

    def itemFeature(self):
        return self._itemFeature

    def setItemFeature(self, feature):
        self.blockSignals(True)
        self._itemFeature = feature
        self.blockSignals(False)

    def _classCode(self):
        return self.classCombo.itemData(self.classCombo.currentIndex())

    def _setClassCode(self, classCode):
        idx = self.classCombo.findData(classCode)
        if idx >= 0:
            self.classCombo.setCurrentIndex(idx)
            self._itemFeature.item().setClassCode(classCode)

    def _itemId(self):
        return self.idEdit.text().strip()

    def _setItemId(self, itemId):
        self.idEdit.setText(itemId)
        self._itemFeature.item().setItemId(itemId)

    def _itemIdChanged(self):
        self._itemFeature.item().setItemId(self._itemId())

    def _category(self):
        for category in self._mapTools:
            if self._mapTools[category].action().isChecked():
                return category
        return ''

    def _setCategory(self, category):
        # self._mapTools[category].action().setChecked(True)
        self._itemFeature.setCategory(category)

    def _label(self):
        return self.labelEdit.text().strip()

    def _setLabel(self, label):
        self.labelEdit.setText(label)
        self._labelChanged()

    def _labelChanged(self):
        self._itemFeature.setLabel(self._label())

    def _comment(self):
        return self.commentEdit.text().strip()

    def _setComment(self, comment):
        self.commentEdit.setText(comment)
        self._commentChanged()

    def _commentChanged(self):
        self._itemFeature.setComment(self._comment())

    # Drawing Tools

    def _addToolButton(self, action, featureType):
        toolButton = QToolButton(self)
        toolButton.setFixedWidth(30)
        toolButton.setFixedHeight(30)
        toolButton.setDefaultAction(action)
        geometryType = FeatureType.toGeometryType(featureType)
        if geometryType == QGis.Point:
            self._addToolWidget(self.pointToolLayout, toolButton, self._pointTool)
            self._pointTool += 1
        elif geometryType == QGis.Line:
            self._addToolWidget(self.lineToolLayout, toolButton, self._lineTool)
            self._lineTool += 1
        elif geometryType == QGis.Polygon:
            self._addToolWidget(self.polygonToolLayout, toolButton, self._polygonTool)
            self._polygonTool += 1

    def _addStandardTool(self, featureType, icon, tooltip, slot=None):
        action = QAction(QIcon(icon), '', self)
        action.setToolTip(tooltip)
        action.setCheckable(False)
        action.triggered.connect(slot)
        self._addToolButton(action, featureType)

    def _addDrawingTool(self, classCode, category, toolName, icon, featureType, query=None):
        data = {}
        data['class'] = classCode
        data['category'] = category
        action = QAction(icon, category, self)
        action.setData(data)
        action.setToolTip(toolName)
        action.setCheckable(True)

        mapTool = MapToolAddFeature(self._iface, featureType, toolName)
        mapTool.setAction(action)
        mapTool.setPanningEnabled(True)
        mapTool.setZoomingEnabled(True)
        mapTool.setSnappingEnabled(True)
        mapTool.activated.connect(self._mapToolActivated)
        if query is not None:
            field = Config.fields[query]
            mapTool.setAttributeQuery(
                field['attribute'],
                field['type'],
                field['default'],
                field['label'],
                field['query'],
                field['min'],
                field['max'],
                field['decimals']
            )

        self._addToolButton(action, featureType)
        self._actions[category] = action
        self._mapTools[category] = mapTool

    def _mapToolActivated(self):
        for mapTool in self._mapTools.values():
            if mapTool.action().isChecked():
                if not mapTool.layer().isEditable():
                    mapTool.layer().startEditing()
                self._setMapToolAttributes(mapTool)

    def _updateMapToolAttributes(self):
        for mapTool in self._mapTools.values():
            if mapTool.action().isChecked():
                self._setMapToolAttributes(mapTool)

    def _setMapToolAttributes(self, mapTool):
        if mapTool is None:
            return
        toolData = mapTool.action().data()
        self._itemFeature.blockSignals(True)
        if toolData['class'] != self._classCode():
            self._setItemId('')
        self._setClassCode(toolData['class'])
        self._setCategory(toolData['category'])
        self._itemFeature.blockSignals(False)
        mapTool.setDefaultAttributes(self.itemFeature().attributes())

    def clearDrawingTools(self):
        self._clearDrawingTools(self.pointToolLayout)
        self._clearDrawingTools(self.lineToolLayout)
        self._clearDrawingTools(self.polygonToolLayout)

    def _clearDrawingTools(self, layout):
        if layout.count():
            for i in range(layout.count() - 1, 0):
                layout.takeAt(i)

    def _addToolWidget(self, layout, toolButton, counter):
        layout.addWidget(toolButton, counter // self._colMax, counter % self._colMax, Qt.AlignCenter)

    def _addToolSpacer(self, layout):
        while layout.columnCount() < self._colMax:
            label = QLabel()
            layout.addWidget(label, 0, layout.columnCount() % self._colMax)

    def _editLayer(self, layer):
        self._iface.setActiveLayer(layer)
        if not layer.isEditable():
            layer.startEditing()
        self._iface.actionNodeTool().trigger()

    def _editPointsLayer(self):
        self._editLayer(self._collection.layer('points'))

    def _editLinesLayer(self):
        self._editLayer(self._collection.layer('lines'))

    def _editPolygonsLayer(self):
        self._editLayer(self._collection.layer('polygons'))

    def _selectLayer(self, layer):
        self._iface.setActiveLayer(layer)
        self._iface.actionSelect().trigger()

    def _selectPointsLayer(self):
        self._selectLayer(self._collection.layer('points'))

    def _selectLinesLayer(self):
        self._selectLayer(self._collection.layer('lines'))

    def _selectPolygonsLayer(self):
        self._selectLayer(self._collection.layer('polygons'))

    def _autoSchematicSelected(self):
        self.actions['sch'].trigger()
        self._autoSchematic(self.metadata, self._collection.layer('lines'), self._collection.layer('polygons'))

    def _autoSchematic(self, md, inLayer, outLayer):
        definitiveFeatures = []
        if inLayer.selectedFeatureCount() > 0:
            definitiveFeatures = inLayer.selectedFeatures()
        else:
            featureIter = inLayer.getFeatures()
            for feature in featureIter:
                if (feature.attribute('id') == self.itemId()
                        and feature.attribute('category') in self._definitiveCategories):
                    definitiveFeatures.append(feature)
        if len(definitiveFeatures) <= 0:
            return
        schematicFeatures = geometry.polygonizeFeatures(definitiveFeatures, outLayer.pendingFields())
        if len(schematicFeatures) <= 0:
            return
        schematic = geometry.dissolveFeatures(schematicFeatures, outLayer.pendingFields())
        attrs = md.feature.toAttributes()
        for attr in attrs.keys():
            schematic.setAttribute(attr, attrs[attr])
        outLayer.beginEditCommand("Add Auto Schematic")
        outLayer.addFeature(schematic)
        outLayer.endEditCommand()
        self.plugin.mapCanvas().refresh()
class ItemFeatureWidget(QWidget, Ui_ItemFeatureWidget):

    featureChanged = pyqtSignal()
    autoToolSelected = pyqtSignal()

    def __init__(self, parent=None):
        super(ItemFeatureWidget, self).__init__(parent)
        self.setupUi(self)

        self._itemFeature = ItemFeature()
        self._actions = {}
        self._mapTools = {}
        self._currentMapTool = None
        self._collection = None
        self._iface = None
        self._definitiveCategories = set()
        self._colMax = 6
        self._pointTool = 0
        self._lineTool = 0
        self._polygonTool = 0

    def initGui(self, iface, collection):
        self._iface = iface
        for key in sorted(Config.classCodes.keys()):
            classCode = Config.classCodes[key]
            if classCode['collection']:
                self.classCombo.addItem(classCode['label'], classCode['class'])

        self._addStandardTool(FeatureType.Point,
                              ':/plugins/ark/plan/editPoints.svg',
                              u'Points Node Tool', self._editPointsLayer)
        self._addStandardTool(FeatureType.Point,
                              ':/plugins/ark/plan/selectPoints.svg',
                              u'Points Select Tool', self._selectPointsLayer)

        self._addStandardTool(FeatureType.Line,
                              ':/plugins/ark/plan/editLines.svg',
                              u'Lines Node Tool', self._editLinesLayer)
        self._addStandardTool(FeatureType.Line,
                              ':/plugins/ark/plan/selectLines.svg',
                              u'Lines Select Tool', self._selectLinesLayer)

        self._addStandardTool(FeatureType.Polygon,
                              ':/plugins/ark/plan/editPolygons.svg',
                              u'Polygons Node Tool', self._editPolygonsLayer)
        self._addStandardTool(FeatureType.Polygon,
                              ':/plugins/ark/plan/selectPolygons.svg',
                              u'Polygons Select Tool',
                              self._selectPolygonsLayer)
        # TODO Make generic somehow
        if collection == 'plan':
            self._addStandardTool(FeatureType.Polygon,
                                  ':/plugins/ark/plan/addPolygons.svg',
                                  u'Auto-Schematic Tool',
                                  self._autoSchematicSelected)

        self._addToolSpacer(self.pointToolLayout)
        self._pointTool = self._colMax
        self._addToolSpacer(self.lineToolLayout)
        self._lineTool = self._colMax
        self._addToolSpacer(self.polygonToolLayout)
        self._polygonTool = self._colMax

        for feature in Config.featureCollections[collection]:
            category = Config.featureCategories[feature['category']]
            if 'query' not in category:
                category['query'] = None
            self._addDrawingTool(feature['class'], feature['category'],
                                 category['name'], QIcon(), category['type'],
                                 category['query'])
            if category['definitive'] is True:
                self._definitiveCategories.add(feature['category'])

        self.idEdit.editingFinished.connect(self.featureChanged)
        self.idEdit.editingFinished.connect(self._itemIdChanged)
        self.labelEdit.editingFinished.connect(self.featureChanged)
        self.labelEdit.editingFinished.connect(self._labelChanged)
        self.commentEdit.editingFinished.connect(self.featureChanged)
        self.commentEdit.editingFinished.connect(self._commentChanged)

        self._itemFeature.changed.connect(self._updateMapToolAttributes)

    def unloadGui(self):
        for action in self._actions.values():
            if action.isChecked():
                action.setChecked(False)

    def loadProject(self, plugin, collection):
        self._collection = plugin.project().collection(collection)
        for category in self._mapTools:
            geometryType = self._mapTools[category].geometryType()
            layer = None
            if geometryType == QGis.Point:
                layer = self._collection.buffer('points')
            elif geometryType == QGis.Polygon:
                layer = self._collection.buffer('polygons')
            elif geometryType == QGis.Line:
                layer = self._collection.buffer('lines')
            self._mapTools[category].setLayer(layer)

    def closeProject(self):
        pass

    def itemFeature(self):
        return self._itemFeature

    def setItemFeature(self, feature):
        self.blockSignals(True)
        self._itemFeature = feature
        self.blockSignals(False)

    def _classCode(self):
        return self.classCombo.itemData(self.classCombo.currentIndex())

    def _setClassCode(self, classCode):
        idx = self.classCombo.findData(classCode)
        if idx >= 0:
            self.classCombo.setCurrentIndex(idx)
            self._itemFeature.item().setClassCode(classCode)

    def _itemId(self):
        return self.idEdit.text().strip()

    def _setItemId(self, itemId):
        self.idEdit.setText(itemId)
        self._itemFeature.item().setItemId(itemId)

    def _itemIdChanged(self):
        self._itemFeature.item().setItemId(self._itemId())

    def _category(self):
        for category in self._mapTools:
            if self._mapTools[category].action().isChecked():
                return category
        return ''

    def _setCategory(self, category):
        # self._mapTools[category].action().setChecked(True)
        self._itemFeature.setCategory(category)

    def _label(self):
        return self.labelEdit.text().strip()

    def _setLabel(self, label):
        self.labelEdit.setText(label)
        self._labelChanged()

    def _labelChanged(self):
        self._itemFeature.setLabel(self._label())

    def _comment(self):
        return self.commentEdit.text().strip()

    def _setComment(self, comment):
        self.commentEdit.setText(comment)
        self._commentChanged()

    def _commentChanged(self):
        self._itemFeature.setComment(self._comment())

    # Drawing Tools

    def _addToolButton(self, action, featureType):
        toolButton = QToolButton(self)
        toolButton.setFixedWidth(30)
        toolButton.setFixedHeight(30)
        toolButton.setDefaultAction(action)
        geometryType = FeatureType.toGeometryType(featureType)
        if geometryType == QGis.Point:
            self._addToolWidget(self.pointToolLayout, toolButton,
                                self._pointTool)
            self._pointTool += 1
        elif geometryType == QGis.Line:
            self._addToolWidget(self.lineToolLayout, toolButton,
                                self._lineTool)
            self._lineTool += 1
        elif geometryType == QGis.Polygon:
            self._addToolWidget(self.polygonToolLayout, toolButton,
                                self._polygonTool)
            self._polygonTool += 1

    def _addStandardTool(self, featureType, icon, tooltip, slot=None):
        action = QAction(QIcon(icon), '', self)
        action.setToolTip(tooltip)
        action.setCheckable(False)
        action.triggered.connect(slot)
        self._addToolButton(action, featureType)

    def _addDrawingTool(self,
                        classCode,
                        category,
                        toolName,
                        icon,
                        featureType,
                        query=None):
        data = {}
        data['class'] = classCode
        data['category'] = category
        action = QAction(icon, category, self)
        action.setData(data)
        action.setToolTip(toolName)
        action.setCheckable(True)

        mapTool = MapToolAddFeature(self._iface, featureType, toolName)
        mapTool.setAction(action)
        mapTool.setPanningEnabled(True)
        mapTool.setZoomingEnabled(True)
        mapTool.setSnappingEnabled(True)
        mapTool.activated.connect(self._mapToolActivated)
        if query is not None:
            field = Config.fields[query]
            mapTool.setAttributeQuery(field['attribute'], field['type'],
                                      field['default'], field['label'],
                                      field['query'], field['min'],
                                      field['max'], field['decimals'])

        self._addToolButton(action, featureType)
        self._actions[category] = action
        self._mapTools[category] = mapTool

    def _mapToolActivated(self):
        for mapTool in self._mapTools.values():
            if mapTool.action().isChecked():
                if not mapTool.layer().isEditable():
                    mapTool.layer().startEditing()
                self._setMapToolAttributes(mapTool)

    def _updateMapToolAttributes(self):
        for mapTool in self._mapTools.values():
            if mapTool.action().isChecked():
                self._setMapToolAttributes(mapTool)

    def _setMapToolAttributes(self, mapTool):
        if mapTool is None:
            return
        toolData = mapTool.action().data()
        self._itemFeature.blockSignals(True)
        if toolData['class'] != self._classCode():
            self._setItemId('')
        self._setClassCode(toolData['class'])
        self._setCategory(toolData['category'])
        self._itemFeature.blockSignals(False)
        mapTool.setDefaultAttributes(self.itemFeature().attributes())

    def clearDrawingTools(self):
        self._clearDrawingTools(self.pointToolLayout)
        self._clearDrawingTools(self.lineToolLayout)
        self._clearDrawingTools(self.polygonToolLayout)

    def _clearDrawingTools(self, layout):
        if layout.count():
            for i in range(layout.count() - 1, 0):
                layout.takeAt(i)

    def _addToolWidget(self, layout, toolButton, counter):
        layout.addWidget(toolButton, counter // self._colMax,
                         counter % self._colMax, Qt.AlignCenter)

    def _addToolSpacer(self, layout):
        while layout.columnCount() < self._colMax:
            label = QLabel()
            layout.addWidget(label, 0, layout.columnCount() % self._colMax)

    def _editLayer(self, layer):
        self._iface.setActiveLayer(layer)
        if not layer.isEditable():
            layer.startEditing()
        self._iface.actionNodeTool().trigger()

    def _editPointsLayer(self):
        self._editLayer(self._collection.layer('points'))

    def _editLinesLayer(self):
        self._editLayer(self._collection.layer('lines'))

    def _editPolygonsLayer(self):
        self._editLayer(self._collection.layer('polygons'))

    def _selectLayer(self, layer):
        self._iface.setActiveLayer(layer)
        self._iface.actionSelect().trigger()

    def _selectPointsLayer(self):
        self._selectLayer(self._collection.layer('points'))

    def _selectLinesLayer(self):
        self._selectLayer(self._collection.layer('lines'))

    def _selectPolygonsLayer(self):
        self._selectLayer(self._collection.layer('polygons'))

    def _autoSchematicSelected(self):
        self.actions['sch'].trigger()
        self._autoSchematic(self.metadata, self._collection.layer('lines'),
                            self._collection.layer('polygons'))

    def _autoSchematic(self, md, inLayer, outLayer):
        definitiveFeatures = []
        if inLayer.selectedFeatureCount() > 0:
            definitiveFeatures = inLayer.selectedFeatures()
        else:
            featureIter = inLayer.getFeatures()
            for feature in featureIter:
                if (feature.attribute('id') == self.itemId()
                        and feature.attribute('category')
                        in self._definitiveCategories):
                    definitiveFeatures.append(feature)
        if len(definitiveFeatures) <= 0:
            return
        schematicFeatures = geometry.polygonizeFeatures(
            definitiveFeatures, outLayer.pendingFields())
        if len(schematicFeatures) <= 0:
            return
        schematic = geometry.dissolveFeatures(schematicFeatures,
                                              outLayer.pendingFields())
        attrs = md.feature.toAttributes()
        for attr in attrs.keys():
            schematic.setAttribute(attr, attrs[attr])
        outLayer.beginEditCommand("Add Auto Schematic")
        outLayer.addFeature(schematic)
        outLayer.endEditCommand()
        self.plugin.mapCanvas().refresh()