Thanks Michael for your advice. I also decided to set styles programmatically because SLDs are easy only for rather simple styles or for raster data. When you decide to create your own functions, it start to get ugly...
From what I see in the code you wrote, you don't use rules. How would you do to process a FeatureType differently depending on a feature attribute ? My idea so far is to use filters or aggregate functions (thanks Jody) on my feature collection (see example below). But this way, I have to create a layer for each style... Which could quickly become annoying and I don't know what could be the consequences on performances. featureSource = dataStore.getFeatureSource(typeName); Filter filter = null; filter = CQL.toFilter("depth >= 50"); FeatureCollection<SimpleFeatureType, SimpleFeature> fc = featureSource.getFeatures(filter); schema = featureSource.getSchema(); Style isobathStyle = createStyle(schema, Color.GREEN); DefaultMapLayer isobathsLayer = new DefaultMapLayer(fc,isobathStyle); Le 17 févr. 09 à 03:55, Michael Bedward a écrit : > Hi Benoît, > > I really struggle with styles for all but the simplest cases. I > mostly want to set styles programmatically rather than use SLD files - > but often find myself stumped by how to avoid deprecated methods. > > For simple, constant line and polygon styles I use methods like these: > > public Style createPolygonStyle(SimpleFeatureType type, Color > fill, Color outline, double width) throws IOException { > Class<?> binding = > type.getGeometryDescriptor().getType().getBinding(); > if (binding.isAssignableFrom(Polygon.class) || > binding.isAssignableFrom(MultiPolygon.class)) { > StyleFactory factory = > CommonFactoryFinder.getStyleFactory(null); > StyleBuilder sb = new StyleBuilder(factory); > PolygonSymbolizer sym = sb.createPolygonSymbolizer(fill, > outline, width); > Style style = sb.createStyle(type.getTypeName(), sym); > return style; > > } else { > throw new IllegalStateException("type doesn't have Polygon > geometry"); > } > } > > As an aside: I've only just discovered DynamicPolygonStyle2D and > related classes in org.geotools.renderer.style. Does anyone use these > ? > > Michael > > > 2009/2/17 Benoît Thiébault <thieba...@artenum.com>: >> Hi everyone, >> >> I'm using geotools 2.5 and I try to set styles programmatically, from >> examples provided on the geotools tutorials (like here >> http://docs.codehaus.org/display/GEOTDOC/05+Style >> or there http://docs.codehaus.org/display/GEOTDOC/09+ShapeLab) >> >> In both cases, a lot of methods seem to be deprecated and "will be >> replaced by live lists in 2.6.x". As Geotools 2.6 is not stable yet, >> what is the best solution to define styles without depending on these >> deprecated methods ? >> >> Any example of code would be greatly appreciated >> >> Benoît >> ------------------------------------------------------------------------------ >> 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 >> Geotools-gt2-users@lists.sourceforge.net >> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users >> > > ------------------------------------------------------------------------------ > 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 > Geotools-gt2-users@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > Benoît Thiébault Société Artenum 24 rue Louis Blanc, 75010 Paris tel: +33 (0)1 46 94 67 54 Artenum - Science & Groupware - http://www.artenum.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 Geotools-gt2-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users