Wednesday, 11 February 2015

Convert String to Integer in QGIS tables


I want it to know how to convert string field values to integer values in QGIS Dufour... there are numbers and strings in the same field, when I use toreal(string) it stops and it won´t create the field.




Answer



I just tried to convert a string to an integer in QGIS Dufour with no issues. I had a text string that was 7 characters long. I did the following:



  • Create a new field (temp2) that is a whole number and holds 10 characters (longer than my source)

  • Field calculate temp2 with: toreal( "temp1" )

  • Field calculate temp3 with: toint( "temp1" )


Both examples worked and produced numbers from text. Make sure you only have numeric values in the source field. If you have any alpha values (a - z) or special characters (* # $ _ etc.) the conversion will not work. The source field must only contain numeric values (0 -9)


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...