Created
December 8, 2016 21:43
-
-
Save jscarto/ff9a22eac8f17cceec4ec3964bb65d9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Script modified from original by Anita Graser: https://twitter.com/underdarkGIS/status/716389969850404864 | |
| # To use: Enter a paletteName, paste array of hex codes into colors, and run! | |
| # Re-running with the same name will update the previous color ramp | |
| ############################################################################ | |
| from PyQt4.QtGui import QColor | |
| paletteName = '' # give the palette a name | |
| colors = [] # replace with hex values | |
| color1 = QColor(colors[0]) | |
| color2 = QColor(colors[-1]) | |
| stops = [] | |
| ramp = QgsVectorGradientColorRampV2(color1,color2,1,stops) | |
| tags = [] | |
| if len(colors) > 2: | |
| step = 1.0 / (len(colors)) | |
| for i, color in enumerate(colors[1:]): | |
| stops.append(QgsGradientStop(step * (i+1), QColor(color))) | |
| ramp.setStops(stops) | |
| QgsStyleV2.defaultStyle().removeColorRamp(paletteName) | |
| QgsStyleV2.defaultStyle().addColorRamp(paletteName, ramp, 0) | |
| QgsStyleV2.defaultStyle().saveColorRamp(paletteName, ramp, 0, tags) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment