Search in sources :

Example 1 with StyleFactory

use of org.geotools.styling.StyleFactory in project sldeditor by robward-scisys.

the class SLDUtils method createSLDFromString.

/**
 * Creates a StyledLayerDescriptor object containing a SLD from a string.
 *
 * @param sldData the sld data
 * @return the styled layer descriptor
 */
public static StyledLayerDescriptor createSLDFromString(SLDDataInterface sldData) {
    if ((sldData == null) || (sldData.getSld() == null)) {
        return null;
    }
    StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
    InputStream stream = new ByteArrayInputStream(sldData.getSld().getBytes());
    SLDParser styleReader = new SLDParser(styleFactory, stream);
    URL resourceLocator = getResourceLocator(sldData);
    sldData.setResourceLocator(resourceLocator);
    setResourcelocator(styleReader, resourceLocator);
    StyledLayerDescriptor sld = null;
    try {
        sld = styleReader.parseSLD();
    } catch (RuntimeException e) {
        String errorMessage = String.format("SLD Parser error : %s", sldData.getStyle().toString());
        ConsoleManager.getInstance().error(SLDUtils.class, errorMessage);
        ConsoleManager.getInstance().error(SLDUtils.class, e.getMessage());
    }
    return sld;
}
Also used : StyleFactory(org.geotools.styling.StyleFactory) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SLDParser(org.geotools.styling.SLDParser) URL(java.net.URL)

Example 2 with StyleFactory

use of org.geotools.styling.StyleFactory in project sldeditor by robward-scisys.

the class SLDUtils method readSLDFile.

/**
 * Creates a StyledLayerDescriptor object containing a SLD by reading the contents of a file.
 *
 * @param file the file
 * @return the styled layer descriptor
 */
public static StyledLayerDescriptor readSLDFile(File file) {
    StyledLayerDescriptor sld = null;
    if (file != null) {
        StyleFactory styleFactory = CommonFactoryFinder.getStyleFactory();
        try {
            // By using URL here allows external graphics to loaded properly
            URL url = file.toURI().toURL();
            SLDParser styleReader = new SLDParser(styleFactory, url);
            setResourcelocator(styleReader, file.toURI().toURL());
            sld = styleReader.parseSLD();
        } catch (MalformedURLException e) {
            ConsoleManager.getInstance().exception(SLDUtils.class, e);
        } catch (IOException e) {
            ConsoleManager.getInstance().exception(SLDUtils.class, e);
        }
    }
    return sld;
}
Also used : StyleFactory(org.geotools.styling.StyleFactory) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) MalformedURLException(java.net.MalformedURLException) SLDParser(org.geotools.styling.SLDParser) IOException(java.io.IOException) URL(java.net.URL)

Example 3 with StyleFactory

use of org.geotools.styling.StyleFactory in project sldeditor by robward-scisys.

the class SLDExternalImagesTest method createTestPoint.

