I have imported a CSV to QGIS with lat/lon values representing points. The other fields, at least in the original CSV file, contain numeric values.
> sapply(pune_hotspots, class)
id lat lon type name 830 930 1030
"integer" "numeric" "numeric" "character" "character" "numeric" "numeric" "numeric"
1130
"numeric"
Now I would like to change the size of the points proportional to values in the attribute table, however, something peculiar happens when I open the Styling page under Layer Properties> Style
When selecting Categorized, I am able to choose any field in my point layer. enter image description here
Here, I see that a number of fields have imported as strings(ABC), but they are actually filled with continuous values (see below) enter image description here
Therefore , when selecting Graduated, I am only left with 4 choices of fields to represent, however, these are not the fields that I need to use.
My question is, when importing the CSV, how can I avoid the conversion of certain fields from numeric to strings in QGIS?
-
Perhaps this post might help: Changing CSV layer attribute value from text to number in QGIS?Joseph– Joseph2016年06月29日 10:29:20 +00:00Commented Jun 29, 2016 at 10:29
2 Answers 2
Within the same folder as your csv file, you can save a csvt file which will then provide the field type for each field within the CSV. To do this list the field types you want each field to adhere to in a string within a text editor (notepad works for this) with each field separated by a comma. Make sure the order within the text file is the same as the columns within the csv! So you would end up with something like: String, string, integer, integer, string..... etc. Then save the text file with the same file name as your csv fiel but add the file ending ".csvt" to the file name. This is then automatically associated with the csv file when imported into QGIS and it will set the fields up to the field types you set in the csvt file. This webpage helps to explain how to do it in a tutorial if you want to follow it through: http://www.qgistutorials.com/en/docs/performing_table_joins.html
For your data you would likely need to replace the "N/A" values for "0" as well to allow you to set it up as a numeric field.
-
Note that the csvt file will be used with
Add Vector layer
, or drag and drop to the legend.Add delimited text
works different, not reading the csvt file.AndreJ– AndreJ2016年06月29日 11:47:36 +00:00Commented Jun 29, 2016 at 11:47
It is because your field names are invalid as (at least) shapefile column names and QGis seems to expect shapefile conforming field names. These must start with a letter not a digit.