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?
Asked
Active
Viewed 4,030 times
3
-
1Perhaps this post might help: Changing CSV layer attribute value from text to number in QGIS? – Joseph Feb 18 '16 at 15:46
-
1create a csvt file. more infos here: http://gis.stackexchange.com/questions/45005/why-are-some-columns-not-recognized-as-numeric-even-though-i-have-a-csvt – Kurt Feb 18 '16 at 19:18
3 Answers
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).
-
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