In QGIS, the preferred/canonical way to store a color ramp is QGIS layer styles (.qml)
files.
If you look inside the qml
file using a simple text editor, you'll find there is nothing hard to understand.
ColorRamp
example:
<colorramp type="gradient" name="[source]">
<prop k="color1" v="247,251,255,255"/>
<prop k="color2" v="8,48,107,255"/>
<prop k="discrete" v="0"/>
<prop k="stops" v="0.13;222,235,247,255:0.26;198,219,239,255:0.39;158,202,225,255:0.52;107,174,214,255:0.65;66,146,198,255:0.78;33,113,181,255:0.9;8,81,156,255"/>
</colorramp>
ColorRampShader
example:
<colorrampshader colorRampType="DISCRETE" clip="0">
<item alpha="255" value="0.5" label="0.1 - 0.5" color="#aaffff"/>
<item alpha="255" value="1" label="0.5 - 1" color="#00aaff"/>
<item alpha="255" value="5" label="1 - 5" color="#0055ff"/>
<item alpha="255" value="10" label="5 - 10" color="#00007f"/>
<item alpha="255" value="15" label="10+" color="#00003c"/>
</colorrampshader>
If you are looking for specifications, please, check this answer.
It should work if you create a layer file for one of your images (the one with the largest range), and apply this layer to the other rasters. You can add the .lyr file to your new document, and change its source to point to the new raster. You can also add the raster dataset as a new layer, and import symbology from your .lyr (properties > symbology > import)
Best Answer
The solution proposed by @Xi Jin is available for raster layers only and is for color maps, not color ramps. Even though very similar, the concepts are different: a color map assigns pre-defined colors (could be a color ramp) to certain values (numbers or classes) - like assigning elevation data to a topographic color ramp:
0 to 200 m: green; 200 to 500 m: yellow; 500 to 1000 m: brown; over 1000 m: white
. Thus color maps are a more narrow concept: color ramp are just ordered gradients of colors, without assigning actual values:green, yellow, brown, white
. See also here for color maps: https://pvanb.wordpress.com/2014/02/05/creating-a-qgis-color-map-from-text-file/The standard way to import color ramps from a file or a URL is using Menu
Settings / Style Manager
, where you have a button to import/export files - see documentation for Style Manager. The color ramps you add in this way will permanently be available everywhere in QGIS.If you want to create your own color ramps, click the green
+
symbol. You can add aName
andTag(s)
for the color ramps created to be easier to find/identify them when you have a lot of color ramps.Color ramps created in this way can be exported (to share) again with the button on the left.
For all color ramps you create or import, set the checkbox
Add to favorites
for those color ramps that you want to be added to favorites. They will be immediately visible in the drop down list when selecting color ramps - all others are hidden behindAll Color Ramps
:Assigning names and tags helps you to keep an overview of your color ramps and other styles.
By the way, the style managar can be used in the same way for other styles like composed styles for vector layers (points, lines, polygons), for texts/labels, legend symbos and 3D symbols. So it is a powerful tool to create and administrate everything connected with styles.