# Styling features based on a custom rule using GeoTools

I have a Java swing app which loads lines shapefiles which represents a road system. I want to show the congested roads on this map with a separate style.

My current approach

I have two attributes in the shapefile for each line named "DesignCapacity" and "CurrentTraffic". I have a simple rule to check whether the DesignCapacity is less than the CurrentTraffic. The rule is attached to a Line symbolizer which draws the line in a separate color.

LineSymbolizer lineSymbolizer = sb.createLineSymbolizer();
Stroke stroke = sb.createStroke(Color.RED, 4);
lineSymbolizer.setStroke(stroke);
Rule rl = sb.createRule(lineSymbolizer1);
rl.setFilter(sb.getFilterFactory().less(
sb.getFilterFactory().property("DesignCapacity"),
sb.getFilterFactory().property("CurrentTraffic")));
FeatureTypeStyle ft = sb.createFeatureTypeStyle("Feature", rl);

return style;


My objective

I would need to add the "DesignCapacity" and "CurrentTraffic" to a separate database thus removing the two attributes from the shapefile. In that case,

1. Can I use the existing rule based styling approach and set a filter? (Instead of shapefile properties, the values should come from database tables)
2. If styling is not the optimum approach, what would be the best way to achieve this?