Hi,
First of all, thank you very much for the code that you kindly provided. It works perfectly when I run it at map creation time.
I've also managed to dynamically change the colour attribute of a particular feature but it doesn't seem to have any effect on what is drawn. I'm kind of thinking that the schema has to be updated. I found a function that suggested it would do this: "updateSchema" but it just returned an error which I will look at in more detail tomorrow. I'm also now thinking (after perusing the JavaDocs) that maybe I have to make use of a FeatureWriter rather than modifying the feature directly.
Thanks again for the code!
Thank you,
Steve
---------- Forwarded message ----------
From: Harsh Jain <[EMAIL PROTECTED] >
Date: Nov 22, 2005 11:31 PM
Subject: Re: [Geotools-gt2-users] How do you apply a different style to one shape in a layer?
To: [EMAIL PROTECTED]
You will need to create a Rule with a proper filter. Use the following function for it. Say if you want the mapping
colour=1 => red
colour=2 => green
call the function with
doit(s, feature, 1, Color.RED); and so on
private void doIt(Style s, FeatureType f, int colourValue, Color c) throws IllegalFilterException{
StyleBuilder sb = new StyleBuilder();
FilterFactory ff = FilterFactory.createFilterFactory();
StyleFactory sf = StyleFactory.createStyleFactory();
FeatureTypeStyle fts = sf.createFeatureTypeStyle();
Rule r = sf.createRule();
CompareFilter cf = ff.createCompareFilter(CompareFilter.COMPARE_EQUALS);
cf.addLeftValue(ff.createAttributeExpression(f, "colour"));
cf.addRightValue(sb.literalExpression(colourValue));
r.setFilter(cf);
PolygonSymbolizer ps = sb.createPolygonSymbolizer(c, Color.BLACK, 2.0);
r.setSymbolizers(new Symbolizer[]{ps});
fts.addRule(r);
s.addFeatureTypeStyle(fts);
}
Let me know if it doesn't work
Hi,
I'm new to Java and new to GeoTools. I've managed to load a shapefile into a layer and can display it using the StyledMapPane.
I can alter the colour of all of the polygons in that layer by replacing the layer's style object.
What I want to do is to change the colour of one of the polygons in the layer.
I have added a field in the shapefile table called "colour" which is an integer which will signify what colour a particular polygon should be drawn in. The problem is I just can't figure out what I need to do to get this to work.
Could someone please tell me which classes I should be looking at, or point me at some sample code?
Thank you very much,
Regards,
Steve Borg
-------------------------------------------------------
This SF.Net email is sponsored by the JBoss Inc. Get Certified Today
Register for a JBoss Training Course. Free Certification Exam
for All Training Attendees Through End of 2005. For more info visit:
http://ads.osdn.com/?ad_id=7628&alloc_id=16845&op=click
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
