Thanks, Michael!! This provided a great deal of insight into how filters and rules work with styles.
I didn't wind up going with the geometry type direction, since I have multiple types of points that will require different icons (thus, I used a PropertyIsEqualTo filter on one of the custom featureType properties to perform the comparison). I seem to be in the same situation with the display of the lines, however. All of the rules appear to be set up and functioning properly; however, LineString features still do not display on the map. I picked up the dependency on the "route" attribute that contains the LineString.class instance, but still to no avail. Below is the rule that I'm adding to the Rule[] for the FeatureTypeStyle. Anything blatantly wrong with this, or should I perhaps be looking elsewhere for the bug? Rule lineRule = sf.createRule(); PropertyIsEqualTo edgeFilter = ff.equal(ff.property("myCustomType"), ff.literal(MyCustomTypes.EDGE), false); // MyCustomTypes is an ENUM, set via the SimpleFeatureBuilder lineRule.setFilter(edgeFilter); Stroke stroke = sf.createStroke(ff.literal(Color.BLUE), ff.literal(1.0f)); LineSymbolizer lineSym = sf.createLineSymbolizer(stroke, geomPropertyName); //geomPropertyName is set to null to use the default geometry lineRule.symbolizers().add(lineSym); I was able to verify that the line features (and all expected attributes) are being added to the FeatureCollections for the displayed map layers. I may wind up testing this style concept out on Polygons, in order to see if I can find some sort of difference in how I'm supposed to deal with points vs. lines vs. anything else. Thanks, Brian On Wed, May 12, 2010 at 10:58 PM, Michael Bedward <michael.bedw...@gmail.com > wrote: > Hello Brian, > > I think each of your rules also needs a filter to specify which > geometry type it is applied to. > > The code snippet below is an example of one way in which you might do this. > > Hope this helps. > > Michael > > // Danger ! Completely untested code > > // this can be null if it is the default feature geometry > String geomPropertyName = ... > > // external graphic URL > URL url = ... > > StyleFactory sf = CommonFactoryFinder.getStyleFactory(null); > FilterFactory2 ff = CommonFactoryFinder.getFilterFactory2(null); > > // create the point rule and give it a filter to identify Point geometry > type > Rule pointRule = sf.createRule(); > Function getGeomFn = ff.function("geometryType", > ff.property(geomPropertyName)); > Filter pointFilter = ff.equals(getGeomFn, ff.literal("Point")); > pointRule.setFilter(pointFilter); > pointRule.setElseFilter(false); > > // symbolizer for the point rule > Graphic graphic = sf.getDefaultGraphic(); > graphic.graphicalSymbols().clear(); > ExternalGraphic eGr = sf.createExternalGraphic(url, "image/png"); > graphic.graphicalSymbols().add(eGr); > Symbolizer sym = sf.createPointSymbolizer(graphic, geomPropertyName); > pointRule.symbolizers().add(sym); > > // create the line rule which doesn't need a filter - it just > // processes anything skipped by the point rule > Rule lineRule = sf.createRule(); > lineRule.setIsElseFilter(true); > Stroke stroke = sf.createStroke(ff.literal(Color.BLUE), ff.literal(1.0f)); > Symbolizer lineSym = sf.createLineSymbolizer(stroke, geomPropertyName); > lineRule.symbolizers().add(lineSym); > > // wrap the rules into a Style > FeatureTypeStyle fts = sf.createFeatureTypeStyle(new Rule[]{pointRule, > lineRule}); > Style style = sf.createStyle(); > style.featureTypeStyles().add(fts); > > The imports for the above are... > > import java.awt.Color; > import java.net.URL; > import org.geotools.factory.CommonFactoryFinder; > import org.geotools.styling.ExternalGraphic; > import org.geotools.styling.FeatureTypeStyle; > import org.geotools.styling.Graphic; > import org.geotools.styling.Rule; > import org.geotools.styling.Stroke; > import org.geotools.styling.Style; > import org.geotools.styling.StyleFactory; > import org.geotools.styling.Symbolizer; > import org.opengis.filter.Filter; > import org.opengis.filter.FilterFactory2; > import org.opengis.filter.expression.Function; > -- Brian Ghigiarelli 570-878-9139
------------------------------------------------------------------------------
_______________________________________________ Geotools-gt2-users mailing list Geotools-gt2-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users