2

I'm attempting to rename a field in a shapefile. I select the layer, enabling editing and then apply changes, and save them. When I open the file again, it's been renamed 'field_to__1'. However this only seems to happen for certain (joined?) fields.

How can I save the field name changes in QGIS?

6
  • 1
    I don't think that shapefiles support renaming fields, you could try adding a new field with the correct name and calculating the values then remove the misnamed field. The reason you're getting the weird field names is because there's a limit of 10 characters to a field name in a shapefile, this is a limitation of the DBASE IV format and cannot be changed. Commented Jun 12, 2017 at 23:35
  • Ddf files and thus shapefiles as well do support renaming fields. There must be something else going on.
    – user30184
    Commented Jun 12, 2017 at 23:38
  • 1
    not recommended but this works, open in a spreadsheet/dbf editor and rename the field.
    – Mapperz
    Commented Jun 12, 2017 at 23:57
  • 1
    "However this only seems to happen for certain (joined?) fields." --> Have you created a new file with the joined columns or are we talking about a shapefile with an active join?
    – AndreasK
    Commented Jun 13, 2017 at 8:34
  • If the joins are active as @AndreasK mentioned, you can edit the prefix to be blank.
    – Joseph
    Commented Jun 13, 2017 at 9:46

2 Answers 2

4

I have used the "Refactor" tool. It can be found in the processing toolbox for QGIS. It outputs a file into temporary memory with the filed name(s) change and re-ordered if you are trying to do that. You can then remove the original layer from the TOC, and save the temporary file over the original file. You should then have the shapefile with the desired attribute names.

1
  • I use the Table manager plugin for such things, but it is discontinued in favour of the Refactor tools. It replaces the original layer internally.
    – AndreJ
    Commented Jun 13, 2017 at 5:39
4

One very simple method, if you don not fear the command line, is to use ogrinfo http://www.gdal.org/ogrinfo.html with OGR SQL dialect http://www.gdal.org/ogr_sql.html.

Take a shapefile with columnn named "foo"

ogrinfo -al -so test.shp
INFO: Open of `test.shp'
      using driver `ESRI Shapefile' successful.

Layer name: test
Metadata:
  DBF_DATE_LAST_UPDATE=2017-06-13
Geometry: Point
Feature Count: 1
Extent: (350.000000, 372.000000) - (350.000000, 372.000000)
Layer SRS WKT:
(unknown)
foo: String (5.0)

Rename column with ogrinfo

ogrinfo -sql "ALTER TABLE test RENAME COLUMN foo TO bar" test.shp

Check the result

ogrinfo -al -so test.shp
INFO: Open of `test.shp'
      using driver `ESRI Shapefile' successful.

Layer name: test
Metadata:
  DBF_DATE_LAST_UPDATE=2017-06-13
Geometry: Point
Feature Count: 1
Extent: (350.000000, 372.000000) - (350.000000, 372.000000)
Layer SRS WKT:
(unknown)
bar: String (5.0)

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