[GIS] How to avoid text field truncation when saving a table join

attribute-joinscsvqgis

Using QGIS I've joined tabular text data (all in fields of less than 255 characters) to a shapefile via a CSV file. All looks good in the joined table but when I save to a new shapefile to make the join permanent the long text fields get truncated to between 50-100 characters. How can I avoid this? It seems the problem is in the saving/exporting process since the initial join is fine.

I'm running QGIS 1.7.0 on Mac 10.6.8

Thanks,
Matt

Best Answer

The problem lies with the OGR library used by QGIS to read the data from the CSV file. It does not attempt to automatically determine the datatype and length of each field in the file like some software, instead relying on an accompanying .csvt file described in the OGR CSV page.

In the absence of a .csvt file, my guess is that OGR reports string field sizes as a default of 80 characters meaning that when a shapefile is saved after joining to a CSV, the shapefile's fields corresponding to those derived from the CSV will be set to this length, and text values longer than this will be truncated.

If a .csvt file is created for the CSV file to be joined then the field sizes are correctly read and passed through to the shapefile following joining, and text truncation is avoided.

(Tested on QGIS 1.8.0)

Related Question