Search in sources :

Example 11 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class PatternRenderer method presentations.

@Override
public Stream<Presentation> presentations(MapLayer layer, Resource resource) {
    if (!(resource instanceof GridCoverageResource)) {
        return Stream.empty();
    }
    final GridCoverageResource gcr = (GridCoverageResource) resource;
    GridCoverage dataCoverage;
    try {
        dataCoverage = gcr.read(renderingContext.getGridGeometry());
    } catch (NoSuchDataException ex) {
        return Stream.empty();
    } catch (DataStoreException ex) {
        ExceptionPresentation ep = new ExceptionPresentation(ex);
        ep.setLayer(layer);
        ep.setResource(resource);
        return Stream.of(ep);
    }
    if (!Utilities.equalsIgnoreMetadata(CRS.getHorizontalComponent(dataCoverage.getCoordinateReferenceSystem()), renderingContext.getObjectiveCRS())) {
        // coverage is not in objective crs, resample it
        try {
            // we resample the native view of the coverage only, the style will be applied later.
            dataCoverage = new ResampleProcess(dataCoverage, renderingContext.getObjectiveCRS(), null, InterpolationCase.NEIGHBOR, null).executeNow();
        } catch (Exception ex) {
            LOGGER.log(Level.WARNING, "ERROR resample in raster symbolizer renderer", ex);
        }
    }
    final Map.Entry<FeatureSet, MutableStyle> entry;
    try {
        entry = symbol.getMasks(dataCoverage);
    } catch (IOException | TransformException ex) {
        ExceptionPresentation ep = new ExceptionPresentation(ex);
        ep.setLayer(layer);
        ep.setResource(resource);
        return Stream.of(ep);
    }
    final MapLayer subLayer = MapBuilder.createLayer(entry.getKey());
    subLayer.setStyle(entry.getValue());
    return DefaultPortrayalService.present(subLayer, entry.getKey(), renderingContext);
}
Also used : DataStoreException(org.apache.sis.storage.DataStoreException) ResampleProcess(org.geotoolkit.processing.coverage.resample.ResampleProcess) MapLayer(org.apache.sis.portrayal.MapLayer) TransformException(org.opengis.referencing.operation.TransformException) IOException(java.io.IOException) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) IOException(java.io.IOException) NoSuchDataException(org.apache.sis.storage.NoSuchDataException) DataStoreException(org.apache.sis.storage.DataStoreException) TransformException(org.opengis.referencing.operation.TransformException) GridCoverage(org.apache.sis.coverage.grid.GridCoverage) MutableStyle(org.geotoolkit.style.MutableStyle) ExceptionPresentation(org.apache.sis.internal.map.ExceptionPresentation) GridCoverageResource(org.apache.sis.storage.GridCoverageResource) FeatureSet(org.apache.sis.storage.FeatureSet) Map(java.util.Map)

Example 12 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class InlineImageTest method readImage.

@Test
public void readImage() throws Exception {
    final BufferedImage image = new BufferedImage(20, 10, BufferedImage.TYPE_INT_ARGB);
    final String geometry = null;
    final ExternalGraphic external = SF.externalGraphic(new ImageIcon(image), Collections.EMPTY_LIST);
    final Graphic graphic = SF.graphic(Collections.singletonList((GraphicalSymbol) external), LITERAL_ONE_FLOAT, LITERAL_ONE_FLOAT, LITERAL_ONE_FLOAT, DEFAULT_ANCHOR_POINT, DEFAULT_DISPLACEMENT);
    final PointSymbolizer ips = SF.pointSymbolizer("", geometry, DEFAULT_DESCRIPTION, Units.POINT, graphic);
    final MutableStyle style = SF.style(ips);
    final File f = File.createTempFile("sld", ".xml");
    f.deleteOnExit();
    final StyleXmlIO io = new StyleXmlIO();
    io.writeStyle(f, style, Specification.StyledLayerDescriptor.V_1_1_0);
    final MutableStyle result = io.readStyle(f, Specification.SymbologyEncoding.V_1_1_0);
    final Symbolizer s = result.featureTypeStyles().get(0).rules().get(0).symbolizers().get(0);
    assertTrue(s instanceof PointSymbolizer);
    final PointSymbolizer ps = (PointSymbolizer) s;
    final ExternalGraphic eg = (ExternalGraphic) ps.getGraphic().graphicalSymbols().get(0);
    assertNotNull(eg);
    final Icon ri = eg.getInlineContent();
    assertNotNull(ri);
    assertEquals(20, ri.getIconWidth());
    assertEquals(10, ri.getIconHeight());
}
Also used : ImageIcon(javax.swing.ImageIcon) PointSymbolizer(org.opengis.style.PointSymbolizer) MutableStyle(org.geotoolkit.style.MutableStyle) Graphic(org.opengis.style.Graphic) ExternalGraphic(org.opengis.style.ExternalGraphic) GraphicalSymbol(org.opengis.style.GraphicalSymbol) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) Icon(javax.swing.Icon) ImageIcon(javax.swing.ImageIcon) ExternalGraphic(org.opengis.style.ExternalGraphic) File(java.io.File) BufferedImage(java.awt.image.BufferedImage) PointSymbolizer(org.opengis.style.PointSymbolizer) Symbolizer(org.opengis.style.Symbolizer) Test(org.junit.Test)

Example 13 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class SEforSLD100Test method testStyle.

