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-tp2416113p2416113.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA
-OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise
-Strategies to boost innovation and cut costs with open source participation
-Receive a $600 discount off the registration fee with the source code: SFAD
http://p.sf.net/sfu/XcvMzF8H
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to