[Schmitzm-commits] r489 - in branches/1.0-gt2-2.6/src: schmitzm/geotools/styling schmitzm/jfree schmitzm/jfree/chart/selection schmitzm/jfree/chart/style skrueger/geotools/selection
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Tue Oct 20 22:04:39 CEST 2009
Author: alfonx
Date: 2009-10-20 22:04:38 +0200 (Tue, 20 Oct 2009)
New Revision: 489
Modified:
branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
branches/1.0-gt2-2.6/src/schmitzm/jfree/JFreeChartUtil.java
branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/selection/CategoryDatasetSelectionModel.java
branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ScatterChartStyle.java
branches/1.0-gt2-2.6/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java
branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
Log:
* chart legend shows r?\194?\178 for regression line
Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java 2009-10-20 19:23:31 UTC (rev 488)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/styling/StylingUtil.java 2009-10-20 20:04:38 UTC (rev 489)
@@ -1656,7 +1656,7 @@
Symbolizer[] symbolizers = new Symbolizer[0];
switch (geometryForm) {
-
+
case POINT:
PointSymbolizer ps = STYLE_FACTORY.createPointSymbolizer();
ps.setGraphic(SELECTION_GRAPHIC1);
Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/JFreeChartUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/JFreeChartUtil.java 2009-10-20 19:23:31 UTC (rev 488)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/JFreeChartUtil.java 2009-10-20 20:04:38 UTC (rev 489)
@@ -30,6 +30,8 @@
package schmitzm.jfree;
import java.awt.Color;
+import java.text.DecimalFormat;
+import java.text.NumberFormat;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
@@ -507,7 +509,7 @@
// only if there are at least 2 items, otherwise we would get a IllegalArgumentException
if ( ((XYSeriesCollection)dataset).getItemCount(0)>=2 ) {
// create sample data for curve (plot function directly is not yet available)
- XYDataset regressionData = createRegressionLineDataset((XYSeriesCollection)dataset,0,title+" (RegressionLine)",2);
+ XYDataset regressionData = createRegressionLineDataset((XYSeriesCollection)dataset,0,title+" Regression line",2);
if ( regressionData != null )
addRegressionLineToPlot(plot, regressionData, Color.blue);
} else {
@@ -526,7 +528,7 @@
* @param seriesKey the key for the created dataset
* @param sampleCnt count of created samples
*/
- public static XYDataset createRegressionLineDataset(XYSeriesCollection dataset, int series, Comparable<?> seriesKey, int sampleCount) {
+ public static XYDataset createRegressionLineDataset(XYSeriesCollection dataset, int series, String seriesKey, int sampleCount) {
double minX = dataset.getSeries(0).getMinX();
double maxX = dataset.getSeries(0).getMaxX();
return createRegressionLineDataset(dataset,series,seriesKey,minX,maxX,sampleCount);
@@ -543,9 +545,12 @@
* @return {@code null} if the regression data could not be created (because of an
* error
*/
- public static XYDataset createRegressionLineDataset(XYDataset dataset, int series, Comparable<?> seriesKey, double startX, double endX, int sampleCount) {
+ public static XYDataset createRegressionLineDataset(XYDataset dataset, int series, String seriesKey, double startX, double endX, int sampleCount) {
try {
double[] coefficients = Regression.getOLSRegression(dataset, series);
+
+ seriesKey += " r²=" + DecimalFormat.getInstance().format(coefficients[1]*coefficients[1]);
+
Function2D curve = new LineFunction2D(coefficients[0], coefficients[1]);
return DatasetUtilities.sampleFunction2D(curve, startX, endX, 2, seriesKey);
} catch (Exception err) {
Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/selection/CategoryDatasetSelectionModel.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/selection/CategoryDatasetSelectionModel.java 2009-10-20 19:23:31 UTC (rev 488)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/selection/CategoryDatasetSelectionModel.java 2009-10-20 20:04:38 UTC (rev 489)
@@ -62,6 +62,7 @@
if ( event.getDataset() != this.dataset ||
!(event.getDataset() instanceof CategoryDataset) )
return;
+
CategoryDataset changedDataset = (CategoryDataset)event.getDataset();
// check whether all series are still present
Modified: branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ScatterChartStyle.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ScatterChartStyle.java 2009-10-20 19:23:31 UTC (rev 488)
+++ branches/1.0-gt2-2.6/src/schmitzm/jfree/chart/style/ScatterChartStyle.java 2009-10-20 20:04:38 UTC (rev 489)
@@ -140,7 +140,7 @@
// Create sample data for regression line for primary dataset (primary series)
// -> plot function directly is not yet available in JFreeChart
XYSeriesCollection dataset = (XYSeriesCollection)chart.getXYPlot().getDataset();
- String regressionTitle = getTitleStyle().getLabel() + " (RegressionLine)";
+ String regressionTitle = getTitleStyle().getLabel() + " Regression line"; //i8n
XYDataset regressionData = JFreeChartUtil.createRegressionLineDataset(
dataset, 0, regressionTitle, 2);
// Add regression line to plot (with default color)
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java 2009-10-20 19:23:31 UTC (rev 488)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/selection/ChartSelectionSynchronizer.java 2009-10-20 20:04:38 UTC (rev 489)
@@ -89,9 +89,8 @@
@Override
public void propertyChange(PropertyChangeEvent evt) {
- if (!isEnabled()) {
+ if (!isEnabled())
return;
- }
if (!(evt instanceof StyledLayerSelectionEvent))
return;
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java 2009-10-20 19:23:31 UTC (rev 488)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/selection/FeatureMapLayerSelectionSynchronizer.java 2009-10-20 20:04:38 UTC (rev 489)
@@ -45,6 +45,7 @@
import java.awt.RenderingHints;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
+import java.io.File;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -56,6 +57,7 @@
import javax.swing.event.ListSelectionListener;
import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.FeatureIterator;
import org.geotools.map.MapLayer;
import org.geotools.renderer.GTRenderer;
import org.geotools.renderer.label.LabelCacheImpl;
@@ -75,6 +77,7 @@
import schmitzm.geotools.map.event.JMapPaneListener;
import schmitzm.geotools.styling.StylingUtil;
import skrueger.geotools.MapPaneToolBar;
+import skrueger.geotools.StyledFeaturesInterface;
import skrueger.geotools.StyledLayerInterface;
/**
@@ -104,7 +107,7 @@
* model.
*/
protected final MapLayer mapLayer;
- protected final StyledLayerInterface<?> styledLayer;
+ protected final StyledFeaturesInterface<?> styledLayer;
protected final JMapPane mapPane;
private final MapPaneToolBar toolBar;
private final HashMap<Object, Object> defaultGTRenderingHints;
@@ -121,7 +124,7 @@
*/
public FeatureMapLayerSelectionSynchronizer(
StyledFeatureLayerSelectionModel layerSelModel,
- StyledLayerInterface<?> styledLayer, MapLayer mapLayer,
+ StyledFeaturesInterface<?> styledLayer, MapLayer mapLayer,
JMapPane mapPane, MapPaneToolBar toolBar,
HashMap<Object, Object> defaultGTRenderingHints) {
@@ -224,27 +227,44 @@
*
* Add a Filter to the selectionMapStyle, so that it is only
* used on objects that are selected. <br/>
+ * To optimize rendering speed, the filter checks whether more
+ * than half of the features are selected. If so, the filter is
+ * inverted to be shorter.
*
- * Note 1:<br/>
- * It is NEVER allowed to GeoTools extend Filter () { .. } (and
- * write tests into the evaluate block). Especially for the
- * ShapeFileRenderer, we may only use a geotools Filter.<br/>
- *
- * Note 2:<br/>
- * The FilterUtil.FILTER_FAC2.id(fids) wants a set of
- * FeatureId-Objects!
*/
- Set<FeatureId> fids = new HashSet<FeatureId>();
- for (String fid : newSelection) {
- fids.add(FilterUtil.FILTER_FAC2.featureId(fid));
+ final FeatureCollection<SimpleFeatureType, SimpleFeature> featureCollectionFiltered = styledLayer
+ .getFeatureCollectionFiltered();
+ if (newSelection.size() > featureCollectionFiltered.size() / 2) {
+ FeatureIterator<SimpleFeature> iterator = featureCollectionFiltered
+ .features();
+ Set<FeatureId> antiFids = new HashSet<FeatureId>();
+ try {
+ while (iterator.hasNext()) {
+ SimpleFeature next = iterator.next();
+ if (!newSelection.contains(next.getID()))
+ antiFids.add(FilterUtil.FILTER_FAC2
+ .featureId(next.getID()));
+ }
+
+ selectionFTStyle.rules().get(0).setFilter(
+ FilterUtil.FILTER_FAC2
+ .not(FilterUtil.FILTER_FAC2
+ .id(antiFids)));
+
+ } finally {
+ featureCollectionFiltered.close(iterator);
+ }
+ } else {
+ Set<FeatureId> fids = new HashSet<FeatureId>();
+ for (String fid : newSelection) {
+ fids.add(FilterUtil.FILTER_FAC2.featureId(fid));
+ }
+
+ selectionFTStyle.rules().get(0).setFilter(
+ FilterUtil.FILTER_FAC2.id(fids));
}
-
- LOGGER.debug("The selection filter:"+fids);
- selectionFTStyle.rules().get(0).setFilter(
- FilterUtil.FILTER_FAC2.id(fids));
-
// Maybe there has already been another selection
// FeatureTypeStyle... Let's replace it...
boolean foundAndReplaced = false;
@@ -268,6 +288,13 @@
dsv.visit(originalStyle);
Style newStyle = (Style) dsv.getCopy();
+ StylingUtil.saveStyleToSLD(newStyle, new File(
+ "/home/stefan/Desktop/selection.sld"));
+
+ // DuplicatingStyleVisitor dsv = new DuplicatingStyleVisitor();
+ // dsv.visit(originalStyle);
+ // Style newStyle = originalStyle;
+
// Style newStyle = StylingUtil.STYLE_BUILDER.createStyle();
// newStyle.featureTypeStyles().addAll(originalStyle.featureTypeStyles());
mapLayer.setStyle(newStyle);
@@ -364,7 +391,7 @@
return;
}
-// LOGGER.debug("do event " + fse);
+ // LOGGER.debug("do event " + fse);
// Avoid event circles in propertyChange(..)
selectionChangeCausedByMe = true;
More information about the Schmitzm-commits
mailing list