New answers tagged

6

You set feature fields to empty QgsFields. fields = QgsFields() # fields is empty feature.setFields(fields) # you set the empty fields Instead, pass layer.fields() to QgsFeature. feature = QgsFeature(layer.fields()) You also get NULL values, because you add the feature to the layer (provider.addFeatures([feature])) before you populate the fields. Use this ...


4

I have had this problem too. You have: vl = QgsVectorLayer("Polygon?crs=EPSG:2193", "Polygons", "memory") Maybe add the attribute definitions into the uri. uri = 'LineString?crs= EPSG:2193&field=id:integer&field=name:String(40)&field=age:double' layer = QgsVectorLayer(uri, "Polygons", "memory") ...


4

Personally, I prefer to use the changeAttributeValues() method of QgsVectorDataProvider (see API docs here) as I find it more reliable. This method takes an attributes map which is basically a dictionary where the key is a feature id and the value is a second dictionary comprising field indexes as keys and the new attributes as values. I have tested this ...


1

You can get the From value for the maximum "Ni_ppm_1" value per unique "Hole-id" with this expression: attribute ( get_feature ( @layer, 'Ni_ppm_1', maximum( "Ni_ppm_1", group_by:="Hole_id" ) ), 'From' ) Replace 'From' in the second last line with '...


5

You can use the maximum() function together with the array_agg() function to achieve this: array_get( with_variable('max_ppm', maximum("Ni_ppm_1", group_by:="Hole_id"), array_agg(expression:="Ni_ppm_1" || '-' || "From" || '-' || "To", ...


4

One example: lyr = iface.activeLayer() feats = [f for f in lyr.getFeatures()] #List all features #names = [f['KOMMUNNAMN'] for f in feats] #List values in KOMMUNNAMN field #['Kiruna', 'Pajala', 'Gällivare', 'Jokkmokk', 'Boden'] fieldindex = lyr.fields().indexFromName('KOMMUNNAMN') attrMap = {} for f in feats: attrMap[f.id()] = {fieldindex:f['...


3

A short and easy way is to use QGIS expressions: Simple expression with repeated calculation count( landfire classification, group_by:=landfire classification) Replace landfire classification with the name of the attribute you use for classification. For the simple version, you're done. See in what follows for some more options. Where to use the expression ...


9

Use built-in Processing algorithm "Statistics by Categories" available in the Processing Toolbox like below. It will return in a new layer the categories and count for selected field. It can also be called through PyQGIS layer = iface.activeLayer() result = processing.run("qgis:statisticsbycategories", { 'INPUT':layer, # Can be a ...


4

You can also use PyQGIS: from collections import Counter layer = QgsProject().instance().mapLayersByName('ok_bs_riks')[0] #Change to match your layername fieldname = 'kkod' #Change c = Counter((val[fieldname] for val in layer.getFeatures())) for key, val in c.items(): print(key, val)


3

I just found out, I could use the vertex tool of the editing toolbar: acitivate the editing mode. activate the vertex-editing-mode right-click on the point insert the new coordinates


6

You can also use the "Group Stats" Plugin. Install it and then choose Vector -> Group Stats. Choose your input file, drag "Count" into the Columns box, drag your categorical field into the Rows box and another field like "id" into the "Value" box. Then Press Calculate. You will get a table showing each unique value ...


7

If you symbolise a layer by your chosen attribute, and then right click the layer in the list of layers, you can select "Show Feature Count". This will then calculate and display a number next to each category, which indicates how many features are in that category.


1

The aggreagate formula don't work well in the layout, I have faced this issue also. The solution I found is to do it in two steps, first creating a virtual field and then show in the layout a table with one cell. Create a virtual field in your layer that will contain the total of the area in your layer. Here is the formula : aggregate( @layer , 'sum', $area ...


3

You can create a specific widget for a specific field to add to the attribute form when it appear. This solution is based on this code by Alexandre Neto and the accepted answer of this post, How to set and configure a value relation edittype in QGIS 2.14? by Matthias Kuhn. Here is the code : my_vector_layer = iface.activeLayer() #layer you want to add ...


3

The Vector - Geoprocessing Tools - Buffer tool in QGIS is applied to all features in a layer. Buffered features can also be dissolved, so that overlapping buffers are not created, if required. This reduces the number of features in the output. The number of items in the attribute table will reflect this.


5

I used this code by Alexandre Neto and this answer to Value map from database in QGIS 3 to provide my answer. Here is a code that works for me : layername = "test_data" layer = QgsProject.instance().mapLayersByName(layername)[0] field = "bezirk" list_values = {"Bezirk 1":1, "Bezirk 2":2} def field_to_value_map(...


2

The easiest way is using the underdog Geo Interface: layer = iface.activeLayer() for feature in layer.getFeatures(): attributes = feature.__geo_interface__["properties"]


6

Assuming you have an Excel-Sheet called BirdLookup containing the three columns LookupBird, LookupScientific and LookupAbbrevation with no geometry and a Pointlayer with the three columns Bird, Scientific and Abbrevation, you can do it like below First, create a relation: Go to Project --> Properties --> Relations. Click on + Add Relation Set it up ...


5

You can use a virtual field (using field calculator) and define it's content with an expression like this: if (name = 'Robin', 'Erithacus rubecula', '') where name is the name of the attribute field where you enter "Robin". So every time you enter "Robin" in the field name, the field defined with this expression will return "...


3

If you want the table to dynamically change its location relative to other objects (including growing from the bottom), you have to: Set the "Reference point" to the bottom part. Set the dynamic height of table1 and table2 in the Position and Size settings using the following expression: 6.2 + 6.2 * (1 + aggregate(layer:='table2', aggregate:='...


0

Attribute table shows features controlled by Atlas if relation between tables has been done. Relations are defined in Project properties. Then on Atlas must select 'Relation children'.


1

I have two solutions that could work : if your cell height don't vary too much. if your label need to appear only in one atlaspage, or in all atlaspage but not on two atlaspages. You still use the table but make multiple "cadre" (sorry I don't know the English name, it is just above position and size). This is normally used when you have a table ...


1

The short answer is no, you cannot edit that pop up. You would typically write your description about your field, what it means, how it was calculated, any limitations on the values etc etc in the metadata for that field. I do this a lot and really should be best practise by all GIS users. To add your important information go to the dataset in the Catalog ...


Top 50 recent answers are included