3

I am trying to import a CSV or DBF into QGIS so I can perform a join on a shapefile. However, QGIS is not detecting the first row as header names. I know I've done similar joins before and there's never been a problem detecting column headers.

4
  • please share the first few lines of your CSV
    – underdark
    Feb 13, 2013 at 18:57
  • Perhaps special characters in the column name?
    – Brad Nesom
    Feb 14, 2013 at 3:16
  • I've tried saving the file as a .dbf in Open Office, but it too is not seeing the intended column names and instead creating a new row of column names. The data looks like this in Open Office: N1,C,20 N2,C,13 N3,C,4 N4,N,7,2 <linebreak> Country Continent OECD 2004.00 <linebreak> Brunei Darussalam Asia N 0.00 <linebreak> Feb 15, 2013 at 5:03
  • @JamesConkling you should 1. edit your original question with enhancing information rather than create a new comment. 2. check the answer that solved the issue an answer.
    – Brad Nesom
    Feb 15, 2013 at 15:41

4 Answers 4

2

Turns out Open Office was adding the new row of column names (N1,C,20 | N2,C,13 | N3,C,4 | N4,N,7,2 etc.) because some of the existing column names were only numbers. The problem persisted even after I reformatted the column row as text. However, after adding text to those column names, (e.g. changing 2004 to year_2004) Open Office stopped automatically inserting the new column names.

Problem solved--don't use only numeric characters as field names.

2

For whatever reason, when saving .csv files in Excel, it uses a different character for line breaks, that QGIS does not recognize.

In your terminal convert the line breaks to the standard '\n' by inputting:

tr '\15' '\n' < infile.csv > outfile.csv

QGIS should now recognize it.

0

I've gotten around this problem by opening the file in Open Office and saving the file as a .dbf

1
  • I've tried saving the file as a .dbf in Open Office, but it too is not seeing the intended column names and instead creating a new row of column names. The data looks like this in Open Office: Feb 15, 2013 at 4:52
0

CSV should probably be in the format of...

Myidfield, country, contintent, OECD, YEAR
1,durusallem, Asia, N, 00000.00

The char fields I think will default to 255, the number field will take the size and decimal from the first value in the column.

csv being "comma separated values".
As per my other comment you should certainly stay away from a "." In the field name.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.