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);
Rule rl = sb.createRule(lineSymbolizer1);
FeatureTypeStyle ft = sb.createFeatureTypeStyle("Feature", rl);

return style;

enter image description here

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?

1 Answer 1


Your described approach will not work as the styling engine (renderer) only has information about the current feature when it comes to draw it.

The easiest solution is to import your shapefile into your database and then create a view that joins the roads with the table holding your traffic details and use that to draw the map. It will be faster and more flexible too.

  • Pardon me if this is blunt request, for I'm new to geotools. But could you please explain what you meant by "create a view that joins the roads with the the table holding you traffic details and use that to draw the map". I've followed the geotools examples and tried most of them by my own.
    – tybandara
    Apr 20, 2016 at 8:59
  • A view is a database thing and not really anything to do with GeoTools, try docs.qgis.org/2.2/en/docs/training_manual/spatial_databases/…
    – Ian Turton
    Apr 20, 2016 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.