I have a polygon layer in QGIS that I have applied a random color style to each polygon. Under Layer Properties -> Style I selected a Categorized style and then generated a random color ramp. I added a color column to the layer table. Is there a way to automatically copy the color assigned in the style to the color column for each polygon in the form "#ff0000".
Ultimately, I want to export it as a GeoJSON layer and import it into a leaflet map. The color column will set the color in leaflet.
Best Answer
You could use PyQGIS for that (not sure is the best solution for it, though).
Assuming your layer has a
color
field (type: string), select (or activate) the layer in the QGIS ToC, open the QGIS Python console, and copy this code snippet:After running it, you'll obtain this:
Let me know if you face any problem.