Forgot to add this to the list. Might be useful
---------- Forwarded message ----------
From: Harsh Jain <ha...@gm...>
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: me...@bo...
You will need to create a Rule with a proper filter. Use the following
function for it. Say if you want the mapping
colour=3D1 =3D> red
colour=3D2 =3D> 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 =3D new StyleBuilder();
FilterFactory ff =3D FilterFactory.createFilterFactory();
StyleFactory sf =3D StyleFactory.createStyleFactory();
FeatureTypeStyle fts =3D sf.createFeatureTypeStyle();
Rule r =3D sf.createRule();
CompareFilter cf =3D ff.createCompareFilter(CompareFilter.COMPARE_EQUALS);
cf.addLeftValue(ff.createAttributeExpression(f, "colour"));
cf.addRightValue(sb.literalExpression(colourValue));
r.setFilter(cf);
PolygonSymbolizer ps =3D 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
On 11/22/05, Steve Borg <me...@bo...> wrote:
>
> Hi,
>
> I'm new to Java and new to GeoTools. I've managed to load a shapefile int=
o
> 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 dra=
wn
> 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=3D7628&alloc_id=3D16845&op=3Dclick
> _______________________________________________
> Geotools-gt2-users mailing list
> Geo...@li...
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
>
|