[Schmitzm-commits] r62 - in trunk/src: schmitzm/geotools/feature schmitzm/geotools/gui skrueger/geotools
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Apr 17 20:56:19 CEST 2009
Author: alfonx
Date: 2009-04-17 20:56:17 +0200 (Fri, 17 Apr 2009)
New Revision: 62
Modified:
trunk/src/schmitzm/geotools/feature/FeatureOperationTreeFilter.java
trunk/src/schmitzm/geotools/gui/FeatureCollectionTableModel.java
trunk/src/schmitzm/geotools/gui/FeatureTablePane.java
trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
Log:
* Enabled the "zoom to layer bounds" for single selected points et al.
* Inserted a stub for getColumnCLass() in FeatureCollectionTableModel.java
Modified: trunk/src/schmitzm/geotools/feature/FeatureOperationTreeFilter.java
===================================================================
--- trunk/src/schmitzm/geotools/feature/FeatureOperationTreeFilter.java 2009-04-17 17:39:13 UTC (rev 61)
+++ trunk/src/schmitzm/geotools/feature/FeatureOperationTreeFilter.java 2009-04-17 18:56:17 UTC (rev 62)
@@ -51,16 +51,24 @@
}
/**
- * Prueft, ob ein {@link Feature} dem Filter entspricht. Dies ist der Fall,
- * wenn das Formel-Ergebnis fuer das Feature ungleich 0 ist.
- * @param feature zu ueberpruefendes Feature
- * @return {@code true}, wenn die Auswertung
- */
- public boolean evaluate(Feature feature) {
- Object result = opTree.evaluate(feature);
- return result instanceof Boolean && (Boolean)result ||
- result instanceof Number && ((Number)result).doubleValue() != 0;
- }
+ * Prueft, ob ein {@link Feature} dem Filter entspricht. Dies ist der Fall,
+ * wenn das Formel-Ergebnis fuer das Feature ungleich 0 ist.
+ *
+ * @param feature
+ * zu ueberpruefendes Feature
+ * @return {@code true}, wenn die Auswertung
+ */
+ public boolean evaluate(Feature feature) {
+ try{
+ Object result = opTree.evaluate(feature);
+ return result instanceof Boolean && (Boolean) result
+ || result instanceof Number
+ && ((Number) result).doubleValue() != 0;
+ } catch (Exception e){
+ e.printStackTrace();
+ return false;
+ }
+ }
/**
* Prueft, ob ein {@link Feature} dem Filter entspricht. Dies ist der Fall,
Modified: trunk/src/schmitzm/geotools/gui/FeatureCollectionTableModel.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/FeatureCollectionTableModel.java 2009-04-17 17:39:13 UTC (rev 61)
+++ trunk/src/schmitzm/geotools/gui/FeatureCollectionTableModel.java 2009-04-17 18:56:17 UTC (rev 62)
@@ -19,7 +19,10 @@
import org.geotools.feature.FeatureCollections;
import org.geotools.feature.FeatureIterator;
import org.geotools.feature.FeatureType;
+import org.geotools.geometry.jts.ReferencedEnvelope;
+import com.vividsolutions.jts.geom.Envelope;
+
import schmitzm.geotools.feature.AttributeTypeFilter;
import schmitzm.geotools.feature.FeatureUtil;
import javax.swing.table.AbstractTableModel;
@@ -192,6 +195,12 @@
featureArray = FeatureUtil.featuresToArray(featureTable);
return featureArray[row].getAttribute( attrIdxForCol[col] );
}
+
+ @Override
+ public Class<?> getColumnClass(int columnIndex) {
+ // TODO Hey Martin! Check what the original Datatype is in the FeatureType and return that class. At the moment its sorting the prices 10EUR, 2EUR 22EUR, 9EUR ...
+ return super.getColumnClass(columnIndex);
+ }
/**
* Liefert Features der Tabelle als Array.
@@ -214,4 +223,5 @@
featureCol.add( featureArray[ idx[i] ] );
return featureCol;
}
+
}
Modified: trunk/src/schmitzm/geotools/gui/FeatureTablePane.java
===================================================================
--- trunk/src/schmitzm/geotools/gui/FeatureTablePane.java 2009-04-17 17:39:13 UTC (rev 61)
+++ trunk/src/schmitzm/geotools/gui/FeatureTablePane.java 2009-04-17 18:56:17 UTC (rev 62)
@@ -39,12 +39,15 @@
import org.geotools.map.MapLayer;
import org.geotools.styling.Style;
+import com.vividsolutions.jts.geom.Envelope;
+
import schmitzm.geotools.feature.AttributeTypeFilter;
import schmitzm.geotools.feature.FeatureUtil;
import schmitzm.swing.JPanel;
import schmitzm.swing.MultiSplitPane;
import schmitzm.swing.SortedJTable;
import schmitzm.swing.SwingUtil;
+import skrueger.geotools.StyledFeatureCollectionTableModel;
/**
* Diese Komponente stellt eine Tabelle dar, in der die Attribute einer
@@ -273,22 +276,39 @@
showFeaturesInMap( subCollection );
}
- /**
- * Zeigt einen {@link FeatureCollection} in der Karte an. Diese Funktion
- * hat keinen Einfluss auf die in der Tabelle angezeigten Features!!
- * @param fc eine {@link FeatureCollection}
- */
- protected void showFeaturesInMap(FeatureCollection fc) {
- if ( mapPane == null )
- return;
- mapPane.getContext().clearLayerList();
- if ( fc != null && fc.size() > 0 && fc.getSchema().getDefaultGeometry() != null ) {
- if ( getFeatureStyle() == null )
- setFeatureStyle( FeatureUtil.createDefaultStyle(fc) );
- mapPane.getContext().addLayer(fc, getFeatureStyle() );
- mapPane.setMapArea(fc.getBounds());
- }
- mapPane.refresh();
- }
+ /**
+ * Zeigt einen {@link FeatureCollection} in der Karte an. Diese Funktion hat
+ * keinen Einfluss auf die in der Tabelle angezeigten Features!!
+ *
+ * @param fc
+ * eine {@link FeatureCollection}
+ */
+ protected void showFeaturesInMap(FeatureCollection fc) {
+ if (mapPane == null)
+ return;
+ mapPane.getContext().clearLayerList();
+
+ Envelope bounds = null;
+
+ if (fc != null && fc.size() > 0
+ && fc.getSchema().getDefaultGeometry() != null) {
+ if (getFeatureStyle() == null)
+ setFeatureStyle(FeatureUtil.createDefaultStyle(fc));
+ mapPane.getContext().addLayer(fc, getFeatureStyle());
+ if (featuresTableModel instanceof StyledFeatureCollectionTableModel) {
+ bounds = ((StyledFeatureCollectionTableModel) featuresTableModel)
+ .getBounds();
+ }
+ // featuresTableModel.getFeatureCollection().getBounds();
+ if (bounds == null)
+ bounds = fc.getBounds();
+
+ mapPane.setMapArea(bounds); // zoom to the full bound if available,
+ // otherwise just to the bounds of the
+ // selected.
+
+ }
+ mapPane.refresh();
+ }
}
Modified: trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java
===================================================================
--- trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java 2009-04-17 17:39:13 UTC (rev 61)
+++ trunk/src/skrueger/geotools/StyledFeatureCollectionTableModel.java 2009-04-17 18:56:17 UTC (rev 62)
@@ -22,6 +22,8 @@
import org.geotools.feature.FeatureCollection;
import org.opengis.filter.Filter;
+import com.vividsolutions.jts.geom.Envelope;
+
import schmitzm.geotools.gui.FeatureCollectionTableModel;
import skrueger.AttributeMetaData;
import skrueger.i8n.I8NUtil;
@@ -48,6 +50,8 @@
protected Map<Integer, AttributeMetaData> origAMD = null;
/** Holds the current filter on the table */
protected Filter filter = null;
+ /** Holds the Bounds for all features. Only set once during the constructor **/
+ protected Envelope bounds;
/**
* Creates a new table model for a styled map.
@@ -94,7 +98,7 @@
protected void setFeatureSource(FeatureSource fs, Map<Integer, AttributeMetaData> amd, Filter filter) throws Exception {
if ( filter == null )
filter = Filter.INCLUDE;
-
+
this.featureSource = fs;
this.filter = filter;
this.origAMD = amd;
@@ -102,7 +106,10 @@
FeatureCollection fc = null;
if (fs != null) {
- Query query = new DefaultQuery();
+
+ bounds = fs.getBounds();
+
+ Query query = new DefaultQuery(fs.getSchema().getTypeName(), filter);
if (amd != null) {
// determine the names of the visible Attributes
this.visibleAMD = StyledMapUtil.getVisibleAttributeMetaData(amd, true);
@@ -114,9 +121,22 @@
// create a query for the visible attributes
String[] properties = visibleAttrNames.toArray(new String[0]);
+
query = new DefaultQuery(fs.getSchema().getTypeName(), filter, properties);
}
fc = fs.getFeatures(query);
+
+// FAILS:!!!, even with query = new DefaultQuery(fs.getSchema().getTypeName(), filter);
+ // java.lang.UnsupportedOperationException: Unknown feature
+ // attribute: PQM_MOD
+ // at
+ // schmitzm.geotools.feature.FeatureOperationTree.evaluate(FeatureOperationTree.java:93)
+ // bounds = fc.getBounds();
+ // SK, 17.4.2009
+ //
+ // System.out.println("Filter = "+filter);
+ // System.out.println("Size of FC = "+fc.size());
+ // System.out.println("anz att= "+fc.getNumberOfAttributes());
}
setFeatureCollection(fc);
}
@@ -173,6 +193,13 @@
throw new RuntimeException(err);
}
}
+
+ /**
+ * @return <code>Filter.INCLUDE</code> or the {@link Filter} applied to the Features
+ */
+ public Filter getFilter() {
+ return this.filter;
+ }
/**
* After calling {@code super.reorganize(.)} this method replaced the
@@ -189,7 +216,7 @@
for (int i = 0; i < colNames.length && keys.hasNext(); i++) {
Translation title = visibleAMD.get(keys.next()).getTitle();
if (!I8NUtil.isEmpty(title)) {
- System.out.println("set colname " + i + " to " + title.toString());
+// System.out.println("set colname " + i + " to " + title.toString());
colNames[i] = title.toString();
}
}
@@ -197,4 +224,12 @@
if ( fireTableStructureChanged )
fireTableStructureChanged();
}
+
+ /**
+ * @returns Cached bounds for the whole dataset (without applying the
+ * filter) or <code>null</code>
+ */
+ public Envelope getBounds() {
+ return bounds;
+ }
}
More information about the Schmitzm-commits
mailing list