Search in sources :

Example 1 with DefaultStyleFactory

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;
}
Also used : GenericName(org.opengis.util.GenericName) TiledResource(org.geotoolkit.storage.multires.TiledResource) MapLayer(org.apache.sis.portrayal.MapLayer) Resource(org.apache.sis.storage.Resource) TiledResource(org.geotoolkit.storage.multires.TiledResource) WebMapTileClient(org.geotoolkit.wmts.WebMapTileClient) URL(java.net.URL) DefaultStyleFactory(org.geotoolkit.style.DefaultStyleFactory) MapLayers(org.apache.sis.portrayal.MapLayers)

Example 2 with DefaultStyleFactory

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);
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) Color(java.awt.Color) ArrayList(java.util.ArrayList) MutableStyleFactory(org.geotoolkit.style.MutableStyleFactory) Feature(org.opengis.feature.Feature) FilterFactory(org.opengis.filter.FilterFactory) Expression(org.opengis.filter.Expression) DefaultStyleFactory(org.geotoolkit.style.DefaultStyleFactory) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 3 with DefaultStyleFactory

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);
}
Also used : FeatureTypeBuilder(org.apache.sis.feature.builder.FeatureTypeBuilder) FeatureType(org.opengis.feature.FeatureType) WritableFeatureSet(org.apache.sis.storage.WritableFeatureSet) InMemoryFeatureSet(org.geotoolkit.storage.memory.InMemoryFeatureSet) GeometryFactory(org.locationtech.jts.geom.GeometryFactory) Shape(java.awt.Shape) MapLayer(org.apache.sis.portrayal.MapLayer) Rectangle(java.awt.Rectangle) MutableStyleFactory(org.geotoolkit.style.MutableStyleFactory) SampleDimension(org.apache.sis.coverage.SampleDimension) Dimension(java.awt.Dimension) Feature(org.opengis.feature.Feature) Coordinate(org.locationtech.jts.geom.Coordinate) GeographicCRS(org.opengis.referencing.crs.GeographicCRS) Polygon(org.locationtech.jts.geom.Polygon) LinearRing(org.locationtech.jts.geom.LinearRing) GeneralEnvelope(org.apache.sis.geometry.GeneralEnvelope) DefaultStyleFactory(org.geotoolkit.style.DefaultStyleFactory) MapLayers(org.apache.sis.portrayal.MapLayers) Test(org.junit.Test)

Aggregations

DefaultStyleFactory (org.geotoolkit.style.DefaultStyleFactory)3 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)2 MapLayer (org.apache.sis.portrayal.MapLayer)2 MapLayers (org.apache.sis.portrayal.MapLayers)2 MutableStyleFactory (org.geotoolkit.style.MutableStyleFactory)2 Test (org.junit.Test)2 Feature (org.opengis.feature.Feature)2 FeatureType (org.opengis.feature.FeatureType)2 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Rectangle (java.awt.Rectangle)1 Shape (java.awt.Shape)1 URL (java.net.URL)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 SampleDimension (org.apache.sis.coverage.SampleDimension)1 GeneralEnvelope (org.apache.sis.geometry.GeneralEnvelope)1 Resource (org.apache.sis.storage.Resource)1 WritableFeatureSet (org.apache.sis.storage.WritableFeatureSet)1 InMemoryFeatureSet (org.geotoolkit.storage.memory.InMemoryFeatureSet)1