I have a geodatabase with all of my data, but I would like to add more friendly aliases from a separate key I have stored in a CSV. How do I go about adding these aliases to my field names in my geodatabase?

  • Just to make sure I understand your question, are you looking to display alternate field values (ie the contents of each cell in the attribute table) or field names (ie the header of each column in the attribute table)? – csk Mar 19 at 16:19

According to the QGIS manual, aliases are stored in the project file.

You can define some alias to display human readable fields in the feature form or the attribute table. In this case, you don’t need to switch to editing mode. Alias are saved in project file.

According to the answers to this question: Save a selection in QGIS and keep the alias of field names?, Field aliases can also be stored as a qml style file. The HTML code for aliases in a QML file looks like this:

  <alias field:"test" index="2" name="HEREISMYNEWNAME"/>

(code sample from this answer by ed.hank)

So you just need to convert your CSV of aliases to that format, and insert it into a QML file for the layer, or into the project file. AFAIK, no one has yet created a plugin or other tool to do this for you.

Here are instructions for inserting aliases from a CSV file into the QGIS project file.

The procedure for putting them in a QML file would be similar.

First we create some test alias the regular way, to figure out the appropriate format and location for inserting them into the QGS file.

  1. Create several aliases in the layer Properties dialog

enter image description here

  1. Save the project file as a QGS file
  2. Open the project file in a text editor, eg Notepad++
  3. Search (ctrl-f) the project file for one of the aliases you created (in my example, it's "ThisIsMyAliasIsntItPretty")

enter image description here

  1. Copy the corresponding lines of code. Make a note of where they are in the project file. They should be in a code section corresponding to the map layer, starting with <maplayer and ending with </maplayer>. Mine look like this:

  2. Convert your CSV into the format of these lines in a text file.

    Eg, in Excel you can use the ampersand & to concatenate text. I divided the html code into sections, and put each section into a spreadsheet between the fields "Alias", "FieldName" and "FieldIndex". Then joined all the cells in each line together with the formula =A2&B2&C2&D2&E2&F2&G2, and copied it down the column.

    enter image description here

    There are probably better ways to do this. If anyone knows a better way, please mention it in the comments or post as an answer.

  3. Add the start and end tags <aliases> and </aliases>. Insert your code into the project file, replacing the code for the aliases you created manually.

Note: Be sure to back up your project file before you attempt this.

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.