Bug report #14078
Incorrect loading of csv files
Status: | Closed | ||
---|---|---|---|
Priority: | Normal | ||
Assignee: | Sebastian Dietrich | ||
Category: | Data Provider | ||
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 |
Description
The first row of the attached file is not interpreted as column headings.
Other, apparently similar, files are loaded fine.
Related issues
History
#1 Updated by Sebastian Dietrich almost 9 years ago
- File QgisLoadCsvWithHeaders.png added
- File QgisCsvLayerFields.png added
I can not reproduce using master (8d105ff8f998bdf3426088d648cd75220b0b469c).
#2 Updated by Nyall Dawson almost 9 years ago
- Status changed from Open to Feedback
#3 Updated by Paolo Cavallini almost 9 years ago
- Status changed from Feedback to Open
Loading through the text delimited plugin is OK, but simply dragging it into the cnavas shows the issue reported. Similar files load fine.
#4 Updated by Sebastian Dietrich almost 9 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.
Bad:
D1,D2 10,20
Good:
"D1","D2" 10,20
Can you confirm the similar files that load fine have different, non-numeric column names?
#5 Updated by Paolo Cavallini almost 9 years ago
- File test1.csv added
The attached test1 loads fine.
Thanks for your feedback.
Perhaps worth opening a ticket on GDAL.
#6 Updated by Giovanni Manghi almost 9 years ago
- Category changed from Data Provider/Delimited Text to Data Provider
#7 Updated by Sebastian Dietrich almost 9 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're welcome.
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.
#8 Updated by Sebastian Dietrich almost 9 years ago
- Assignee set to Sebastian Dietrich
#9 Updated by Paolo Cavallini almost 9 years ago
Done both, thanks.
#10 Updated by Even Rouault almost 9 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.