1

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?

  • 1
    What does "the column names are exchanged" mean, exactly? – matt.f.c Aug 6 '18 at 17:52
  • Can you use a format other than shapefile? Not all formats are limited to 10 character column names. switchfromshapefile.org/#alternatives – csk Aug 6 '18 at 18:14
  • @matt.f.c sorry I meant changed. QGIS changes the column names into numbers – Hannah H. Aug 6 '18 at 19:20
  • @csk I will check again. But I am pretty sure, that I need the shapefile format. – Hannah H. Aug 6 '18 at 19:21
  • 1
    You are also very close to another limitation: maximum number of fields per record = 255. – user30184 Aug 6 '18 at 19:56
4

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.

  • 3
    There's an option in the QGIS join dialogue to add a custom prefix / no prefix... that might help here too, as maybe the QGIS default prefix is causing the names to bee too long... – DPSSpatial Aug 6 '18 at 20:51

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.