// //////////////////////////////////////////////////////////////////////////
// JAXB TEST MARSHELLING AND UNMARSHELLING FOR STYLE ORDERING //////////////
// //////////////////////////////////////////////////////////////////////////
@Test
public void testStyle() throws JAXBException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_SE_STYLE);
    assertNotNull(obj);
    UserStyle jax = (UserStyle) obj;
    MutableStyle style = TRANSFORMER_GT.visitUserStyle(jax);
    assertNotNull(style);
    assertEquals(style.getName(), valueName);
    assertEquals(style.getDescription().getTitle().toString(), valueTitle);
    assertEquals(style.getDescription().getAbstract().toString(), valueAbstract);
    assertEquals(style.isDefault(), true);
    assertEquals(style.featureTypeStyles().size(), 3);
    // Write test
    UserStyle pvt = TRANSFORMER_OGC.visit(style, null);
    assertNotNull(pvt);
    assertEquals(pvt.getName(), valueName);
    assertEquals(pvt.getTitle(), valueTitle);
    assertEquals(pvt.getAbstract(), valueAbstract);
    assertEquals(pvt.isIsDefault(), Boolean.TRUE);
    assertEquals(pvt.getFeatureTypeStyle().size(), 3);
    MARSHALLER.marshal(pvt, TEST_FILE_SE_STYLE);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : UserStyle(org.geotoolkit.sld.xml.v100.UserStyle) Marshaller(javax.xml.bind.Marshaller) MutableStyle(org.geotoolkit.style.MutableStyle) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 14 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class SEforSLD110Test method testStyle.

// //////////////////////////////////////////////////////////////////////////
// JAXB TEST MARSHELLING AND UNMARSHELLING FOR STYLE ORDERING //////////////
// //////////////////////////////////////////////////////////////////////////
@Test
public void testStyle() throws JAXBException, FactoryException {
    final Unmarshaller UNMARSHALLER = POOL.acquireUnmarshaller();
    final Marshaller MARSHALLER = POOL.acquireMarshaller();
    // Read test
    Object obj = UNMARSHALLER.unmarshal(FILE_SE_STYLE);
    assertNotNull(obj);
    UserStyle jax = (UserStyle) obj;
    MutableStyle style = TRANSFORMER_GT.visitUserStyle(jax);
    assertNotNull(style);
    assertEquals(style.getName(), valueName);
    assertEquals(style.getDescription().getTitle().toString(), valueTitle);
    assertEquals(style.getDescription().getAbstract().toString(), valueAbstract);
    assertEquals(style.isDefault(), true);
    assertEquals(style.featureTypeStyles().size(), 3);
    // Write test
    UserStyle pvt = TRANSFORMER_OGC.visit(style, null);
    assertNotNull(pvt);
    assertEquals(pvt.getName(), valueName);
    assertEquals(String.valueOf(pvt.getDescription().getTitle()), valueTitle);
    assertEquals(String.valueOf(pvt.getDescription().getAbstract()), valueAbstract);
    assertEquals(pvt.isIsDefault(), Boolean.TRUE);
    assertEquals(pvt.getFeatureTypeStyleOrCoverageStyleOrOnlineResource().size(), 3);
    MARSHALLER.marshal(pvt, TEST_FILE_SE_STYLE);
    POOL.recycle(MARSHALLER);
    POOL.recycle(UNMARSHALLER);
}
Also used : UserStyle(org.geotoolkit.sld.xml.v110.UserStyle) Marshaller(javax.xml.bind.Marshaller) MutableStyle(org.geotoolkit.style.MutableStyle) Unmarshaller(javax.xml.bind.Unmarshaller) Test(org.junit.Test)

Example 15 with MutableStyle

use of org.geotoolkit.style.MutableStyle in project geotoolkit by Geomatys.

the class CopyStyleVisitor method visit.

@Override
public MutableStyle visit(Style style, Object data) {
    final MutableStyle copy = SF.style();
    copy.setDefault(style.isDefault());
    copy.setDefaultSpecification(style.getDefaultSpecification());
    copy.setDescription(style.getDescription());
    copy.setName(style.getName());
    for (FeatureTypeStyle fts : style.featureTypeStyles()) {
        copy.featureTypeStyles().add((MutableFeatureTypeStyle) fts.accept(this, data));
    }
    return copy;
}
Also used : MutableStyle(org.geotoolkit.style.MutableStyle) MutableFeatureTypeStyle(org.geotoolkit.style.MutableFeatureTypeStyle) FeatureTypeStyle(org.opengis.style.FeatureTypeStyle)

Aggregations

MutableStyle (org.geotoolkit.style.MutableStyle)55 Expression (org.opengis.filter.Expression)20 MapLayer (org.apache.sis.portrayal.MapLayer)19 Unit (javax.measure.Unit)16 MapLayers (org.apache.sis.portrayal.MapLayers)15 Description (org.opengis.style.Description)15 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)11 Feature (org.opengis.feature.Feature)11 FeatureType (org.opengis.feature.FeatureType)11 Fill (org.opengis.style.Fill)11 GraphicalSymbol (org.opengis.style.GraphicalSymbol)11 Stroke (org.opengis.style.Stroke)11 FeatureTypeBuilder (org.apache.sis.feature.builder.FeatureTypeBuilder)10 FeatureSet (org.apache.sis.storage.FeatureSet)10 GraphicStroke (org.opengis.style.GraphicStroke)10 PointSymbolizer (org.opengis.style.PointSymbolizer)10 BufferedImage (java.awt.image.BufferedImage)9 MutableFeatureTypeStyle (org.geotoolkit.style.MutableFeatureTypeStyle)9 PolygonSymbolizer (org.opengis.style.PolygonSymbolizer)9