2

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.

enter image description here

My question is, when importing the CSV, how can I avoid the conversion of certain fields from numeric to strings in QGIS?

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 Jun 29 '16 at 11:47
0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.