7

I noticed that after joining a table to a shapefile the headers of each fields in the table used for the join are changed by QGIS and they are attributed to a different name.

For instance, I had a shapefile with vegetation_codes and a table with vegetation_codes and veg_definition (these were the headers). After joining the table to the shapefile and also saving the shapefile and creating a new one, the vegetation_classes header was changed into vegetati_1.

Is there a way to keep the original headers?

I am using QGIS Dufour on Windows 7 and the table that I join to the shapefile is CSV (tried with dbf as well and the problem is the same).

1

2 Answers 2

7

No, you cannot keep the original names. The problem is that DBF files and therefore Shapefile attribute tables have a limit of 10 characters for the column names.

When you join two layers, QGIS constructs new attribute names by combining layer and attribute names of the joined layer. To ensure unique column names, QGIS further adds a running number to the end of the name.

You'll have to rename the columns in the resulting file manually. The Table Manager plugin allows easy renaming.

6
  • 1
    thank you Underdark. I use already that plugin and it is actually very handy. Just a curiosity, do you think that in the future QGIS will be able to keep the headers as they are? If the joined table is large it may take a while to rename the fields. i guess that probably is not a high priority but to be honest an improvement in the join can be very handy and reduce time of the data analysts. thanks Commented Nov 25, 2013 at 18:42
  • @ilariamarengo No. QGIS cannot decide to change the Shapefile specification. It is what it is.
    – underdark
    Commented Nov 25, 2013 at 19:09
  • OK, I see this point, although if you keep the headers of 10 characters still it would be nice not to have them "renamed" and be in the position of rechanging the names. Commented Nov 25, 2013 at 19:55
  • 2
    QGIS pre 2.0 did not do any renaming. This resulted in many issues since most layer will have a column "name" and/or "id" and those won't be unique anymore after the join..
    – underdark
    Commented Nov 25, 2013 at 20:34
  • A custom mapping option would be nice though.
    – Chau
    Commented Jan 14, 2015 at 13:13
3

I had the same problem and figured out a solution with the 'processing modeler' from QGIS 2.6. Weird enough: in the resulting shapefile, the original columnnames from the .dbf are kept!

How to use the processing modeler?

With the processing modeler you can automate whatever geoprocessing, analysis, datamanagement, etc you do within the usual QGIS environment. In this case I want to join a table to a shapefile and save it as a new shapefile to get an extended attributetabel.

Within QGIS first I have to load a shapefile and the table I want to join with.Then I have to perform that join by entering the Layer Properties and define the joinspecifications under the tab join. Then I have rightclick the shapefile and choose 'save as', fill in a dialogue window and enter the specifications. Then I need to rename all the added fields because they are renamed to obtain unique fieldnames. A lot of work if you have to do a lot of them.

Within the processsing modeler you only have to add these steps once. After saving the model you can easely re-use it.

Enter the processing modeler through processing > graphical modeler

(afbeelding1)

You get something like this

enter image description here

Activate the tab Input as shown above. Double click 'Vector layer', you get:

(afbeelding 3)

Fill in a descriptive name: eg. original shapefile.

Double click 'Table field', you get:

enter image description here

Fill in a descriptive name: eg. Field to join with. The parent Layer is automaticly set because you only have one input added.

Double click 'Table' and give it a descripive name: eg. table to be joined.

Double click 'Table field', fill in a descriptive name: eg. joinfield. Check if the parent Layer is set correctly to the name you gave to the table.

Untill now you only have defined the needed features: shapefile, table and their corresponding unique fields.

Now we have to define the algorithm. Open the 'Algorithms' tab.

enter image description here

Here you find all the scripts an algorithms that are used within the 'normal' QGIS-interface. To easely find the right algorithm, enter a description in the searchfield.

(afbeelding6)

Double click on 'join attributes table'. You get a dialogue window where you have to define the right parameters as shown.

enter image description here

When you enter a name under 'output layer', you will be asked to add a name and location for the new shapefile that will be created.

Press 'ok'.

Now you can see in the right panel the relations between the inputfields, the algorithm and the output.

enter image description here

Give your model a name and save it.

Now you can test the model by running it. Press enter image description here.

Select the shapefile, table and corresponding fields.

enter image description here

Press 'Run' and see if everything goes fine. If not, you can change parameters in the processing modeler and try it again.

The nice thing about the models is that you can run them in batchmode. Open the toolbox ! enter image description here

Right click your model and choose enter image description here

You can now run different joins at the same time.

enter image description here

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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