use of org.geotoolkit.style.function.Interpolate in project geotoolkit by Geomatys.
the class StyleCacheTest method GraphicCacheTest.
@Test
public void GraphicCacheTest() throws Exception {
// Test a complex graphic
final Expression Lookup = FF.property("POP_CNTRY");
final List<InterpolationPoint> values = new ArrayList<InterpolationPoint>();
// test color interpolation ---------------------------------------------
values.clear();
values.add(new DefaultInterpolationPoint(0d, FF.literal(3d)));
values.add(new DefaultInterpolationPoint(500000000d, FF.literal(50d)));
Interpolate interpolate = new DefaultInterpolate(Lookup, values, Method.COLOR, Mode.CUBIC, null);
List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
symbols.add(SF.mark(StyleConstants.MARK_CIRCLE, SF.fill(Color.RED), SF.stroke()));
Graphic graphic = SF.graphic(symbols, StyleConstants.DEFAULT_GRAPHIC_OPACITY, interpolate, StyleConstants.DEFAULT_GRAPHIC_ROTATION, StyleConstants.DEFAULT_ANCHOR_POINT, StyleConstants.DEFAULT_DISPLACEMENT);
CachedGraphic cached = CachedGraphic.cache(graphic);
assertFalse(cached.isStatic());
assertEquals(VisibilityState.DYNAMIC, cached.isStaticVisible());
}
use of org.geotoolkit.style.function.Interpolate in project geotoolkit by Geomatys.
the class SEforSLD110Test method testFillInterpolation.
// //////////////////////////////////////////////////////////////////////////
// JAXB TEST UNMARSHELLING FOR USER CASES //////////////////////////////////
// //////////////////////////////////////////////////////////////////////////
@Test
public void testFillInterpolation() throws JAXBException {
final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
// Read test
Object obj = UNMARSHALLER.unmarshal(FILE_SE_FILL_INTERPOLATION);
assertNotNull(obj);
JAXBElement<org.geotoolkit.se.xml.v110.PointSymbolizerType> jax = (JAXBElement<org.geotoolkit.se.xml.v110.PointSymbolizerType>) obj;
PointSymbolizer pointSymbol = TRANSFORMER_GT.visit(jax.getValue());
assertNotNull(pointSymbol);
assertEquals(pointSymbol.getGeometryPropertyName(), valueGeom);
assertEquals(Units.POINT, pointSymbol.getUnitOfMeasure());
assertNotNull(pointSymbol.getGraphic());
Graphic graphic = pointSymbol.getGraphic();
Mark mark = (Mark) graphic.graphicalSymbols().get(0);
Expression color = mark.getFill().getColor();
assertTrue(color instanceof Interpolate);
POOL.recycle(UNMARSHALLER);
}
use of org.geotoolkit.style.function.Interpolate in project geotoolkit by Geomatys.
the class GTtoSE110Transformer method visit.
@Override
public ColorMapType visit(final ColorMap colorMap, final Object data) {
// TODO Fix that when better undestanding raster functions.
final org.geotoolkit.se.xml.v110.ColorMapType cmt = se_factory.createColorMapType();
final Expression fct = colorMap.getFunction();
if (fct instanceof Categorize) {
cmt.setCategorize(visit((Categorize) fct));
} else if (fct instanceof Interpolate) {
cmt.setInterpolate(visit((Interpolate) fct));
} else if (fct instanceof Jenks) {
cmt.setJenks(visit((Jenks) fct));
}
return cmt;
}
use of org.geotoolkit.style.function.Interpolate in project geotoolkit by Geomatys.
the class PaletteReaderTest method readCLR.
@Test
public void readCLR() throws IOException {
String palette = "ColorMap 1 1\n" + "0.000000 143 0 0\n" + "500.000000 244 0 0\n" + "1000.000000 255 89 0\n" + "1500.000000 255 189 0\n" + "2000.000000 236 255 34\n" + "2500.000000 135 255 135\n" + "3000.000000 34 255 236\n" + "3500.000000 0 189 255\n" + "4000.000000 0 89 255\n" + "4500.000000 0 0 244\n" + "5000.000000 0 0 143";
final ColorMap cm = new PaletteReader(PaletteReader.PATTERN_CLR).read(palette);
assertTrue(cm.getFunction() instanceof Interpolate);
final Interpolate interpolate = (Interpolate) cm.getFunction();
final List<InterpolationPoint> steps = interpolate.getInterpolationPoints();
assertEquals(12, steps.size());
for (int i = 0; i < steps.size(); i++) {
final InterpolationPoint step = steps.get(i);
InterpolationPoint expected = null;
switch(i) {
case 0:
expected = new DefaultInterpolationPoint(Double.NaN, SF.literal(new Color(0, 0, 0, 0)));
break;
case 1:
expected = new DefaultInterpolationPoint(0d, SF.literal(new Color(143, 0, 0)));
break;
case 2:
expected = new DefaultInterpolationPoint(500d, SF.literal(new Color(244, 0, 0)));
break;
case 3:
expected = new DefaultInterpolationPoint(1000d, SF.literal(new Color(255, 89, 0)));
break;
case 4:
expected = new DefaultInterpolationPoint(1500d, SF.literal(new Color(255, 189, 0)));
break;
case 5:
expected = new DefaultInterpolationPoint(2000d, SF.literal(new Color(236, 255, 34)));
break;
case 6:
expected = new DefaultInterpolationPoint(2500d, SF.literal(new Color(135, 255, 135)));
break;
case 7:
expected = new DefaultInterpolationPoint(3000d, SF.literal(new Color(34, 255, 236)));
break;
case 8:
expected = new DefaultInterpolationPoint(3500d, SF.literal(new Color(0, 189, 255)));
break;
case 9:
expected = new DefaultInterpolationPoint(4000d, SF.literal(new Color(0, 89, 255)));
break;
case 10:
expected = new DefaultInterpolationPoint(4500d, SF.literal(new Color(0, 0, 244)));
break;
case 11:
expected = new DefaultInterpolationPoint(5000d, SF.literal(new Color(0, 0, 143)));
break;
default:
fail("Unexpected number of elements.");
}
assertEquals(expected, step);
}
}
use of org.geotoolkit.style.function.Interpolate in project geotoolkit by Geomatys.
the class CachedIsolineSymbolizer method extractSteps.
/**
* Extract isolines steps from RasterSymbolizer ColorMap.
*/
private double[] extractSteps(RasterSymbolizer rasterSymbolizer) {
Set<Double> steps = new HashSet<Double>();
if (rasterSymbolizer != null && rasterSymbolizer.getColorMap() != null) {
ColorMap colorMap = rasterSymbolizer.getColorMap();
Expression function = colorMap.getFunction();
if (function instanceof Interpolate) {
Interpolate interpolate = (Interpolate) function;
List<InterpolationPoint> points = interpolate.getInterpolationPoints();
for (InterpolationPoint point : points) {
steps.add(point.getData().doubleValue());
}
dynamicColorMap = false;
} else if (function instanceof Categorize) {
Categorize categorize = (Categorize) function;
Map<Expression, Expression> thresholds = categorize.getThresholds();
for (Map.Entry<Expression, Expression> entry : thresholds.entrySet()) {
Expression key = entry.getKey();
Number step = (Number) key.apply(null);
if (step != null && Double.isFinite(step.doubleValue())) {
steps.add(step.doubleValue());
}
}
dynamicColorMap = false;
} else if (function instanceof Jenks) {
Jenks jenks = (Jenks) function;
Map<Double, Color> jenksColorMap = jenks.getColorMap();
if (jenksColorMap != null) {
for (Double jenksStep : jenksColorMap.keySet()) {
if (jenksStep != null && !jenksStep.isNaN()) {
steps.add(jenksStep);
}
}
}
dynamicColorMap = true;
}
}
int i = 0;
Iterator<Double> iterator = steps.iterator();
double[] stepsArray = new double[steps.size()];
while (iterator.hasNext()) {
stepsArray[i++] = iterator.next();
}
return stepsArray;
}
Aggregations