Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GEOS-8034] Fix ysld color conversion master #1649

Merged
merged 5 commits into from Nov 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -167,7 +167,14 @@ YsldEncodeHandler<T> inline(Map<String, Object> values) {
}

Object toColorOrNull(Expression expr) {
Object obj = toObjOrNull(expr, false);
Object obj;
if (expr instanceof Literal) {
obj = ((Literal) expr).getValue();
if (obj instanceof Color) {
return obj;
}
}
obj = toObjOrNull(expr, false);
if (obj instanceof String && expr instanceof Literal) {
String str = Util.stripQuotes(obj.toString());
obj = makeColorIfPossible(str);
Expand Down Expand Up @@ -225,6 +232,7 @@ Object toObjOrNull(Expression expr, boolean isname) {
return null;

List<Expression> subExpressions = Util.splitConcatenates(expr);

StringBuilder builder = new StringBuilder();
for (Expression subExpr : subExpressions) {
if (isNull(subExpr)) {
Expand Down
Expand Up @@ -32,6 +32,7 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.util.ArrayList;
Expand All @@ -41,11 +42,13 @@
import javax.measure.unit.NonSI;

import org.geotools.factory.CommonFactoryFinder;
import org.geotools.styling.ColorMap;
import org.geotools.styling.ColorMapEntry;
import org.geotools.styling.FeatureTypeStyle;
import org.geotools.styling.LabelPlacement;
import org.geotools.styling.LineSymbolizer;
import org.geotools.styling.Mark;
import org.geotools.styling.NamedLayer;
import org.geotools.styling.PointSymbolizer;
import org.geotools.styling.RasterSymbolizer;
import org.geotools.styling.Rule;
Expand All @@ -58,10 +61,11 @@
import org.geotools.styling.TextSymbolizer2;
import org.geotools.styling.UomOgcMapping;
import org.geotools.styling.UserLayer;
import org.geotools.ysld.Tuple;
import org.geotools.ysld.YamlMap;
import org.geotools.ysld.YamlSeq;
import org.geotools.ysld.Ysld;
import org.junit.Ignore;
import org.geotools.ysld.parse.YsldParser;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.opengis.filter.FilterFactory;
Expand Down Expand Up @@ -1320,4 +1324,29 @@ public void testSymbolizerUoMOther() throws Exception {
exception.expect(IllegalArgumentException.class);
Ysld.encode(sld(fts), out);
}

@Test
public void testEncodeColorMapEntry() throws IOException {
StyledLayerDescriptor style = new YsldParser(new ByteArrayInputStream(
("name: Test\n" +
"title: Test Style title\n" +
"abstract: Styling of Test layer\n" +
"feature-styles:\n" +
"- rules:\n" +
" - title: raster\n" +
" symbolizers:\n" +
" - raster:\n" +
" opacity: 1.0\n" +
" color-map:\n" +
" type: values\n" +
" entries:\n" +
" - ['#e20374', 1.0, 1, Lorem Ipsum (magenta = covered)]").getBytes())).parse();

RasterSymbolizer symbolizer = (RasterSymbolizer)((NamedLayer)style.getStyledLayers()[0]).styles().get(0).featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);

ColorMap colorMap = symbolizer.getColorMap();
RasterSymbolizerEncoder.ColorMapEntryIterator iterator = new RasterSymbolizerEncoder(symbolizer).new ColorMapEntryIterator(colorMap);
Tuple map = iterator.next();
assertEquals("('#E20374',1.0,1,Lorem Ipsum (magenta = covered))", map.toString());
}
}