Hi,
I am new to geotools. (windows 8.1 - geotols 14.2) I am trying to write an .sld file with the "SE version 1.1.0". (gt-xsd-sld SEConfiguration) I have looked at this page http://docs.geotools.org/stable/userguide/library/xml/style.html to get started. I also looked at the test in gt-xsd-sld; but all the test are for parsing an sld file (I could not find and example that write a file ). Are there any example? There is something like SLDTransformer?(for SE version 1.1.0) I wrote this program (it works; but the output is not what i expected) package org.geotools.tutorial; import org.geotools.factory.CommonFactoryFinder; import org.geotools.se.v1_1.SEConfiguration; import org.geotools.styling.*; import org.geotools.styling.Stroke; import org.geotools.xml.Encoder; import org.opengis.filter.FilterFactory; import javax.xml.transform.TransformerException; import java.awt.*; import java.io.*; /** * Created by alai on 05/04/2016. */ public class TestSE { public static void main(String[] args) throws IOException, TransformerException { // very simple style and SLD ----------------------------------------------- FilterFactory ff = CommonFactoryFinder.getFilterFactory2(); StyleFactory sf = CommonFactoryFinder.getStyleFactory(); Stroke stroke = sf.createStroke(ff.literal(Color.RED), ff.literal(2)); LineSymbolizer lineSymbolizer = sf.createLineSymbolizer(stroke, null); Rule rule = sf.createRule(); rule.symbolizers().add(lineSymbolizer); FeatureTypeStyle featureTypeStyle = sf.createFeatureTypeStyle(new Rule[]{rule});// save to SE ver. 1.1.0 featureTypeStyle.setName("TEST for SE 1.1.0 and SLD 1.0"); Style style = sf.createStyle(); style.featureTypeStyles().add(featureTypeStyle); StyledLayerDescriptor styledLayerDescriptor = sf.createStyledLayerDescriptor(); // save to SLD ver. 1.0 NamedLayer namedLayer = sf.createNamedLayer(); namedLayer.styles().add(style); styledLayerDescriptor.layers().add(namedLayer); // write SLD version 1.0 --------------------------------------------------------------- FileWriter sldFileWriter = new FileWriter(new File("SLDver_1_0.sld")); SLDTransformer aTransformer = new SLDTransformer(); aTransformer.setIndentation(4); aTransformer.transform(styledLayerDescriptor, sldFileWriter); // write SE version 1.1.0 ------------------------------------------------------------------ // http://docs.geotools.org/stable/userguide/library/xml/style.html org.geotools.xml.Configuration configuration = new SEConfiguration(); // configuration.setupBindings(); Encoder encoder = new org.geotools.xml.Encoder( configuration ); OutputStream outputStream = new FileOutputStream("SEver_1_1_0.XML"); encoder.encode(featureTypeStyle , org.geotools.se.v1_1.SE.FeatureTypeStyle , outputStream); //-------------------------------------------------------------------------- ---------------- } } SEver_1_1_0.XML (this is the output) <?xml version="1.0" encoding="UTF-8"?> <se:FeatureTypeStyle xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:se="http://www.opengis.net/se" xmlns:ogc="http://www.opengis.net/ogc"> FeatureTypeStyleImpl[ name=TEST for SE 1.1.0 and SLD 1.0, [], rules=<1>(<RuleImpl> null <LineSymbolizerImp property=null uom=null stroke=org.geotools.styling.StrokeImpl: Color java.awt.Color[r=255,g=0,b=0] Width 2 Opacity 1.0 LineCap butt LineJoin miter Dash Array null Dash Offset 0.0 Fill Graphic null Stroke Graphic null> ), options={}]</se:FeatureTypeStyle> Thanks Andrea Lai
------------------------------------------------------------------------------
_______________________________________________ GeoTools-GT2-Users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
