0

I am trying to make a heat map of every town in my state. After joining my data (a .csv) to the shapefile, the column I need to map is not visible on the graduated color option under Symbology.

I have read many responses to similar questions here, but none of them have worked for me. Changing the .csv to a .csvt or .txt or other file type does not work.

I also saw posts that it was recommended to convert using the Field Calculator ... but the message says, "This layer does not support adding new provider fields. You can only add virtual fields."

I somehow need to get the data file to be read as integers, not text, if I am correct. However, 12 columns are available to be mapped on my .csv file ... just not the joined column that I need. So I am quite confused.

FWIW, under Symbology, the correct column DOES appear when I tried to map by "categorized," but that is not what I need to do, I need it "graduated."

3
4

If your CSV contains columns with values that are all valid numeric representations then it will be read in and interpreted as a numeric field and so available in graduated styles.

If the column contains text that cannot be read as a number, then it will be interpreted as character values, and so not available for graduated styles.

For example this CSV:

id,x,y,N
1,0,0,"12"
2,0,.1,"14"
3,.1,.1,"22"

will let me create a graduated style with N but this one wont:

id,x,y,N
1,0,0,"12"
2,0,.1,"14m"
3,.1,.1,"22"

because of that "14m" in there. In this case I can use the expression system in the graduated styler (The "E" next to the drop-down) to style by to_int(N) which converts the string representation to an integer. However, values that don't hold purely numerical values get styled as "missing", or don't appear.

You need to inspect your CSV column and figure out why QGIS doesn't think it contains numbers. Often its because there's a flag like "NONE" for missing data, or blank spaces, or other non-numeric content. If you can figure that out then in some cases an expression can again be used to convert to numeric.

For example with the failing CSV above, if I have a column where some values are like "14m" because the data entry was done with units, I could use the string processing expressions to remove all letters before calling to_int() and that would work. I'd have to be careful in case there were a mix of units though...

But the key is to find out why your column isn't numeric. Use the "select by expression" button in the attribute table to select by "to_int(N)" and then hit the "Move selection to top" button, and then all the non-numeric rows will be at the bottom of the attribute list where you can figure out what the problem is with them. Example here:

enter image description here

3
  • Thank you for your detailed response Spacedman. Would a percent ( %) symbol throw off QGIS here? My numeric columns that I joined were all percents. I'm on a Mac and some threads haver noted mac might have had problems with the .csv conversion.
    – Steve
    Dec 3 '19 at 23:05
  • Yes I reckon a % sign would do that. I reckon to_real(replace(pcfield,'%','')) should get rid of any percentage signs and convert to a real numeric value which should let you make a graduated symbolism (where pcfield is the name of your percentage field)
    – Spacedman
    Dec 3 '19 at 23:52
  • Thank you once again. I can now see the column on the graduated column option!
    – Steve
    Dec 4 '19 at 1:44

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.