/**
 * Creates the test point.
 *
 * @param url the url
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createTestPoint(URL url) {
    StyleBuilder sb = new StyleBuilder();
    StyleFactory styleFactory = sb.getStyleFactory();
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    sld.addStyledLayer(namedLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = styleFactory.createRule();
    fts.rules().add(rule);
    PointSymbolizer point = styleFactory.createPointSymbolizer();
    rule.symbolizers().add(point);
    Graphic graphic = createGraphic(url, styleFactory);
    point.setGraphic(graphic);
    return sld;
}
Also used : StyleFactory(org.geotools.styling.StyleFactory) PointSymbolizer(org.geotools.styling.PointSymbolizer) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) StyleBuilder(org.geotools.styling.StyleBuilder) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer)

Example 4 with StyleFactory

use of org.geotools.styling.StyleFactory in project sldeditor by robward-scisys.

the class SLDExternalImagesTest method createTestPolygon.

/**
 * Creates the test polygon.
 *
 * @param url the url
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createTestPolygon(URL url) {
    StyleBuilder sb = new StyleBuilder();
    StyleFactory styleFactory = sb.getStyleFactory();
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    sld.addStyledLayer(namedLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = styleFactory.createRule();
    fts.rules().add(rule);
    PolygonSymbolizer polygon = styleFactory.createPolygonSymbolizer();
    rule.symbolizers().add(polygon);
    Graphic graphicFill1 = createGraphic(url, styleFactory);
    Graphic graphicFill2 = createGraphic(url, styleFactory);
    Graphic graphicStroke = createGraphic(url, styleFactory);
    Fill fill = styleFactory.createFill(null, null, null, graphicFill1);
    polygon.setFill(fill);
    Stroke stroke = styleFactory.createStroke(null, null, null, null, null, null, null, graphicFill2, graphicStroke);
    polygon.setStroke(stroke);
    return sld;
}
Also used : StyleFactory(org.geotools.styling.StyleFactory) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Fill(org.geotools.styling.Fill) Stroke(org.geotools.styling.Stroke) PolygonSymbolizer(org.geotools.styling.PolygonSymbolizer) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) StyleBuilder(org.geotools.styling.StyleBuilder) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer)

Example 5 with StyleFactory

use of org.geotools.styling.StyleFactory in project sldeditor by robward-scisys.

the class SLDExternalImagesTest method createTestLine.

/**
 * Creates the test line.
 *
 * @param url the url
 * @return the styled layer descriptor
 */
private StyledLayerDescriptor createTestLine(URL url) {
    StyleBuilder sb = new StyleBuilder();
    StyleFactory styleFactory = sb.getStyleFactory();
    StyledLayerDescriptor sld = styleFactory.createStyledLayerDescriptor();
    NamedLayer namedLayer = styleFactory.createNamedLayer();
    sld.addStyledLayer(namedLayer);
    Style style = styleFactory.createStyle();
    namedLayer.addStyle(style);
    List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
    FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle();
    ftsList.add(fts);
    Rule rule = styleFactory.createRule();
    fts.rules().add(rule);
    LineSymbolizer line = styleFactory.createLineSymbolizer();
    rule.symbolizers().add(line);
    Graphic graphicFill = createGraphic(url, styleFactory);
    Graphic graphicStroke = createGraphic(url, styleFactory);
    Stroke stroke = styleFactory.createStroke(null, null, null, null, null, null, null, graphicFill, graphicStroke);
    line.setStroke(stroke);
    return sld;
}
Also used : StyleFactory(org.geotools.styling.StyleFactory) StyledLayerDescriptor(org.geotools.styling.StyledLayerDescriptor) Stroke(org.geotools.styling.Stroke) ExternalGraphic(org.geotools.styling.ExternalGraphic) Graphic(org.geotools.styling.Graphic) LineSymbolizer(org.geotools.styling.LineSymbolizer) StyleBuilder(org.geotools.styling.StyleBuilder) Style(org.geotools.styling.Style) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) FeatureTypeStyle(org.geotools.styling.FeatureTypeStyle) Rule(org.geotools.styling.Rule) NamedLayer(org.geotools.styling.NamedLayer)

Aggregations

StyleFactory (org.geotools.styling.StyleFactory)6 StyledLayerDescriptor (org.geotools.styling.StyledLayerDescriptor)5 ExternalGraphic (org.geotools.styling.ExternalGraphic)3 FeatureTypeStyle (org.geotools.styling.FeatureTypeStyle)3 Graphic (org.geotools.styling.Graphic)3 NamedLayer (org.geotools.styling.NamedLayer)3 Rule (org.geotools.styling.Rule)3 SLDParser (org.geotools.styling.SLDParser)3 Style (org.geotools.styling.Style)3 StyleBuilder (org.geotools.styling.StyleBuilder)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 URL (java.net.URL)2 Stroke (org.geotools.styling.Stroke)2 IOProviderConfigurationException (eu.esdihumboldt.hale.common.core.io.IOProviderConfigurationException)1 IOMessageImpl (eu.esdihumboldt.hale.common.core.io.report.impl.IOMessageImpl)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 MalformedURLException (java.net.MalformedURLException)1 Fill (org.geotools.styling.Fill)1 LineSymbolizer (org.geotools.styling.LineSymbolizer)1