3

I have a polygon layer patches in QGIS. I joined with attributes from an attributes table, where the column names are relatively large. Then I save the polygon layer as patches.new.

When opening patches.new, everything seems fine except for the fact that the column names appear to be abbreviated. Is there a way to omit abbreviation when saving a shapefile in QGIS? I tried different encondings, it didn't help. So I suppose there must be something I missed...

3
  • 2
    For shapefiles in particular, the .dbf format limits field names to 10 characters. You can read more about some more limitations here. But you can allow QGIS to give your fields an alias which can display a field with a name exceeding 10 characters. You can do this by right-clicking your layer and going to Layer Properties > Fields > Alias.
    – Joseph
    Commented Nov 22, 2017 at 10:12
  • 2
    @Joseph one remark I would make: The alias is stored in the style file So if you save the shapefile you will still get the "old" names without the alias. I will update my answer to reflect that.
    – LaughU
    Commented Nov 22, 2017 at 10:24
  • As @LaughU stated: when I set alias and store the file, I only get the "old " names without alias in the resulting patch.new-file. As the list of attributes is rather long, I'd prefer not having to rewrite all alias. In many cases, the attributes even begin with a similar string, so that I'd even have to guess whether "Chorthip_1" is Chorthippus biguttlus or Chorthippus bruneus.
    – yenats
    Commented Nov 22, 2017 at 13:48

1 Answer 1

2

When joining two layers, you can set a prefix for the joined attribute fields. The standard is the name of the joined layer. This ensures, that all fields will be joined together. In addition to that, shapefiles field names are restricted to 10 characters.

Thus the field "meaningful_fieldname" from a layer "my_long_layername" will be something like "my_long__1" which is not meaningful at all.

A solution could be, that you set the Coustum field name prefix under Joins as something like "_" as shown in the image which will result in "_meaningfu"

enter image description here

EDIT:

Ss Joseph suggests using an alias will make the names readable again and will show in the Label and styling tabs of the layer context menu. However, they are not preserved with a simple Save as.. command in QGIS. You need to either save a style file or define the default style with the alias in the style menu.

enter image description here

Edit2:

The workflow for the whole process could be something like this:

  • Join your table and the shapefile
  • Save the layer with the joined fields.
  • Set the style and the alias for the fields
  • follow my first edit to save this as a default styling
  • Result: Now when you load the data the styling and the aliases should be preserved (tested with QGIS 2.18.13)

A funny sidenote: When you choose a long alias, it will be correctly displayed in the drop-down menu for style and labels but the old name will be displayed when selected.

6
  • Yes, when "meaningful_fieldname" is short enough, this works. However, it won't help in my case - I have scientific species names that I do not want to abbreviate. In some cases, these are rather long (e.g. Myrmeleotettix maculatus)
    – yenats
    Commented Nov 22, 2017 at 13:45
  • indeed, the alias appear in the attribute table. However, when I store the patches-layer with the joined attributes, I lose the aliases. Honestly, I tried but I don't understand how to actually store them...
    – yenats
    Commented Nov 22, 2017 at 13:54
  • oh - I just see that your answer was updated, @LaughU. I will try that.
    – yenats
    Commented Nov 22, 2017 at 13:56
  • I tried the "trick" you suggested. Unfortunately, it only works for those fields which are not joined. So - I lose the aliases for the "important" fileds. Are there other workarounds? Is there another way to incorporate joined fields with an original layer than simply storing the original layer with the joined fields?
    – yenats
    Commented Nov 22, 2017 at 14:09
  • 2
    @yenats I think the shapefile format has its limits on your specific use case. I, therefore, would advise you to save the files into a PostGIS or SQLlight database. but this is too much for the comments and I think out of scope for this specific question
    – LaughU
    Commented Nov 22, 2017 at 14:31

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.