Search in sources :

Example 1 with MutableStyleFactory

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);
}
Also used : Stroke(org.opengis.style.Stroke) Fill(org.opengis.style.Fill) Graphic(org.opengis.style.Graphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) ArrayList(java.util.ArrayList) MutableStyleFactory(org.geotoolkit.style.MutableStyleFactory) FilterFactory(org.opengis.filter.FilterFactory)

Example 2 with MutableStyleFactory

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);
}
Also used : Path(java.nio.file.Path) MutableStyle(org.geotoolkit.style.MutableStyle) Expression(org.opengis.filter.Expression) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) List(java.util.List) MutableStyleFactory(org.geotoolkit.style.MutableStyleFactory) FilterFactory2(org.geotoolkit.filter.FilterFactory2) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 3 with MutableStyleFactory

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);
}
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 4 with MutableStyleFactory

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;
}
Also used : MutableStyleFactory(org.geotoolkit.style.MutableStyleFactory) StyleFactory(org.opengis.style.StyleFactory) FeatureType(org.opengis.feature.FeatureType) DataStoreException(org.apache.sis.storage.DataStoreException) MutableStyle(org.geotoolkit.style.MutableStyle) MapLayer(org.apache.sis.portrayal.MapLayer) MutableStyleFactory(org.geotoolkit.style.MutableStyleFactory)

Example 5 with MutableStyleFactory

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);
}
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

MutableStyleFactory (org.geotoolkit.style.MutableStyleFactory)7 FilterFactory (org.opengis.filter.FilterFactory)4 Test (org.junit.Test)3 FeatureType (org.opengis.feature.FeatureType)3 Stroke (org.opengis.style.Stroke)3 ArrayList (java.util.ArrayList)2 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)2 MapLayer (org.apache.sis.portrayal.MapLayer)2 DefaultStyleFactory (org.geotoolkit.style.DefaultStyleFactory)2 MutableStyle (org.geotoolkit.style.MutableStyle)2 Feature (org.opengis.feature.Feature)2 Expression (org.opengis.filter.Expression)2 Fill (org.opengis.style.Fill)2 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 Rectangle (java.awt.Rectangle)1 Shape (java.awt.Shape)1 Path (java.nio.file.Path)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1