Skip to content

Commit

Permalink
Moved definition of nr of breaks in default legend to const module.
Browse files Browse the repository at this point in the history
  • Loading branch information
yellowcap committed Jul 13, 2016
1 parent 12657dc commit 4f30b08
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
1 change: 1 addition & 0 deletions raster/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
IMG_FORMATS = {'.png': 'PNG', '.jpg': 'JPEG'}
EXPORT_MAX_PIXELS = 10000 * 10000
MAX_EXPORT_NAME_LENGTH = 100
DEFAULT_LEGEND_BREAKS = 7
README_TEMPLATE = """Django Raster Algebra Export
============================
{description}
Expand Down
11 changes: 4 additions & 7 deletions raster/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from django.views.generic import View
from raster.algebra.const import ALGEBRA_PIXEL_TYPE_GDAL
from raster.algebra.parser import RasterAlgebraParser
from raster.const import EXPORT_MAX_PIXELS, IMG_FORMATS, MAX_EXPORT_NAME_LENGTH, README_TEMPLATE
from raster.const import DEFAULT_LEGEND_BREAKS, EXPORT_MAX_PIXELS, IMG_FORMATS, MAX_EXPORT_NAME_LENGTH, README_TEMPLATE
from raster.exceptions import RasterAlgebraException
from raster.models import Legend, RasterLayer
from raster.tiles.const import WEB_MERCATOR_SRID, WEB_MERCATOR_TILESIZE
Expand Down Expand Up @@ -63,21 +63,18 @@ def get_colormap(self, layer=None):
if meta is None:
return

# Set the number of breaks to be used
nr_of_breaks = 7

# Compute bin width for a linear scaling
diff = (meta.max - meta.min) / 7
diff = (meta.max - meta.min) / DEFAULT_LEGEND_BREAKS

# Create colormap with seven breaks
colormap = {}
for i in range(nr_of_breaks):
for i in range(DEFAULT_LEGEND_BREAKS):
if i == 0:
expression = '({0} <= x) & (x <= {1})'
else:
expression = '({0} < x) & (x <= {1})'
expression = expression.format(meta.min + diff * i, meta.min + diff * (i + 1))
colormap[expression] = [(255 / (nr_of_breaks - 1)) * i] * 3 + [255, ]
colormap[expression] = [(255 / (DEFAULT_LEGEND_BREAKS - 1)) * i] * 3 + [255, ]
else:
return

Expand Down

0 comments on commit 4f30b08

Please sign in to comment.