New answers tagged

2

Although it seems a bug in my opinion (see my comment), you can bypass it using the following (tested) layer.setRenderer(layer.renderer().clone())


2

Here a standalone recipe. We've seen you are using "Rule-based" symbology. Instead of doing the case for this particular case, we've made the sample for "Single Symbol" and at the end made the transformation to "Rule-based" symbology iface.addVectorLayer('https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/...


0

Another approach using QgsPoint and QgsPolyline, a list of QgsPoints (standalone script using a memory layer but you should replace vl with the reference to your own layer) vl = QgsVectorLayer("LineString", "temp", "memory") pr = vl.dataProvider() with edit(vl): pr.addAttributes([QgsField("id", QVariant.Int)]) ...


1

When I run the following code in the Python console of QGIS, the dialog window has the same behavior as the dialog windows in the processing toolbox. dlg = QDialog(iface.mainWindow()) dlg.show() You can achieve this by giving the dialog a parent (here, the main window of QGIS). A child dialog always stays on top of its parent window.


0

I found an interesting implementation of QgsMapToolIdentifyFeature here


3

You should change your code by replacing def onFeatureIdentified(feature): with def onFeatureIdentified(self, feature): If I'm not wrong your onFeatureIdentified is a method of your plugin: it expects something like def myfunction(self, arg1, arg2, ...):


0

Instead of comparing every feature with the keys in the dictionary, I saved the whole dictionary as a csv and simply used the QGIS algorithm Join Attribute Table (probably some SQL plays its part here as well!?) to join the csv to the vector. #create csv from dictionary os.chdir(Output_Ordner) header_list = ["keys", "values"] ...


2

Add the following script as a new function: (How to add custom function) from qgis.core import * from qgis.gui import * total=0 @qgsfunction(args='auto', group='Custom') def cumulative_sum(field, feature, parent): global total total += feature[field] return total Then you can use it in Expression tab: cumulative_sum('comp') # don't use double ...


0

Two points: Look at the following methods as I'm not sure you should use setClassificationField (PS: not certain as only supposed from the API doc) dr.setClassificationAttributeExpression(strExp) dr.setClassificationAttributeIsExpression(True) The part that calculate the value for the "Find" button should be the following. It's a port of the C++ ...


1

You can use below recipe layer = iface.activeLayer() fieldName = 'ADM0_A3' # Change fieldIndex = layer.fields().indexFromName(fieldName) categories = [] for u in layer.uniqueValues(fieldIndex): symbol = QgsSymbol.defaultSymbol(layer.geometryType()) category = QgsRendererCategory(u, symbol, str(u)) categories.append(category) renderer = ...


4

Add the following lines to save the map as image. This is a minimal solution. Add these lines to __init__ method: self.actionSaveAsImage = QAction("Save As Image", self) self.actionSaveAsImage.triggered.connect(self.saveAsImage) self.toolbar.addAction(self.actionSaveAsImage) And add this as a new method to the class: (change image path) def saveAsImage(...


0

So here's the complete code to achieve what I wanted : couche = self.dlg.mMapLayerComboBox_2.currentText() champ = self.dlg.mFieldComboBox.currentText() path = self.get_enregistrement() p = path + "/" + datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') + "_" + couche + "_" + champ os.makedirs(p) #separation de la couche active par le champ defini ...


1

So despite the very elaborate answer by fastest which for some reason didn't work for QVariant.Integer and QVariant.Double I ended up using a simpler solution. It might be a bit hacky but it's a classical case of "works-for-me": def replace_nulls(layer): with edit(layer): for feat in layer.getFeatures(): for field in feat.fields()....


1

So is it possible to save a loaded CSV layer as temporary shapefile with PyQGIS? If so, how can this be done? Yes, it's possible to copy from your CSV to memory layer with QGIS 3. You can find below a recipe. # Here we take the selected layer but you may want to get it through another way original_layer = iface.activeLayer() csv_provider = original_layer....


2

one way I found to solve the issue of replacing the NULL values with zeros or similar values is the following: I define a function that maps the NULL value to some other value of choice, depending on the QVariant type: def map_null_to_zero(qvariant_type): if qvariant_type == QVariant.Invalid or qvariant_type >= QVariant.Int and qvariant_type <= ...


Top 50 recent answers are included