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) # [('...
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.
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 ...
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 ...
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()])
...
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&...
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.
(...
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 ...
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 ...
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.
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]+§)',...
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 ...
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). ...
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;
...
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....
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 ...
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)
...
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....
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 ...
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 ...
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 ...
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[...
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 ...
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 ...
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 ...
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:
...
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-...
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;
...
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 ...
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
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
unique-value × 63qgis × 23
symbology × 13
arcgis-desktop × 11
arcgis-pro × 10
fields-attributes × 9
raster × 7
arcpy × 5
attribute-table × 5
pyqgis × 4
point × 4
field-calculator × 3
labeling × 3
layers × 3
qgis-processing × 3
python × 2
arcmap × 2
shapefile × 2
qgis-3 × 2
google-earth-engine × 2
export × 2
spatial-join × 2
classification × 2
expression × 2
select-by-attribute × 2