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