Skip to content

Commit b2d71f2

Browse files
committed
Merge remote-tracking branch 'origin/raster-styling'
2 parents 7b2d2f1 + fbaeecd commit b2d71f2

File tree

8 files changed

+149
-21
lines changed

8 files changed

+149
-21
lines changed

geocss/src/main/scala/org/geoscript/geocss/CssParser.scala

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,17 @@ object CssParser extends RegexParsers {
4343
}
4444
}
4545

46-
private object SingleComment extends Parser[String] {
47-
val whiteSpace = """\s*""".r
48-
val comment = """/\*((?:[^/]|[^*]/)*)\*/""".r
49-
50-
override def apply(in: Reader[Char]): ParseResult[String] = {
51-
val source = in.source
52-
val start = findStart(source, in.offset)
53-
val space = source.subSequence(start, source.length)
54-
comment.findPrefixMatchOf(space) match {
55-
case Some(cmt) => Success(cmt.group(1), in.drop(start - in.offset + cmt.end))
56-
case None => Failure("nothing found", in)
57-
}
58-
}
59-
60-
private def findStart(source: CharSequence, offset: Int): Int = {
61-
val space = source.subSequence(offset, source.length)
62-
whiteSpace.findPrefixMatchOf(space) match {
63-
case Some(m) => offset + m.end
64-
case None => offset
65-
}
66-
}
46+
private val SingleComment: Parser[String] = {
47+
val whitespacepadding = rep(elem("Whitespace", _.isWhitespace))
48+
val startComment = elem('/') ~ elem('*')
49+
val endComment = elem('*') ~ elem('/')
50+
val commentChar = (elem('*') <~ not(elem('/'))) | elem("Comment content", _ != '*')
51+
for {
52+
_ <- whitespacepadding
53+
_ <- startComment
54+
body <- rep(commentChar)
55+
_ <- endComment
56+
} yield body.mkString
6757
}
6858

6959
private val ParsedComment = rep1(SingleComment) map { x => Description(x.last) }
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
* The raster-color-enhancement property specifies image processing filters to
3+
* be applied to an entire raster layer.
4+
*
5+
* The keyword "none" will cause colors to be included directly; with high
6+
* values encoded as white and low values encoded as black. This is the default
7+
* behavior.
8+
* raster-color-enhancement: none;
9+
*
10+
* The keyword "normalize" will stretch or compress values so that the minimum
11+
* value in the raster is mapped to black and the maximum is mapped to white,
12+
* with intermediate colors mapped linearly along the scale between the two.
13+
* raster-color-enhancement: normalize;
14+
*
15+
* The keyword "histogram" will calculate a color curve such that the output
16+
* image has roughly the same number of pixels at each brightness.
17+
*/
18+
* {
19+
raster-channels: 1;
20+
raster-color-enhancement: histogram;
21+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* The raster-color-map property specifies a series of colors to associate with
3+
* specific values in a raster. Note that this only applies with grey-scale
4+
* rasters - that is, when raster-color-map is used, it should always be in
5+
* conjunction with a raster-channels value specifying only a single value.
6+
*
7+
* A raster-color-map property consists at least one color map entry, created
8+
* by the color-map-entry function. The color-map-entry must contain a CSS
9+
* color and a numeric value:
10+
* raster-color-map: color-map-entry(#ff0000, 0)
11+
*
12+
* Optionally, it may also include an opacity value:
13+
* raster-color-map: color-map-entry(#ff0000, 0, 0.5)
14+
*
15+
* By default values in between entries in the color map will have colors
16+
* smoothly interpolated. This behavior can be controlled using the
17+
* raster-color-map-type property.
18+
*/
19+
* {
20+
raster-channels: 1;
21+
raster-color-map: color-map-entry(#ff0000, 0)
22+
color-map-entry(#00ff00, 50, 0.5),
23+
color-map-entry(#00ff00, 100);
24+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* The raster-color-map-type property specifies how values that are not
3+
* explicitly listed in a colormap should be rendered. If no color-map is
4+
* being used, then it has no effect.
5+
*
6+
* There are three meaningful values of this property; others will be ignored.
7+
* The default value is "ramp." This specifies that colors should be linearly
8+
* interpolated.
9+
* raster-color-map-type: ramp;
10+
*
11+
* A value of "intervals" causes every value to be colored according to the
12+
* highest-valued entry in the colormap that is not greater than the value.
13+
* raster-color-map-type: intervals;
14+
*
15+
* A value of "values" causes the style to render only values that exactly
16+
* match those specified in the color map.
17+
* raster-color-map-type: values;
18+
*/
19+
* {
20+
raster-channels: 1;
21+
raster-color-map: color-map-entry(#ff0000, 0)
22+
color-map-entry(#00ff00, 100);
23+
raster-color-map-type: intervals;
24+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
* The raster-gamma property specifies a gamma correction
3+
* (http://en.wikipedia.org/wiki/Gamma_correction) to be applied to the output raster.
4+
* Gamma correction has the general effect of brightening or darkening shadows
5+
* in the image.
6+
*
7+
* A gamma value of 1 leaves the image unaltered (this is the default). Values
8+
* smaller than one darken the image, while values larger than one lighten it.
9+
*/
10+
* {
11+
raster-channels: 1;
12+
raster-gamma: 0.5;
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/*
2+
* The GeoTools RasterSymbolizer representation has a Geometry property, so I
3+
* exposed it via CSS. I am not really sure what it does, but it is important
4+
* enough that GeoTools preserves it when serializing to SLD. It takes a CQL
5+
* filter expression (Don't forget to enclose that in [square brackets]).
6+
*/
7+
* {
8+
raster-channels: auto;
9+
raster-geometry: [the_geom];
10+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/**
2+
* The raster-opacity property specifies an opacity in the range 0 (fully
3+
* transparent) to 1 (fully opaque.) to be applied to the entire raster.
4+
* Note that a color ramp may specify varying opacity, in which case the
5+
* opacities multiply - if raster-opacity is .5 and a pixel is assigned opacity
6+
* value 0.5 by a color ramp, then the pixel will be rendered with opacity
7+
* 0.25.
8+
*/
9+
* {
10+
raster-channels: auto;
11+
raster-opacity: 0.5;
12+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* The simplest possible style that applies to raster data. Raster display is
3+
* activated by the raster-channels property, which selects bands of the raster to display.
4+
* Raster bands can have any string for a name, but most (all?) GeoTools
5+
* coverage stores use numerals (so the first band is named "1", the second is
6+
* named "2", etc.)
7+
*
8+
* The raster-channels property can take four forms.
9+
*
10+
* If it contains simply the keyword "auto" then the style will attempt to
11+
* guess how to render the raster by inspection - a single-band raster is
12+
* rendered in greyscale, a 3-band raster is interpreted as RGB. I believe
13+
* (but have not verified) that rasters with other numbers of bands will be
14+
* interpreted as greyscale by discarding all but the first band.
15+
* raster-channels: auto;
16+
*
17+
* If it contains a single string other than "auto" then that string will be
18+
* taken as the name of a band which will be used for a grey channel in the
19+
* output.
20+
* raster-channel: 1;
21+
*
22+
* If it contains three strings then they will be taken as the names of the
23+
* bands to use for Red, Green, and Blue channels respectively.
24+
* raster-channel: 1 2 3;
25+
*
26+
* As with other styling properties, commas (',') delimit values to be used in
27+
* separate rendering passes, so: raster-channel: 1, 2, 3; overlays channels 1,
28+
* 2, and 3 on top of each other in greyscale, rather than combining them into
29+
* an RGB image.
30+
*/
31+
32+
* {
33+
raster-channels: auto;
34+
}

0 commit comments

Comments
 (0)