I'm using QGIS, and I've put KML files in as seen in the photo. Each polygon is a distinct feature with a name. I'm trying to upload a CSV file which has a list of the same exact names as the features in the KML files, but has an associated value (say, X) in the beside column. I want X to dictate the color of the KML polygons, but I'm not sure how.

Map of voting precincts in Minnesota (arbitrarily colored)


Consider adding the CSV to your project then going to the KML layer> layer properties>joins, to join column X from the CSV to the KML (based on a shared unique ID).

Then go to the KML's styling options, and next to the relevant symbol's colour setting, look for the data defined button > Field. X should be available as an option so select that and the polygons will be re-coloured accordingly, assuming the data are hex colour values that can be interpreted by QGIS, eg #0000ff. If not you may need to click Edit under Data-defined override and enter an expression to modify X on the fly (e.g. adding a hash sign like '#'||"X" or converting rgb values - if an example value is 255,255,0 try color_rgb("X"))

If you want to permanently join column X to the KML I think you might not be able to, as QGIS's ability to edit KMLs is quite limited.

  • Thanks for helping me out. If you don't mind me asking -- what's a unique shared ID? I can't seem to join the CSV and KML Jun 5 '20 at 20:09
  • Well you need something to "link up" the two data sets, some way of knowing which record in the KML matches up to which record in the CSV. Typically this would be an unique ID column (eg a column called id with values 1,2,3,4,5….no duplicates) that is present in both datasets so id=1 in the CSV is joined with id=1 in the KML. It's these columns that you select as your join field and target field. Sometimes joins don't work because the two fields aren't exactly identical (e.g. extra spaces)
    – she_weeds
    Jun 5 '20 at 23:55

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.