Hi Brian: There is a constraint but it is up a bit higher in the data structure then Rule.
On this page there are some nice diagrams I did up: - http://docs.codehaus.org/display/GEOTDOC/04+Styling I always have to go back and look at them when making a style for myself. I think it is semanticTypeIdentifierss (POINT, LINE etc...). Jody On 15/05/2010, at 12:13 AM, Brian Ghigiarelli wrote: > A few more notes to the general community (unless I'm the only one running > into these problems; please correct me if I'm mistaken on any of this): > Point feature types are dependent upon a "location" attribute that is an > instance of com.vividsolutions.jts.geom.Point > LineString feature types are dependent upon a "route" attribute that is an > instance of com.vividsolutions.jts.geom.LineString > I was able to get my line features to display by putting them on another > layer with a new style (essentially a cut-paste of the Rule/Filter from the > primary Point style). I'm starting to wonder if there is some sort of > constraint on Rules that they can only be applied to one geometry type. I > realize that thought may not make sense, and Michael's previous email states > otherwise, but I just haven't found a way to have Rules for features of > different geometry types in the same Style on the same MapLayer. I struggled > with Michael's suggestion for a short while before taking the "new layer" > approach, but I'd still like to do things the "right way," or at least a > little bit closer to the "good enough" way. Might get back to that in a bit > now that I've got something to show for now. (gotta love software for that, > huh?) > > Ciao for now, > Brian > > On Thu, May 13, 2010 at 10:14 AM, Brian Ghigiarelli <briang...@gmail.com> > wrote: > 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 > > > > -- > 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
------------------------------------------------------------------------------
_______________________________________________ Geotools-gt2-users mailing list Geotools-gt2-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users