6

As I digitized stuff manually from a raster map and I have a list of all needed features, I want to compare tables.

One complete CSV or Excel, for illustration:

Feature_Code Fruit Disabled
TH1 Banana Yes
TH2 Apple No
TH3 Cherry No

One GeoPackage Table, with missing Feature Codes:

Feature_Code Fruit Disabled
TH1 Banana Yes
TH3 Cherry No

I want to know what "Feature_Code" are not mapped / missing. Here: 'TH2'.

So far, I searched QGIS and here for any "compare" "table" functions/questions. I also read the QGIS Documentation on Attribute tables.

How do I do this?

0
6

"Join attributes by field value" does exactly what you're looking for.

Hand it your CSV first and the GeoPackage second. Choose the fields containing the matching "ID"s.

The join type is probably irrelevant, but you need to make sure the tool provides you with the second, optional output, the list of features from the first layer which couldn't be joined.

enter image description here

4

You can aggregate the "Feature_Code" fields of both layers in an array, then compare the arrays to see which element from the CSV array is missing in the GeoPackage array.

Use this expression on the CSV layer and replace point with the name of your GeoPackage layer:

array_to_string(
    array_remove_all(
        array_replace(
            array_agg("Feature_Code"),
            aggregate('point', 'array_agg', "Feature_Code"),
            ''
        ),
    '')
)

Screenshot: Output of the expression is 'TH2': the value missing in the layer point:

enter image description here

4

You can also use PyQGIS:

#Change the layer- and fieldnames below
complete_table = QgsProject.instance().mapLayersByName('ok_ak_riks')[0]
missing_table = QgsProject.instance().mapLayersByName('ok_ak_riks_sample')[0]
id_column = 'kom_kod'

not_all_records = [f[id_column] for f in missing_table.getFeatures()] #List all records in the new table

for f in complete_table.getFeatures():
    if f[id_column] not in not_all_records: #If some record isnt in the listed records
        print('{0} is missing'.format(f[id_column])) #Print it

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.