Skip to main content
14 votes
Accepted

Getting unique values from multiple fields as matched using PyQGIS

You can use set() which is a Python built-in function. layer = iface.activeLayer() pairs = list(set([(f["Code"], f["Color"]) for f in layer.getFeatures()])) print(pairs) # [('...
Noura's user avatar
  • 3,439
11 votes

Deleting features with identical table attributes in QGIS

For future reference: the next version of QGIS (3.6) includes a built-in 'Delete duplicates by attribute' tool which does exactly this.
ndawson's user avatar
  • 27.9k
10 votes

Showing only one label for multiple points with same value in QGIS

If a Virtual layer through Layer > Add Layer > Add/Edit Virtual Layer is an option: SELECT id, st_pointonsurface(st_union(geometry)) FROM your_layer GROUP BY id will place a point around the ...
Kazuhito's user avatar
  • 31.2k
10 votes
Accepted

Showing only one label for multiple points with same value in QGIS

I assume that you have multiple features with the same ID and not real multipoint. If needed there is also a solution with real multipoint, let me know. You can add an integer field to your shapefile ...
YoLecomte's user avatar
  • 3,340
10 votes

Getting unique values from multiple fields as matched using PyQGIS

You can use the class Counter() from the collections module. from collections import Counter layer = iface.activeLayer() c = Counter([(feat['Code'],feat['Color']) for feat in layer.getFeatures()]) ...
Vincent Bré's user avatar
  • 4,120
10 votes
Accepted

Auto incremental field filled with filtered by other field value in QGIS Attribute Form

You need to specify the second parameter group_by as "CATEG" for the maximum() function. if(maximum("ORDER", "CATEG") is NULL, 1, maximum("ORDER", "CATEG&...
Kadir Şahbaz's user avatar
9 votes
Accepted

Adding auto incremented value to existing ID

Assuming "maintenance_ID" field is already given, I would use Add autoincremental field tool (in Processing Toolbox > Vector table) to prepare a temporary field, then put them together. (...
Kazuhito's user avatar
  • 31.2k
9 votes

Counting values of each classification code using QGIS

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 ...
alphabetasoup's user avatar
9 votes

Counting values of each classification code using QGIS

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 ...
ThomasG77's user avatar
  • 31.2k
8 votes

Getting unique values in a QGIS Expression

You must use array_agg: array_distinct(array_agg( "cab_no" )) This will return an array with distinct values found in your layer with the field cab_no.
etrimaille's user avatar
  • 7,447
8 votes
Accepted

Adding consecutive unique ID for distinct value sets and sorting by date

This expression should do what you need: array_find(array_foreach(array_distinct(array_sort(array_agg("Date"||'§'||"info"))),regexp_replace(@element,'([0-9]+)-+([0-9]+)-+([0-9]+§)',...
MrXsquared's user avatar
  • 35.6k
8 votes

Counting values of each classification code using QGIS

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 ...
Leigh Bettenay's user avatar
7 votes
Accepted

Extracting attributes list with unique values from QGIS Attribute table

The following tool will output a file containing all unique values in a column. Vector > Analysis Tools > List unique values. Select the input layer Click the ellipsis within Target field(s). ...
Stu Smith's user avatar
  • 8,356
6 votes

QGIS List Unique Values tool only exports to .html format

Go to DB Manager -> Virtual Layers -> QGIS layers, click on SQL Window button (or press F2), and write the next SQL expression: SELECT DISTINCT your_field FROM your_layer ORDER BY your_field; ...
Germán Carrillo's user avatar
5 votes
Accepted

Unique List of Image Dates from Image Collection in Google Earth Engine

You can find out how many images are available per date with the frequencyHistogram reducer. Script with example roi. var ymd = ymdList(landsat) print(ee.List(ymd).reduce(ee.Reducer....
Kersten's user avatar
  • 9,947
5 votes

How to run for loop with unique values

Although Hornbydd is absolutely correct (+1 for that by the way), the first part of the question is to loop through all the unique values in a field.. this snippet should be usable in your existing ...
Michael Stimson's user avatar
4 votes

Adding consecutive unique ID for distinct value sets and sorting by date

You can execute the following code in the Python Console of QGIS: # Your layer your_layer = iface.activeLayer() # Unique values for your Date field stored in a list (adapts the name of your field) ...
Vincent Bré's user avatar
  • 4,120
4 votes
Accepted

Getting unique values in a QGIS Expression

The filter expression requests a true/false output. The function array_distinct() gives you an array with distinct values as an output, plus you need to use array_agg first, as @etrimaille pointed out....
nepluisse's user avatar
  • 628
4 votes

Keep unique names of places

A tip is to use the QGIS tool Dissolve tool by specifying province as the grouping field. This operation makes it possible to switch from simple polygon geometry to multi-polygon geometry. Then, you ...
Vincent Bré's user avatar
  • 4,120
4 votes

Showing only one label for multiple points with same value in QGIS

Another option is to use "Collect Geometries" under the Vector->Geometry Tools menu. Then choose the field to group them by. This will create multipart geometries with one table record ...
SDNX's user avatar
  • 81
4 votes
Accepted

Create attributes from unique values of another features classes category attribute with FME

The simplest way to create the attribute is to use an AttributeManager and use the value of the landuse_category attribute as the name of the new attribute: When you write that (and I'm using plain ...
Mark Ireland's user avatar
  • 13.2k
4 votes

Counting values of each classification code using QGIS

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[...
Bera's user avatar
  • 77.8k
4 votes

Counting values of each classification code using QGIS

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 ...
Babel's user avatar
  • 74.9k
4 votes

Using Save symbol to style for layer with Unique Values style in ArcGIS Pro

I think you are getting confused with the terminology; in your screen shot above you show an option to save a symbol to a style. The key point here it is a symbol, note it's in the singular. If you ...
Hornbydd's user avatar
  • 44.6k
4 votes
Accepted

number the soil_unit_code in a soil_id column

Use this expression: array_find (array_distinct (array_agg("soil_unit_code")), "soil_unit_code") Explanation: With array_agg (array aggregate), you get a list (array) of all ...
Babel's user avatar
  • 74.9k
4 votes
Accepted

Changing Widget type to 'Unique Values' and making it editable using PyQGIS

Try this: layer = iface.activeLayer() # start with a list of your fields to edit mt20_fields = ['POINT_ADDR', 'STEET_ROAD', 'LANDMARK'] # fields must be iterated through: for field in mt20_fields: ...
Andre Geo's user avatar
  • 801
3 votes

How to run for loop with unique values

If you read the help file for this tool and look at the syntax section what does it takes as input? A Feature Layer. Unlike a Feature Class, you can do selections on Feature Layers. As all geo-...
Hornbydd's user avatar
  • 44.6k
3 votes

Deleting features with identical table attributes in QGIS

In QGIS 3, you could use 'Add autoincremental field' tool to distinguish the identical set of attribute fields. If your ABC field holds A, B, ... and mnp field holds m, p, ... like below image; ...
Kazuhito's user avatar
  • 31.2k
3 votes
Accepted

Automatically style raster using unique values in QGIS?

For those still looking for this. Unique raster values have been added to QGIS 3. "Added by Nyall Dawson about 1 year ago [FEATURE] Allow classifying paletted renderer using unique values from a ...
Baswein's user avatar
  • 2,396
3 votes

Naming polylines in sequences from left to right (west to east) using QGIS

You can try the 'Add autoincremental field' with x(centroid($geometry)) expression for a 'Sort expression', see image below
Taras's user avatar
  • 34k

Only top scored, non community-wiki answers of a minimum length are eligible