use of org.geotoolkit.style.DefaultStyleFactory in project geotoolkit by Geomatys.
the class WMTSClientDemo method createContext.
public static MapLayers createContext() throws Exception {
final MapLayers context = MapBuilder.createContext(CommonCRS.WGS84.normalizedGeographic());
final WebMapTileClient server = new WebMapTileClient(new URL("http://localhost:8080/constellation/WS/wmts/test"), WMTSVersion.v100);
for (final Resource ref : DataStores.flatten(server, false)) {
final GenericName n = ref.getIdentifier().get();
System.out.println(n);
final MapLayer layer = MapBuilder.createCoverageLayer(ref, new DefaultStyleFactory().style(StyleConstants.DEFAULT_RASTER_SYMBOLIZER));
TiledResource model = (TiledResource) ref;
System.out.println(model);
layer.setTitle(n.tip().toString());
context.getComponents().add(layer);
}
return context;
}
use of org.geotoolkit.style.DefaultStyleFactory 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.DefaultStyleFactory 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