geopyspark.geotrellis.color module

This module contains functions needed to create color maps used in coloring tiles, PNGs, and GeoTiffs.

geopyspark.geotrellis.color.get_colors_from_colors(colors)

Returns a list of integer colors from a list of Color objects from the colortools package.

Parameters:colors ([colortools.Color]) – A list of color stops using colortools.Color
Returns:[int]
geopyspark.geotrellis.color.get_colors_from_matplotlib(ramp_name, num_colors=256)

Returns a list of color breaks from the color ramps defined by Matplotlib.

Parameters:
  • ramp_name (str) – The name of a matplotlib color ramp. See the matplotlib documentation for a list of names and details on each color ramp.
  • num_colors (int, optional) – The number of color breaks to derive from the named map.
Returns:

[int]

class geopyspark.geotrellis.color.ColorMap(cmap)

A class that wraps a GeoTrellis ColorMap class.

Parameters:cmap (py4j.java_gateway.JavaObject) – The JavaObject that represents the GeoTrellis ColorMap.
cmap

py4j.java_gateway.JavaObject – The JavaObject that represents the GeoTrellis ColorMap.

classmethod build(breaks, colors=None, no_data_color=0, fallback=0, classification_strategy=<ClassificationStrategy.LESS_THAN_OR_EQUAL_TO: 'LessThanOrEqualTo'>)

Given breaks and colors, build a ColorMap object.

Parameters:
  • breaks (dict or list or np.ndarray or Histogram) – If a dict then a mapping from tile values to colors, the latter represented as integers e.g., 0xff000080 is red at half opacity. If a list then tile values that specify breaks in the color mapping. If a Histogram then a histogram from which breaks can be derived.
  • colors (str or list, optional) – If a str then the name of a matplotlib color ramp. If a list then either a list of colortools Color objects or a list of integers containing packed RGBA values. If None, then the ColorMap will be created from the breaks given.
  • no_data_color (int, optional) – A color to replace NODATA values with
  • fallback (int, optional) – A color to replace cells that have no value in the mapping
  • classification_strategy (str or ClassificationStrategy, optional) – A string giving the strategy for converting tile values to colors. e.g., if ClassificationStrategy.LESS_THAN_OR_EQUAL_TO is specified, and the break map is {3: 0xff0000ff, 4: 0x00ff00ff}, then values up to 3 map to red, values from above 3 and up to and including 4 become green, and values over 4 become the fallback color.
Returns:

ColorMap

classmethod from_break_map(break_map, no_data_color=0, fallback=0, classification_strategy=<ClassificationStrategy.LESS_THAN_OR_EQUAL_TO: 'LessThanOrEqualTo'>)

Converts a dictionary mapping from tile values to colors to a ColorMap.

Parameters:
  • break_map (dict) – A mapping from tile values to colors, the latter represented as integers e.g., 0xff000080 is red at half opacity.
  • no_data_color (int, optional) – A color to replace NODATA values with
  • fallback (int, optional) – A color to replace cells that have no value in the mapping
  • classification_strategy (str or ClassificationStrategy, optional) – A string giving the strategy for converting tile values to colors. e.g., if ClassificationStrategy.LESS_THAN_OR_EQUAL_TO is specified, and the break map is {3: 0xff0000ff, 4: 0x00ff00ff}, then values up to 3 map to red, values from above 3 and up to and including 4 become green, and values over 4 become the fallback color.
Returns:

ColorMap

classmethod from_colors(breaks, color_list, no_data_color=0, fallback=0, classification_strategy=<ClassificationStrategy.LESS_THAN_OR_EQUAL_TO: 'LessThanOrEqualTo'>)

Converts lists of values and colors to a ColorMap.

Parameters:
  • breaks (list) – The tile values that specify breaks in the color mapping.
  • color_list ([int]) – The colors corresponding to the values in the breaks list, represented as integers—e.g., 0xff000080 is red at half opacity.
  • no_data_color (int, optional) – A color to replace NODATA values with
  • fallback (int, optional) – A color to replace cells that have no value in the mapping
  • classification_strategy (str or ClassificationStrategy, optional) – A string giving the strategy for converting tile values to colors. e.g., if ClassificationStrategy.LESS_THAN_OR_EQUAL_TO is specified, and the break map is {3: 0xff0000ff, 4: 0x00ff00ff}, then values up to 3 map to red, values from above 3 and up to and including 4 become green, and values over 4 become the fallback color.
Returns:

ColorMap

classmethod from_histogram(histogram, color_list, no_data_color=0, fallback=0, classification_strategy=<ClassificationStrategy.LESS_THAN_OR_EQUAL_TO: 'LessThanOrEqualTo'>)

Converts a wrapped GeoTrellis histogram into a ColorMap.

Parameters:
  • histogram (Histogram) – A Histogram instance; specifies breaks
  • color_list ([int]) – The colors corresponding to the values in the breaks list, represented as integers e.g., 0xff000080 is red at half opacity.
  • no_data_color (int, optional) – A color to replace NODATA values with
  • fallback (int, optional) – A color to replace cells that have no value in the mapping
  • classification_strategy (str or ClassificationStrategy, optional) – A string giving the strategy for converting tile values to colors. e.g., if ClassificationStrategy.LESS_THAN_OR_EQUAL_TO is specified, and the break map is {3: 0xff0000ff, 4: 0x00ff00ff}, then values up to 3 map to red, values from above 3 and up to and including 4 become green, and values over 4 become the fallback color.
Returns:

ColorMap

static nlcd_colormap()

Returns a color map for NLCD tiles.

Returns:ColorMap