3

I am trying to join a CSV table to a shapefile in QGIS 2.12.0. I have exported a table from Excel to CSV format, but when opening the table I noticed that my unique ID field in Excel is in text format, is changed to number in QGIS. Since my shapefile has that same ID field as a text string I cannot join them. I have tried to change the format to string but it does not let me. Does anyone know how to do this?

whyzar
  • 12,053
  • 23
  • 38
  • 72
Armando Anaya
  • 31
  • 1
  • 3

3 Answers3

3

You can use the Field Calculator (open the Attribute Table, then Ctrl + I) to convert numbers to strings. The following command should do the job :

 tostring( "ID" )

(replace ID with the actual name of your ID field).

wittich
  • 2,356
  • 1
  • 16
  • 30
ArMoraer
  • 5,649
  • 2
  • 26
  • 48
  • Make sure there are no spaces or other "notnumbers" in your fields when doing it the other way around with to_int or to_real. – Papierwolf Feb 18 '16 at 16:01
2

Use the add spreadsheet layer plugin to bring in the CSV. You can then set the field types on import.

SpatialSuccess
  • 545
  • 2
  • 10
1

Use the .csvt technic. Check this short tutorial: http://www.qgistutorials.com/en/docs/performing_table_joins.html?highlight=csvt

sig_renato
  • 450
  • 2
  • 13