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?
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:
<aliases> <alias field:"test" index="2" name="HEREISMYNEWNAME"/> </aliases>
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.
- Create several aliases in the layer Properties dialog
- Save the project file as a QGS file
- Open the project file in a text editor, eg Notepad++
- Search (ctrl-f) the project file for one of the aliases you created (in my example, it's "ThisIsMyAliasIsntItPretty")
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
<maplayerand ending with
</maplayer>. Mine look like this:
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.
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.
Add the start and end tags
</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.