QGIS CSV Export – Export Shapefile with Column Name of CSV File or Change Column Names Afterwards

attribute-joinscsvexportqgis

I am joining a .csv file with a shapefile in QGIS 2.18.12 and I need the column names for further processing (but they are way longer than 10 digits). However, when I save the new file, the column names are changed by GQIS. I found a manual way here. But my .csv file has 253 columns, therefore a manual processing afterwards is not reasonable.

Is there any way to export my file with the column names of the csv file, or change the column names of the shapefile afterwards in an automated way?

Best Answer

The 10-character limit for column names is a limitation of the shapefile format. So the easiest solution is to use format that allows longer column names, such as geopackage.

If for some reason you must use shapefiles, give each column a short name before importing into QGIS. In Excel, it would be very simple to add a row, fill the first value as "field1", then click and drag across the row to auto-fill with field2, field3, etc.

Now the first two rows of your spreadsheet are:

  1. short column names (field1, field2, field3, etc)
  2. original column names

Save these two rows as a separate spreadsheet.

Delete the second row from the CSV before importing into QGIS.

You won't be able to import the original column names into a shapefile, because the 10-character field name limit still applies. But after any processing you do in QGIS, you can export the layer as a CSV and add the original column names. Open the exported CSV in Excel, make sure the columns are in numerical order, and insert the row of original column names.