Andy, The classification and legend was a bit tricky ...
I've attached an implementation of the Jenks algorithm for your consideration. It can be used to classify your features. Map<FeatureId, Double> densities = new HashMap<FeatureId, Double>(); ... calculate densities ... ClassificationFunction classify = new JenksNBFunction(); ArrayList<Expression> params = new ArrayList<Expression>(); params.add(ff.property("name")); params.add(ff.literal(4)); classify.setParameters(params); RangedClassifier groups = (RangedClassifier) classify.evaluate(densities); You can get the min/max foreach range from groups Also consider a map of class number to color. From there I styled my feature layer by creating a set of rules, each rule containing a filter of a set of feature IDs and a symbolizer tied to a color (from the color lookup map). Hal -----Original Message----- From: Andy Turner [mailto:a.g.d.tur...@leeds.ac.uk] Sent: Wednesday, November 26, 2014 5:51 PM To: 'Hal Mirsky'; geotools-gt2-users@lists.sourceforge.net Subject: RE: [Geotools-gt2-users] Choropleth map legend Thanks Hal, I tried making a class by extending DirectLayer. I tried adding it as a layer to the MapContent. It does something, but I have not figured out what as yet... I'm going to work on this tomorrow. It is most important for me that I can get the bounds for each of the classes. Ideally I would like to produce a legend, but at the moment I haven't found a way of getting the values back... Hopefully I will find a way tomorrow, but if anyone has any further pointers, that would be great. Cheers, Andy -----Original Message----- From: Hal Mirsky [mailto:hmir...@aseg.com] Sent: 25 November 2014 22:22 To: Andy Turner; geotools-gt2-users@lists.sourceforge.net Subject: RE: [Geotools-gt2-users] Choropleth map legend Andy, I derived a class from DirectLayer and implemented the draw method which worked great. Some of the legend text was dynamic (e.g. low/high values for each color). A little interesting to figure out the size of rectangles I needed to draw for each legend item. Here's a snippet: private Font titlef = new Font("Ariel", Font.BOLD, 12); private Font itemf = new Font("Ariel", Font.BOLD, 10); Rectangle2D titleLabelRect = titlef.getStringBounds(title, new FontRenderContext(null, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT, RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT)); Rectangle2D itemLabelRect = itemf.getStringBounds(label, new FontRenderContext(null, RenderingHints.VALUE_TEXT_ANTIALIAS_DEFAULT, RenderingHints.VALUE_FRACTIONALMETRICS_DEFAULT)); // now get the height of the title rectangle and height to use for each legend item: th = (int) titleLabelRect.getHeight(); ih = (int) itemLabelRect.getHeight(); // height of site label. Also used as icon size ... Hope this helps, Hal -----Original Message----- From: Andy Turner [mailto:a.g.d.tur...@leeds.ac.uk] Sent: Tuesday, November 25, 2014 11:36 AM To: geotools-gt2-users@lists.sourceforge.net Subject: [Geotools-gt2-users] Choropleth map legend Hi, I would like to have a map legend for the choropleth maps I am generating, please will you help? To style the main part of the map I have followed an example using ColorBrewer and FilterFactory2. I have a Classifier by calling evaluate on a Function from the FilterFactory2. I've have searched and found others asking about this [1], but no answers. [1] http://gis.stackexchange.com/questions/22962/create-a-color-scale-legend-for -choropleth-map-using-geotools-or-other-open-sou Thanks, Andy http://www.geog.leeds.ac.uk/people/a.turner/index.html ---------------------------------------------------------------------------- -- Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk _______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
JenksNBFunction.java
Description: Binary data
------------------------------------------------------------------------------ Download BIRT iHub F-Type - The Free Enterprise-Grade BIRT Server from Actuate! Instantly Supercharge Your Business Reports and Dashboards with Interactivity, Sharing, Native Excel Exports, App Integration & more Get technology previously reserved for billion-dollar corporations, FREE http://pubads.g.doubleclick.net/gampad/clk?id=157005751&iu=/4140/ostg.clktrk
_______________________________________________ GeoTools-GT2-Users mailing list GeoTools-GT2-Users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users