Bug report #14078
Incorrect loading of csv files
|Affected QGIS version:||master||Regression?:||No|
|Operating System:||Easy fix?:||No|
|Pull Request or Patch supplied:||No||Resolution:||up/downstream|
|Crashes QGIS or corrupts data:||No||Copied to github as #:||22088|
The first row of the attached file is not interpreted as column headings.
Other, apparently similar, files are loaded fine.
#4 Updated by Sebastian Dietrich almost 5 years ago
OK, now I could reproduce in master. Turns out this is a GDAL/OGR issue.Note that files are loaded through GDAL/OGR when
- dropping them onto QGIS
- specifying them on the commandline
- double-clicking them on MAC
The meta-data will show
OGR data provider.
This is different from opening a file using the Create a Layer from a Delimited Text File dialog where the provider will be
Delimited text data provider.
The GDAL/OGR .csv-driver uses some logic to detect whether the first line is a header or not. In your case it finds some all numeric values in the first row (D1 to D31, D is considered a hex-digit) and treats it as a data record instead of as a header.
The easiest solution would be to put the column names within double quotes, at least the offending ones.
Can you confirm the similar files that load fine have different, non-numeric column names?
#7 Updated by Sebastian Dietrich almost 5 years ago
- Status changed from Open to Closed
- Resolution set to up/downstream
Paolo Cavallini wrote:
The attached test1 loads fine.
Thanks for your feedback.
Perhaps worth opening a ticket on GDAL.
You might consider opening a feature request to prefer the QGIS-providers over the OGR-provider for files that are supported by both, like CSVs.
#10 Updated by Even Rouault almost 5 years ago
Fixed in GDAL per https://trac.osgeo.org/gdal/ticket/6305. I'd note that the OGR CSV driver has gained editing capabilities in GDAL 2.1dev (specificaly to be used through QGIS), whereas AFAICS the QGIS CSV provider is read-only. It would be a shame that using the OGR CSV driver is no longer possible.