コード例 #1
0
 def addLinePolygon(self, attributes):
     ''' Add the new line or polygon and display '''
     # debugging
     print "AddLinesPolygons.addLinePolygon() starting"
     # Set the data provider
     self.provider = self.mainwindow.provider
     # make a list of the original points in the active layer
     self.originalFeats = shared.listOriginalFeatures(self.provider)
     # need to update the mainwindow instance variable for call to Tools.shared.deleteEdits
     self.mainwindow.originalFeats = self.originalFeats
     
     feat = QgsFeature()
     vlayerName = self.mainwindow.activeVLayer.name()
     # add the line or polygon geometry to the feature
     feat.setGeometry(self.rubberBand.asGeometry())
     feat.setAttributeMap(attributes)
     # this actually writes the added point to disk!
     # the space between parentheses, brackets and the parameter are needed!
     try:
         self.provider.addFeatures( [ feat ] )
     except (IOError, OSError), e:
         error = unicode(e)
         print error                    
         QtGui.QMessageBox.warning(self, "Failed to add feature(s)", "Please check if "
                              + vlayerName + " is open in another program and then try again.")
コード例 #2
0
ファイル: addpoints.py プロジェクト: bobenglish/testing_Git
 def markPoint(self, attributes):
     ''' Add the new feature and display '''
     # debugging
     print "markPoint starting"
     # set the current provider
     self.provider = self.mainwindow.provider
     # make a list of the original points in the active layer
     self.originalFeats = shared.listOriginalFeatures(self.provider)
     # need to update the mainwindow instance variable for call to Tools.shared.deleteEdits
     self.mainwindow.originalFeats = self.originalFeats
     
     feat = QgsFeature()
     vlayerName = self.mainwindow.activeVLayer.name()
     # add the point geometry to the feature
     feat.setGeometry(QgsGeometry.fromPoint(self.qgsPoint))
     feat.setAttributeMap(attributes)
     # this actually writes the added point to disk!
     try:
         self.mainwindow.provider.addFeatures( [ feat ] )
     except (IOError, OSError), e:
         error = unicode(e)
         print error                    
         QtGui.QMessageBox.warning(self, "Failed to add feature(s)", "Please check if "
                              + vlayerName + " is open in another program and then try again.")