Search in sources :

Example 6 with StyleXmlIO

use of org.geotoolkit.sld.xml.StyleXmlIO in project geotoolkit by Geomatys.

the class IsolineSymbolizer method setLineSymbolizer.

public void setLineSymbolizer(LineSymbolizer lineSymbolizer) {
    this.lineSymbolizer = lineSymbolizer;
    if (lineSymbolizer != null) {
        final StyleXmlIO util = new StyleXmlIO();
        this.lineSymbolizerType = util.getTransformerXMLv110().visit(lineSymbolizer, null).getValue();
    }
}
Also used : StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO)

Example 7 with StyleXmlIO

use of org.geotoolkit.sld.xml.StyleXmlIO in project geotoolkit by Geomatys.

the class IsolineSymbolizer method setRasterSymbolizer.

public void setRasterSymbolizer(RasterSymbolizer rasterSymbolizer) {
    this.rasterSymbolizer = rasterSymbolizer;
    if (rasterSymbolizer != null) {
        final StyleXmlIO util = new StyleXmlIO();
        this.rasterSymbolizerType = util.getTransformerXMLv110().visit(rasterSymbolizer, null).getValue();
    }
}
Also used : StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO)

Example 8 with StyleXmlIO

use of org.geotoolkit.sld.xml.StyleXmlIO in project geotoolkit by Geomatys.

the class OGCforSLD110Test method testCustom2.

@Test
public void testCustom2() throws JAXBException, FactoryException {
    StyleXmlIO util = new StyleXmlIO();
    final SortProperty sort = util.readSortBy(OGCforSLD110Test.class.getResource("/org/geotoolkit/test/filter/sortby.xml"), org.geotoolkit.sld.xml.Specification.Filter.V_1_1_0);
    assertEquals("sf:str4Property", sort.getValueReference().getXPath());
    assertEquals(SortOrder.ASCENDING, sort.getSortOrder());
}
Also used : SortProperty(org.opengis.filter.SortProperty) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO) Test(org.junit.Test)

Example 9 with StyleXmlIO

use of org.geotoolkit.sld.xml.StyleXmlIO 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 10 with StyleXmlIO

use of org.geotoolkit.sld.xml.StyleXmlIO in project geotoolkit by Geomatys.

the class StyledLayerDescriptorToReferenceConverter method convert.

/**
 * {@inheritDoc}
 */
@Override
public Reference convert(final StyledLayerDescriptor source, final Map<String, Object> params) throws UnconvertibleObjectException {
    if (params.get(TMP_DIR_PATH) == null) {
        throw new UnconvertibleObjectException("The output directory should be defined.");
    }
    if (source == null) {
        throw new UnconvertibleObjectException("The source is not defined.");
    }
    Reference reference = new Reference();
    reference.setMimeType((String) params.get(MIME));
    reference.setEncoding((String) params.get(ENCODING));
    reference.setSchema((String) params.get(SCHEMA));
    if (WPSMimeType.APP_SLD.val().equalsIgnoreCase(reference.getMimeType())) {
        // create file
        final Path dataFile = buildPath(params, UUID.randomUUID().toString() + ".sld");
        try {
            StyleXmlIO xmlio = new StyleXmlIO();
            xmlio.writeSLD(dataFile, source, Specification.StyledLayerDescriptor.V_1_1_0);
        } catch (JAXBException e) {
            throw new UnconvertibleObjectException(e.getMessage(), e);
        }
        final String relLoc = getRelativeLocation(dataFile, params);
        reference.setHref(params.get(TMP_DIR_URL) + "/" + relLoc);
    } else {
        throw new UnconvertibleObjectException("Unsupported mime-type for " + this.getClass().getName() + " : " + reference.getMimeType());
    }
    return reference;
}
Also used : Path(java.nio.file.Path) UnconvertibleObjectException(org.apache.sis.util.UnconvertibleObjectException) Reference(org.geotoolkit.wps.xml.v200.Reference) JAXBException(javax.xml.bind.JAXBException) StyleXmlIO(org.geotoolkit.sld.xml.StyleXmlIO)

Aggregations

StyleXmlIO (org.geotoolkit.sld.xml.StyleXmlIO)21 Test (org.junit.Test)6 MutableStyle (org.geotoolkit.style.MutableStyle)5 Path (java.nio.file.Path)4 List (java.util.List)3 Expression (org.opengis.filter.Expression)3 File (java.io.File)2 ArrayList (java.util.ArrayList)2 JAXBElement (javax.xml.bind.JAXBElement)2 JAXBException (javax.xml.bind.JAXBException)2 ContentType (org.geotoolkit.owc.xml.v10.ContentType)2 StyleSetType (org.geotoolkit.owc.xml.v10.StyleSetType)2 UserStyle (org.geotoolkit.sld.xml.v110.UserStyle)2 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 LinkedHashMap (java.util.LinkedHashMap)1 Icon (javax.swing.Icon)1 ImageIcon (javax.swing.ImageIcon)1 Envelope2D (org.apache.sis.geometry.Envelope2D)1 MapLayer (org.apache.sis.portrayal.MapLayer)1