use of org.geotoolkit.style.MutableStyleFactory in project geotoolkit by Geomatys.
the class IntervalStyleBuilder method createPointTemplate.
public static PointSymbolizer createPointTemplate() {
final MutableStyleFactory sf = GO2Utilities.STYLE_FACTORY;
final FilterFactory ff = GO2Utilities.FILTER_FACTORY;
final Stroke stroke = sf.stroke(Color.BLACK, 1);
final Fill fill = sf.fill(Color.BLUE);
final List<GraphicalSymbol> symbols = new ArrayList<GraphicalSymbol>();
symbols.add(sf.mark(StyleConstants.MARK_CIRCLE, fill, stroke));
final Graphic gra = sf.graphic(symbols, ff.literal(1), ff.literal(12), ff.literal(0), sf.anchorPoint(), sf.displacement());
return sf.pointSymbolizer(gra, null);
}
use of org.geotoolkit.style.MutableStyleFactory in project geotoolkit by Geomatys.
the class PatternSymbolizerTest method testXml.
/**
* Test Jaxb xml support.
*/
@Test
public void testXml() throws JAXBException, IOException {
final MutableStyleFactory SF = GO2Utilities.STYLE_FACTORY;
final FilterFactory2 FF = GO2Utilities.FILTER_FACTORY;
final Map<Expression, List<Symbolizer>> ranges = new LinkedHashMap<>();
ranges.put(FF.literal(-1000), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.BLUE), null)));
ranges.put(FF.literal(-500), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.RED), null)));
ranges.put(FF.literal(-100), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.GREEN), null)));
ranges.put(FF.literal(100), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.YELLOW), null)));
ranges.put(FF.literal(1000), Arrays.asList(SF.polygonSymbolizer(null, SF.fill(Color.GRAY), null)));
final PatternSymbolizer ps = new PatternSymbolizer(FF.literal(0), ranges, ThreshholdsBelongTo.PRECEDING);
final MutableStyle style = GO2Utilities.STYLE_FACTORY.style(ps);
final Path path = Files.createTempFile("xml", ".xml");
IOUtilities.deleteOnExit(path);
new StyleXmlIO().writeStyle(path, style, Specification.StyledLayerDescriptor.V_1_1_0);
}
use of org.geotoolkit.style.MutableStyleFactory in project geotoolkit by Geomatys.
the class InterpolateTest method interpolate.
@Test
public void interpolate() {
final String attribut = "att_value";
final FilterFactory ff = FilterUtilities.FF;
final MutableStyleFactory sf = new DefaultStyleFactory();
final FeatureTypeBuilder sftb = new FeatureTypeBuilder();
sftb.setName("test");
sftb.addAttribute(Double.class).setName(attribut);
final FeatureType sft = sftb.build();
final Feature f1 = sft.newInstance();
f1.setPropertyValue(attribut, 0d);
final Feature f2 = sft.newInstance();
f2.setPropertyValue(attribut, 5d);
final Feature f3 = sft.newInstance();
f3.setPropertyValue(attribut, 10d);
final Feature f4 = sft.newInstance();
f4.setPropertyValue(attribut, 15d);
final Expression Lookup = ff.property(attribut);
final List<InterpolationPoint> values = new ArrayList<>();
// test color interpolation ---------------------------------------------
values.clear();
values.add(new DefaultInterpolationPoint(0d, ff.literal(BLACK)));
values.add(new DefaultInterpolationPoint(10d, ff.literal(RED)));
values.add(new DefaultInterpolationPoint(20d, ff.literal(BLUE)));
Interpolate interpolate = new DefaultInterpolate(Lookup, values, Method.COLOR, Mode.CUBIC, null);
Color c = (Color) interpolate.apply(f1);
assertEquals(c, BLACK);
c = (Color) interpolate.apply(f2);
assertEquals(c.getAlpha(), 255);
assertEquals(c.getRed(), 127);
assertEquals(c.getGreen(), 0);
assertEquals(c.getBlue(), 0);
c = (Color) interpolate.apply(f3);
assertEquals(c, RED);
// test color interpolation ---------------------------------------------
values.clear();
values.add(new DefaultInterpolationPoint(0d, sf.literal(BLACK)));
values.add(new DefaultInterpolationPoint(10d, sf.literal(RED)));
values.add(new DefaultInterpolationPoint(20d, sf.literal(BLUE)));
interpolate = new DefaultInterpolate(Lookup, values, Method.COLOR, Mode.CUBIC, null);
c = (Color) interpolate.apply(f1);
assertEquals(c, BLACK);
c = (Color) interpolate.apply(f2);
assertEquals(c.getAlpha(), 255);
assertEquals(c.getRed(), 127);
assertEquals(c.getGreen(), 0);
assertEquals(c.getBlue(), 0);
c = (Color) interpolate.apply(f3);
assertEquals(c, RED);
// test number interpolation --------------------------------------------
values.clear();
values.add(new DefaultInterpolationPoint(0d, ff.literal(0d)));
values.add(new DefaultInterpolationPoint(10d, ff.literal(100d)));
values.add(new DefaultInterpolationPoint(20d, ff.literal(50d)));
interpolate = new DefaultInterpolate(Lookup, values, Method.COLOR, Mode.CUBIC, null);
Double d = (Double) interpolate.apply(f1);
assertEquals(d.doubleValue(), 0d, 0d);
d = (Double) interpolate.apply(f2);
assertEquals(d.doubleValue(), 50d, 0d);
d = (Double) interpolate.apply(f3);
assertEquals(d.doubleValue(), 100d, 0d);
d = (Double) interpolate.apply(f4);
assertEquals(d.doubleValue(), 75d, 0d);
// test get lookup property
Collection<String> requieredAttributs = new HashSet<String>();
ListingPropertyVisitor.VISITOR.visit(interpolate, requieredAttributs);
assertEquals(requieredAttributs.size(), 1);
assertEquals(requieredAttributs.iterator().next(), attribut);
}
use of org.geotoolkit.style.MutableStyleFactory in project geotoolkit by Geomatys.
the class MapBuilder method createFeatureLayer.
/**
* Create a default feature map layer with a feature collection and a style.
* @param collection layer data collection
* @return FeatureMapLayer
* @deprecated use createLayer method instead
*/
@Deprecated
public static MapLayer createFeatureLayer(final FeatureSet collection) {
MutableStyle style;
String name = "";
String title = null;
String abstrat = null;
try {
final FeatureType type = collection.getType();
name = type.getName().tip().toString();
title = name;
abstrat = type.getName().toString();
style = RandomStyleBuilder.createDefaultVectorStyle(type);
} catch (DataStoreException ex) {
style = ((MutableStyleFactory) DefaultFactories.forBuildin(StyleFactory.class)).style(RandomStyleBuilder.createRandomPointSymbolizer());
}
final MapLayer maplayer = new MapLayer();
maplayer.setData(collection);
maplayer.setStyle(style);
maplayer.setIdentifier(name);
maplayer.setTitle(title);
maplayer.setAbstract(abstrat);
maplayer.setOpacity(1.0);
return maplayer;
}
use of org.geotoolkit.style.MutableStyleFactory in project geotoolkit by Geomatys.
the class VisitorTest method intersectionFeatureTest.
/**
* Feature visitor test.
*/
@Test
public void intersectionFeatureTest() throws Exception {
final MutableStyleFactory sf = new DefaultStyleFactory();
final GeographicCRS crs = CommonCRS.WGS84.normalizedGeographic();
final FeatureTypeBuilder sftb = new FeatureTypeBuilder();
sftb.setName("testingIntersect");
sftb.addAttribute(String.class).setName("id").addRole(AttributeRole.IDENTIFIER_COMPONENT);
sftb.addAttribute(Polygon.class).setName("geom").setCRS(crs).addRole(AttributeRole.DEFAULT_GEOMETRY);
final FeatureType sft = sftb.build();
final WritableFeatureSet collection = new InMemoryFeatureSet("id", sft);
final Feature f = sft.newInstance();
final GeometryFactory gf = org.geotoolkit.geometry.jts.JTS.getFactory();
LinearRing ring = gf.createLinearRing(new Coordinate[] { new Coordinate(10, 10), new Coordinate(20, 10), new Coordinate(20, 20), new Coordinate(10, 20), new Coordinate(10, 10) });
Polygon pol = gf.createPolygon(ring, new LinearRing[0]);
pol.setUserData(crs);
f.setPropertyValue("id", "id-0");
f.setPropertyValue("geom", pol);
collection.add(Arrays.asList(f).iterator());
MapLayer layer = MapBuilder.createLayer(collection);
layer.setStyle(sf.style(sf.polygonSymbolizer()));
layer.setVisible(true);
MapLayers context = MapBuilder.createContext(CommonCRS.WGS84.normalizedGeographic());
context.getComponents().add(layer);
final GeneralEnvelope env = new GeneralEnvelope(CommonCRS.WGS84.normalizedGeographic());
env.setRange(0, -180, 180);
env.setRange(1, -90, 90);
final Dimension dim = new Dimension(360, 180);
// starting at top left corner
Shape shparea = new Rectangle(195, 75, 2, 2);
ListVisitor visitor = new ListVisitor();
// ensure we can paint image
DefaultPortrayalService.portray(context, env, dim, true);
DefaultPortrayalService.visit(context, env, dim, true, null, shparea, visitor);
assertEquals(1, visitor.features.size());
assertEquals("id-0", FeatureExt.getId(visitor.features.get(0)).getIdentifier());
// starting at top left corner
shparea = new Rectangle(30, 12, 2, 2);
visitor = new ListVisitor();
// ensure we can paint image
DefaultPortrayalService.portray(context, env, dim, true);
DefaultPortrayalService.visit(context, env, dim, true, null, shparea, visitor);
assertTrue(visitor.features.size() == 0);
}
Aggregations