Hi list, 
I'm trying to make themes by Geotools on a map service wms (Geoserver). 
I'm using the sld. 
I added SLD=http://localhost:8080/webGeoTools/sld.xml at the call wms and
it's work fine
but now, I would like to create the file sld in my code java and then pass
it as string to wms by: SLD_BODY = "_________________" 

with Geotools how can I create this? 

my sld file is: 
<StyledLayerDescriptor version="1.0.0">
        <NamedLayer>
                <Name>test:Province</Name>
                <UserStyle>
                        <Title>title sld</Title>
                        <FeatureTypeStyle>
                                <Rule>
                                        <Filter>
                                                <PropertyIsEqualTo>
                                                
<PropertyName>NOME_PRO</PropertyName>
                                                <Literal>MILANO</Literal>
                                                </PropertyIsEqualTo>
                                        </Filter>
                                        <PolygonSymbolizer>
                                                <Geometry>
                                                        
<PropertyName>the_geom</PropertyName>
                                                </Geometry>
                                                <Fill>
                                                        <CssParameter 
name="fill">#ff0000</CssParameter>
                                                </Fill>
                                        </PolygonSymbolizer>
                                </Rule>
                        </FeatureTypeStyle>
                </UserStyle>
        </NamedLayer>
</StyledLayerDescriptor>


I tried writing this code to get the same file, but I am missing something
.... 
  private String buldSLD() {
    String styleAsXml="";
    StyledLayerDescriptor sld = new StyledLayerDescriptorImpl();
    NamedLayer nameLayer = new NamedLayerImpl();
    nameLayer.setName("test:Province");
    StyleBuilder builder = new StyleBuilder();
    Style style = builder.createStyle();
    style.setName("MyStyle");
    try {

      FilterFactoryImpl factory = new FilterFactoryImpl();
      Expression exp1 = builder.attributeExpression("NOME_PRO");
      Expression exp2 = builder.attributeExpression("MILANO");
      PropertyIsEqualTo eq = factory.equal(exp1, exp2, true);
      
      PolygonSymbolizerImpl pol =
(PolygonSymbolizerImpl)builder.createPolygonSymbolizer(Color.yellow,
Color.gray, 2);
      pol.setGeometryPropertyName("the_geom");
      Rule rule =builder.createRule(pol);
      rule.setFilter(eq);
      FeatureTypeStyle st = builder.createFeatureTypeStyle("uno", rule);
      FeatureTypeStyle[] fts = new FeatureTypeStyle[1];
      fts[0] = st;
      style.addFeatureTypeStyle(st);
      
      SLDUserStyleBinding user = new
SLDUserStyleBinding(builder.getStyleFactory());
      nameLayer.addStyle(style);
      
      SLDTransformer transform = new SLDTransformer();
      styleAsXml = transform.transform(style);
      System.out.println(styleAsXml);
      styleAsXml = URLEncoder.encode(styleAsXml);
      System.out.println(styleAsXml);
    } catch(TransformerException e) {
      e.printStackTrace();
    }
    return styleAsXml;
  }

then i pass this string with SLD_BODY=
but wms return an error:
<?xml version="1.0" encoding="UTF-8" standalone="no"?><!DOCTYPE
ServiceExceptionReport SYSTEM
"http://schemas.opengis.net/wms/1.1.1/WMS_exception_1_1_1.dtd";>
<ServiceExceptionReport version="1.1.1" >   <ServiceException>
        java.lang.NullPointerException
        null
</ServiceException></ServiceExceptionReport>

help me! 
thanks
Peppe
-- 
View this message in context: 
http://n2.nabble.com/Create-sld-dinamically-tp2415506p2415506.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Apps built with the Adobe(R) Flex(R) framework and Flex Builder(TM) are
powering Web 2.0 with engaging, cross-platform capabilities. Quickly and
easily build your RIAs with Flex Builder, the Eclipse(TM)based development
software that enables intelligent coding and step-through debugging.
Download the free 60 day trial. http://p.sf.net/sfu/www-adobe-com
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to