Thanks Justin,

It is error free now but doesnt do what i want.

What i am trying to do is to get all features from shapefile and 
render them on map depending on their colour attribute, e.g.

colour=1 => blue
colour=2 => black ...

I am probably doing something wrong but dont know what:

FeatureSource<SimpleFeatureType,SimpleFeature> featureSource;
FeatureCollection<SimpleFeatureType, SimpleFeature> collection;
FeatureIterator<org.opengis.feature.simple.SimpleFeature> iterator;

featureSource = pgDatastore.getFeatureSource("bugsites");
collection = featureSource.getFeatures();
iterator = collection.features();

try {
    while (iterator.hasNext()) {
        SimpleFeature feature = iterator.next();
        createBugsitesStyle(style,feature,1,Color.BLACK);
        createBugsitesStyle(style,feature,2,Color.GREEN); ...
     }
} finally {
   iterator.close();
}

map.addLayer(fs, style);

private static Style createBugsitesStyle(Style style, SimpleFeature feature, 
int colourValue, Color c) throws IllegalFilterException {

        StyleBuilder sb = new StyleBuilder();
        FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
        PropertyIsEqualTo cf = ff.equals(ff.property("Colour"), 
ff.literal(colourValue));

        StyleFactory sf = CommonFactoryFinder.getStyleFactory(null);
             FeatureTypeStyle fts = sf.createFeatureTypeStyle();
             Rule r = sf.createRule();

             cf.evaluate(feature);
             r.setFilter(cf);

             Mark circle = sb.createMark(StyleBuilder.MARK_CIRCLE, c, 
Color.BLACK, 1);
             Graphic grBug = sb.createGraphic(null, circle, null);
             PointSymbolizer ps = sb.createPointSymbolizer(grBug);
             r.setSymbolizers(new Symbolizer [ ]{ps});

             fts.addRule(r);
             style.addFeatureTypeStyle(fts);

             return style;
}




Yeah, the filter interfaces are now based on geoapi (. The following is 
the equivalent:

import org.opengis.filter.FilterFactory;
import org.opengis.filter.PropertyIsEqualTo;
...

FilterFactory ff = CommonFactoryFinder. getFilterFactory(null);
PropertyIsEqualTo cf = ff.equals( ff.property( "color" ), 
ff.literal(colorValue) );

Hope that helps.

-Justin

iceDice wrote:
> Hello guys,
> 
> I try to do something similar like this in GeoTools-2.5.4 but i got errors.
> It seems that i use some deprecated methods.
> 
> FilterFactory ff = CommonFactoryFinder.getFilterFactory(null);
> 
> 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);
> 
> Can someone tell me how to do this on other way in GeoTools-2.5.4?
> 
> Thanks.


-- 
Justin Deoliveira
OpenGeo - http://opengeo.org
Enterprise support for open source geospatial.

------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users



-- 
View this message in context: 
http://n2.nabble.com/Geotools-2.5.4_CompareFilter-tp2654797p2661036.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


------------------------------------------------------------------------------
Stay on top of everything new and different, both inside and 
around Java (TM) technology - register by April 22, and save
$200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco.
300 plus technical and hands-on sessions. Register today. 
Use priority code J9JMT32. http://p.sf.net/sfu/p
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to