Oh good that worked for you!
Well tell me where you looked for the answer; so we can update those docs for
the next person...
Do you have links? Did did you use google search? Did you find any
documentation ... what did you do :-)
My only thought is this: The symbology encoding specification we use for our
style data model demands that we work this way - converting strings to colours.
As such we link to the specification and don't try to retype it in a second
time; why get information second hand?
--
Jody Garnett
On Thursday, 2 June 2011 at 11:48 PM, Javier Moreno wrote:
> lol Jody... I spent ten hours trying to figure it out... and didn't see the
> easier way. Please let me know how can I invite you to take a beer :-)
>
>
> jv
>
> On Thu, Jun 2, 2011 at 2:43 AM, Jody Garnett <[email protected]
> (mailto:[email protected])> wrote:
> > Dude you are working *way* to hard - let geotools do the work for you!
> >
> > It automatically knows it is looking for a color; and will convert your
> > string value to a colour as needed.
> > So a simple ff.proeprty("column") will suffice; as long as the values can
> > be parsed as a color.
> >
> > For more information on why your function did not work; you needed to
> > register it with the system (so it can for example copy it (which is what
> > DuplicatingFilterVisitor is doing). It looks like we did not trust you to
> > modify the filter as it was being used for rendering - so they made a copy.
> >
> > There is a tutorial on making functions here (and registering them for the
> > library):
> > - http://docs.geotools.org/latest/userguide/tutorial/advanced/function.html
> >
> > (Note this tutorial is "Advanced" as it involves you contributing a new
> > idea to geotools; and not simply using what is there)
> >
> >
> >
> > --
> > Jody Garnett
> >
> >
> > On Thursday, 2 June 2011 at 7:23 AM, Javier Moreno wrote:
> >
> >
> >
> > > Argh... looks like in fact the problem is somewhere else, throwing an
> > > exception like this one:
> > >
> > > java.lang.RuntimeException: Unable to find function Color
> > > at
> > > org.geotools.filter.FunctionFinder.findFunction(FunctionFinder.java:177)
> > > at org.geotools.filter.FunctionFinder.findFunction(FunctionFinder.java:74)
> > > at
> > > org.geotools.filter.FilterFactoryImpl.function(FilterFactoryImpl.java:467)
> > > at
> > > org.geotools.filter.visitor.DuplicatingFilterVisitor.visit(DuplicatingFilterVisitor.java:309)
> > > at
> > > org.geotools.filter.FunctionExpressionImpl.accept(FunctionExpressionImpl.java:147)
> > > at
> > > org.geotools.styling.visitor.DuplicatingStyleVisitor.copy(DuplicatingStyleVisitor.java:420)
> > > at
> > > org.geotools.styling.visitor.DuplicatingStyleVisitor.visit(DuplicatingStyleVisitor.java:669)
> > > at org.geotools.styling.FillImpl.accept(FillImpl.java:199)
> > > at
> > > org.geotools.styling.visitor.DuplicatingStyleVisitor.copy(DuplicatingStyleVisitor.java:451)
> > > at
> > > org.geotools.styling.visitor.DuplicatingStyleVisitor.visit(DuplicatingStyleVisitor.java:878)
> > > at org.geotools.styling.MarkImpl.accept(MarkImpl.java:204)
> > > at
> > > org.geotools.styling.visitor.DuplicatingStyleVisitor.copy(DuplicatingStyleVisitor.java:523)
> > > at
> > > org.geotools.styling.visitor.DuplicatingStyleVisitor.copy(DuplicatingStyleVisitor.java:851)
> > > at
> > > org.geotools.styling.visitor.DuplicatingStyleVisitor.visit(DuplicatingStyleVisitor.java:818)
> > > at org.geotools.styling.GraphicImpl.accept(GraphicImpl.java:367)
> > > at
> > > org.geotools.styling.visitor.DuplicatingStyleVisitor.copy(DuplicatingStyleVisitor.java:439)
> > > at
> > > org.geotools.styling.visitor.DuplicatingStyleVisitor.visit(DuplicatingStyleVisitor.java:724)
> > > at
> > > org.geotools.styling.visitor.UomRescaleStyleVisitor.visit(UomRescaleStyleVisitor.java:180)
> > > at
> > > org.geotools.styling.PointSymbolizerImpl.accept(PointSymbolizerImpl.java:91)
> > > at
> > > org.geotools.styling.visitor.DuplicatingStyleVisitor.copy(DuplicatingStyleVisitor.java:537)
> > > at
> > > org.geotools.styling.visitor.DuplicatingStyleVisitor.visit(DuplicatingStyleVisitor.java:275)
> > > at
> > > org.geotools.renderer.lite.StreamingRenderer.rescaleFeatureTypeStyle(StreamingRenderer.java:1846)
> > > at
> > > org.geotools.renderer.lite.StreamingRenderer.applyUnitRescale(StreamingRenderer.java:1824)
> > > at
> > > org.geotools.renderer.lite.StreamingRenderer.processStylers(StreamingRenderer.java:1774)
> > > at
> > > org.geotools.renderer.lite.StreamingRenderer.paint(StreamingRenderer.java:707)
> > > at
> > > org.geotools.renderer.lite.StreamingRenderer.paint(StreamingRenderer.java:533)
> > >
> > >
> > >
> > > On Wed, Jun 1, 2011 at 11:09 PM, Javier Moreno <[email protected]
> > > (mailto:[email protected])> wrote:
> > > > Hi everybody!
> > > >
> > > > I'm trying to stylish a shape and I would like to draw the points with
> > > > the color that is written in a feature attribute. The name of the
> > > > attribute is "FILL" and its value is just a rgb triplet string
> > > > ("#A0A0A0", for example).
> > > >
> > > > I've been looking at the documentation and as far as I can understand
> > > > it should result in something like this (based on an example of the
> > > > doc):
> > > >
> > > > class ColorFunction extends FunctionExpressionImpl {
> > > > public static final FunctionName NAME = new
> > > > FunctionNameImpl("Colorizador", 0);
> > > > public ColorFunction() {
> > > > super("Color", filterFactory.literal("Color"));
> > > > super.fallback =
> > > > CommonFactoryFinder.getFilterFactory2(null).literal(Color.WHITE);
> > > > }
> > > > @Override
> > > > public int getArgCount() {
> > > > return 0;
> > > > }
> > > >
> > > > @Override
> > > > public Object evaluate(SimpleFeature feature) {
> > > > String fill = (String) feature.getAttribute("FILL");
> > > > ...
> > > > Color color = new Color(...);
> > > > return color;
> > > > }
> > > > }
> > > >
> > > >
> > > > class XXX {
> > > > ...
> > > > public Style getStyle() {
> > > > style = styleFactory.createStyle();
> > > > FeatureTypeStyle fts = styleFactory.createFeatureTypeStyle(
> > > > new Rule[]{ this.createRule("dummy", 10); }
> > > > style.featureTypeStyles().add(fts);
> > > > return style;
> > > > }
> > > >
> > > > protected Rule createRule(String name, int size) {
> > > > ColorFunction colorFn = new ColorFunction();
> > > >
> > > > Graphic gr = styleFactory.createDefaultGraphic();
> > > > Mark mark = styleFactory.getCircleMark();
> > > > mark.setStroke(styleFactory.createStroke(
> > > > colorFn, filterFactory.literal(1), filterFactory.literal(0.5)));
> > > > mark.setFill(styleFactory.createFill(
> > > > colorFn, filterFactory.literal(1), filterFactory.literal(0.3),
> > > > null));
> > > > gr.graphicalSymbols().clear();
> > > > gr.graphicalSymbols().add(mark);
> > > > gr.setSize(filterFactory.literal(size));
> > > > Rule rule = styleFactory.createRule();
> > > > PointSymbolizer sym = styleFactory.createPointSymbolizer(gr, null);
> > > > rule.setName(name);
> > > > rule.symbolizers().add(sym);
> > > > return rule;
> > > > }
> > > >
> > > > }
> > > >
> > > > If I've understood it right once applied the StreamingRenderer should
> > > > invoke the ColorFunction evaluate(...) method for each point instance
> > > > but looks like it's never call and I'm running out of ideas. Could
> > > > someone tell me what's happening? Maybe am I absolutely wrong about the
> > > > way this should be implemented?
> > > >
> > > > Thanks in advance!
> > > >
> > > > jv
> > > ------------------------------------------------------------------------------
> > > Simplify data backup and recovery for your virtual environment with
> > > vRanger.
> > > Installation's a snap, and flexible recovery options mean your data is
> > > safe,
> > > secure and there when you need it. Data protection magic?
> > > Nope - It's vRanger. Get your free trial download today.
> > > http://p.sf.net/sfu/quest-sfdev2dev
> > > _______________________________________________
> > > Geotools-gt2-users mailing list
> > > [email protected]
> > > (mailto:[email protected])
> > > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
> >
>
------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger.
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today.
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users