New answers tagged

1

After some search I finally found a working solution: As I saw that layer.maximumValue(idx) always kept the same value until I commited changes, I added the number of new elements and that are pending to be commited to this variable. This way I always get serial (autonumeric) number. Idea taken from here: def openProject(): from qgis.core import ...


3

Nice question! Say that you have a vector layer referenced: lyr = iface.activeLayer() At this point, I assume you start an edit session and digitize some features. Now you can use the QgsVectorLayerEditBuffer class, in this way: if lyr.editBuffer(): print len( lyr.editBuffer().addedFeatures() ), "features to add!" addedFeatures gives you a ...


1

To fix the error: NameError: global name 'QgsMapLayerRegistry' is not defined Just add the following at the top of your script: from qgis.core import QgsMapLayerRegistry Tip: What I do normally when I receive similar errors is to type the class into the Python Console. It will then provide you with a list of classes and libraries in which they ...


0

Try using an expression like this: left( "STRNAME", strpos( "STREET", "STRNAME") )


1

check this: from PyQt4.QtCore import * from PyQt4.QtXml import * myFile = "PATH_TO_COMPOSER_TEMPLATE" myTemplateFile = file(myFile, 'rt') myTemplateContent = myTemplateFile.read() myTemplateFile.close() myDocument = QDomDocument() myDocument.setContent(myTemplateContent, False) newcomp = iface.createNewComposer() ...


5

You can use something like the following: layer = qgis.utils.iface.activeLayer() provider = layer.dataProvider() ext = layer.extent() stats = provider.bandStatistics(1,QgsRasterBandStats.All,ext,0) print "minimum value = ", stats.minimumValue print "maximum value = ", stats.maximumValue print "mean = ", stats.mean print "stdDev = ", stats.stdDev Here ...



Top 50 recent answers are included