[GIS] Changing data type in attribute table in QGIS

attribute-tablefields-attributesqgis

I have county data in which the "FIP"s (actually State "FIP"s and County "FIP"s combined). I have data imported as CSV with the sames "FIP"s data titled 'STCounty'. However, the shapefile "FIP"s is listed as a Real and the CSV came in as an Integer and the Join function does not seem to work. The drop boxes are greyed out/empty.

So the bigger questions is how do you change the attribute type in a table?

I tried to create a new column in the shapefile (county data) and set it to an integer and then multiply the "FIP"s*1, but got a column full of NULL.

I am new to QGIS and have a lot of experience in MapInfo, so the join concept is not new to me, just the syntax in QGIS.

Best Answer

Creating a new integer column is the right way to go - but the 1*FIPS that you used (which would work in Excel or Libreoffice) is where the problem comes in; QGIS doesn't automatically convert between field types in a calculation.

You need to use one of the conversion functions (toint converts to integer, tostring to text, and toreal to real/decimal) with the correct column name:

toreal("FIPS")

You can use the Tablemanager plugin to then remove unnecessary columns.

Setting up a .csvt file would be the best repeatable solution but for a single column, this should be pretty straightforward.

Related Question