[Schmitzm-commits] r426 - in branches/1.0-gt2-2.6/src: schmitzm/geotools/feature skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Fri Oct 2 19:20:01 CEST 2009


Author: alfonx
Date: 2009-10-02 19:20:00 +0200 (Fri, 02 Oct 2009)
New Revision: 426

Modified:
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java
   branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollection.java
   branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeaturesInterface.java
Log:
* Added setFilter, getFilter and getSchema to StyledFeaturesInterface
* Changed AtlasStyler to not work an FeatureCollection anymore, but on a StyledFeatureInterface. Otherwise the AtlasStyler didn't have proper knowledge about the first-level filter associated with the layer.
* Start slowly to move MigLayout into the AtlasStyler

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java	2009-10-02 14:16:12 UTC (rev 425)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/CQLFilterParser.java	2009-10-02 17:20:00 UTC (rev 426)
@@ -30,11 +30,9 @@
 
 package schmitzm.geotools.feature;
 
-import org.geotools.factory.CommonFactoryFinder;
 import org.geotools.filter.text.cql2.CQL;
 import org.geotools.filter.text.cql2.CQLException;
 import org.opengis.filter.Filter;
-//import org.opengis.filter.FilterFactory;
 
 /**
  * This parser creates a CQL-{@link Filter} from a rule string.

Modified: branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java
===================================================================
--- branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-10-02 14:16:12 UTC (rev 425)
+++ branches/1.0-gt2-2.6/src/schmitzm/geotools/feature/FeatureUtil.java	2009-10-02 17:20:00 UTC (rev 426)
@@ -192,7 +192,7 @@
 	 * Enthaelt die {@link AttributeDescriptor AttributeTypes}, fuer die
 	 * automatisch Werte generiert werden koennen.
 	 */
-	private static HashMap<AttributeDescriptor, AutoValueGenerator> autoAttrValueGenerators = new HashMap<AttributeDescriptor, AutoValueGenerator>();
+	private static HashMap<AttributeDescriptor, AutoValueGenerator<?>> autoAttrValueGenerators = new HashMap<AttributeDescriptor, AutoValueGenerator<?>>();
 
 	/**
 	 * Determines the kind of geometry of a {@link SimpleFeatureType}.
@@ -1631,7 +1631,7 @@
 	 *            generiert automatische Attribut-Werte
 	 */
 	public static void registerAutoValueGenerator(AttributeDescriptor aType,
-			AutoValueGenerator generator) {
+			AutoValueGenerator<?> generator) {
 		autoAttrValueGenerators.put(aType, generator);
 	}
 
@@ -1656,7 +1656,7 @@
 	 * @return {@code null}, wenn fuer den {@link AttributeDescriptor} noch kein
 	 *         {@link AutoValueGenerator} registriert worden ist
 	 */
-	public static AutoValueGenerator getAutoValueGenerator(
+	public static AutoValueGenerator<?> getAutoValueGenerator(
 			AttributeDescriptor aType) {
 		return autoAttrValueGenerators.get(aType);
 	}

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java	2009-10-02 14:16:12 UTC (rev 425)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFS.java	2009-10-02 17:20:00 UTC (rev 426)
@@ -41,11 +41,13 @@
 
 import org.apache.log4j.Logger;
 import org.geotools.data.FeatureSource;
+import org.geotools.data.store.EmptyFeatureCollection;
 import org.geotools.feature.FeatureCollection;
 import org.geotools.styling.Style;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.filter.Filter;
 import org.opengis.referencing.crs.CoordinateReferenceSystem;
 
 import schmitzm.geotools.styling.StylingUtil;
@@ -81,6 +83,8 @@
 
 	private AttributeMetadataMap map;
 
+	private Filter filter = Filter.INCLUDE;
+
 	/**
 	 * This class enables a non Atlas context to use the Atlas LayerPanel
 	 * {@link JPanel} as a {@link MapContextManagerInterface}
@@ -92,7 +96,8 @@
 	 *            may be <code>null</code>. Otherwise the SLD {@link File} to
 	 *            import and associate with this {@link StyledFS}
 	 */
-	public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs, File sldFile) {
+	public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs,
+			File sldFile) {
 
 		this.fs = fs;
 		id = StyledFS.class.getSimpleName()
@@ -111,12 +116,19 @@
 			}
 		}
 		title = new Translation();
-		title.fromOneLine(sldFile.getName());
+		desc = new Translation();
 
-		desc = new Translation();
-		desc.fromOneLine(sldFile.getAbsolutePath());
+		if (sldFile != null) {
+			title.fromOneLine(sldFile.getName());
+			desc.fromOneLine(sldFile.getAbsolutePath());
+		}
+
 	}
 
+	public StyledFS(FeatureSource<SimpleFeatureType, SimpleFeature> fs) {
+		this(fs, null);
+	}
+
 	public void dispose() {
 	}
 
@@ -243,7 +255,7 @@
 
 	/**
 	 * @return The {@link File} where the SLD was loaded from or
-	 *         <code>null</code> if there didn't exist a {@link File}. 
+	 *         <code>null</code> if there didn't exist a {@link File}.
 	 * 
 	 * @author <a href="mailto:skpublic at wikisquare.de">Stefan Alfons
 	 *         Kr&uuml;ger</a>
@@ -280,8 +292,33 @@
 	 * @see {@link StyledFeaturesInterface}
 	 */
 	@Override
-	public FeatureSource getFeatureSource() {
+	public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() {
 		return getGeoObject();
 	}
 
+	@Override
+	public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
+		final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection();
+		if (filter == Filter.EXCLUDE)
+			return new EmptyFeatureCollection(fc.getSchema());
+		if (filter == Filter.INCLUDE)
+			return fc;
+		return fc.subCollection(filter);
+	}
+
+	@Override
+	public Filter getFilter() {
+		return filter;
+	}
+
+	@Override
+	public void setFilter(Filter filter) {
+		this.filter = filter;
+	}
+
+	@Override
+	public SimpleFeatureType getSchema() {
+		return getGeoObject().getSchema();
+	}
+
 }

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollection.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollection.java	2009-10-02 14:16:12 UTC (rev 425)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollection.java	2009-10-02 17:20:00 UTC (rev 426)
@@ -36,19 +36,22 @@
 
 import org.geotools.data.FeatureSource;
 import org.geotools.data.collection.CollectionDataStore;
+import org.geotools.data.store.EmptyFeatureCollection;
 import org.geotools.feature.FeatureCollection;
+import org.geotools.feature.collection.SubFeatureCollection;
 import org.geotools.styling.Style;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
 import org.opengis.feature.type.AttributeDescriptor;
+import org.opengis.filter.Filter;
 
 import schmitzm.geotools.feature.FeatureUtil;
 import skrueger.AttributeMetaData;
 import skrueger.i8n.Translation;
 
 /**
- * This class provides a simple implementation of {@link StyledLayerInterface} for
- * {@link FeatureCollection}. The uncache functionality is not supported,
+ * This class provides a simple implementation of {@link StyledLayerInterface}
+ * for {@link FeatureCollection}. The uncache functionality is not supported,
  * because this class bases on an existing {@link FeatureCollection} object in
  * memory.
  * 
@@ -56,9 +59,10 @@
  *         (University of Bonn/Germany)
  * @version 1.0
  */
-public class StyledFeatureCollection extends
-		AbstractStyledLayer<FeatureCollection<SimpleFeatureType, SimpleFeature> > implements
-		StyledFeatureCollectionInterface {
+public class StyledFeatureCollection
+		extends
+		AbstractStyledLayer<FeatureCollection<SimpleFeatureType, SimpleFeature>>
+		implements StyledFeatureCollectionInterface {
 
 	/** Holds the meta data for displaying a legend. */
 	protected AttributeMetadataMap attrMetaData = null;
@@ -69,6 +73,12 @@
 	private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = null;
 
 	/**
+	 * A Filter that will be applied internally applied to this
+	 * FeatureCollection
+	 **/
+	private Filter filter = Filter.INCLUDE;
+
+	/**
 	 * Creates a styled {@link FeatureCollection} with language-specific
 	 * informations.
 	 * 
@@ -91,12 +101,13 @@
 	 * @exception IllegalArgumentException
 	 *                if {@code null} is given as ID or geo object
 	 */
-	public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
+	public StyledFeatureCollection(
+			FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
 			Translation title, Translation desc, Translation keywords,
-			Style style, AttributeMetadataMap attrMetaData,
-			ImageIcon icon) {
+			Style style, AttributeMetadataMap attrMetaData, ImageIcon icon) {
 		super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()
-				.getCoordinateReferenceSystem(), id, title, desc, keywords, style, icon);
+				.getCoordinateReferenceSystem(), id, title, desc, keywords,
+				style, icon);
 		setAttributeMetaData(attrMetaData);
 	}
 
@@ -121,10 +132,10 @@
 	 * @exception IllegalArgumentException
 	 *                if {@code null} is given as ID or geo object
 	 */
-	public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
+	public StyledFeatureCollection(
+			FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
 			Translation title, Translation desc, Translation keywords,
-			StyledLayerStyle<AttributeMetadataMap> style,
-			ImageIcon icon) {
+			StyledLayerStyle<AttributeMetadataMap> style, ImageIcon icon) {
 		super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()
 				.getCoordinateReferenceSystem(), id, title, desc, keywords,
 				style != null ? style.getGeoObjectStyle() : null, icon);
@@ -148,7 +159,8 @@
 	 *                if {@code null} is given as ID or geo object
 	 * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
 	 */
-	public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
+	public StyledFeatureCollection(
+			FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
 			Translation title, Style style) {
 		this(fc, id, title, null, null, style, null, null);
 	}
@@ -176,7 +188,8 @@
 	 * @exception IllegalArgumentException
 	 *                if {@code null} is given as ID or geo object
 	 */
-	public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
+	public StyledFeatureCollection(
+			FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
 			String title, String desc, String keywords, Style style,
 			AttributeMetadataMap attrMetaData, ImageIcon icon) {
 		this(fc, id, (Translation) null, null, null, style, attrMetaData, icon);
@@ -206,10 +219,10 @@
 	 * @exception IllegalArgumentException
 	 *                if {@code null} is given as ID or geo object
 	 */
-	public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
+	public StyledFeatureCollection(
+			FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
 			String title, String desc, String keywords,
-			StyledLayerStyle<AttributeMetadataMap> style,
-			ImageIcon icon) {
+			StyledLayerStyle<AttributeMetadataMap> style, ImageIcon icon) {
 		this(fc, id, title, desc, keywords, style != null ? style
 				.getGeoObjectStyle() : null, style != null ? style
 				.getMetaData() : null, icon);
@@ -232,7 +245,8 @@
 	 *                if {@code null} is given as ID or geo object
 	 * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
 	 */
-	public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
+	public StyledFeatureCollection(
+			FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
 			String title, Style style) {
 		this(fc, id, title, null, null, style, null, null);
 	}
@@ -254,7 +268,8 @@
 	 *                if {@code null} is given as ID or geo object
 	 * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
 	 */
-	public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,
+	public StyledFeatureCollection(
+			FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
 			String title, StyledLayerStyle<AttributeMetadataMap> style) {
 		this(fc, id, title, null, null, style != null ? style
 				.getGeoObjectStyle() : null, style != null ? style
@@ -285,8 +300,7 @@
 	 * @param attrMetaData
 	 *            map of attribute meta data
 	 */
-	public void setAttributeMetaData(
-			AttributeMetadataMap attrMetaData) {
+	public void setAttributeMetaData(AttributeMetadataMap attrMetaData) {
 		this.attrMetaData = (attrMetaData != null) ? attrMetaData
 				: createDefaultAttributeMetaDataMap(geoObject);
 	}
@@ -299,7 +313,7 @@
 	 *            a {@link FeatureCollection}
 	 */
 	public static AttributeMetadataMap createDefaultAttributeMetaDataMap(
-			FeatureCollection<SimpleFeatureType,SimpleFeature> fc) {
+			FeatureCollection<SimpleFeatureType, SimpleFeature> fc) {
 		AttributeMetadataMap metaDataMap = new AttributeMetadataMap();
 		SimpleFeatureType ftype = fc.getSchema();
 		for (int i = 0; i < ftype.getAttributeCount(); i++) {
@@ -356,22 +370,45 @@
 	}
 
 	/**
-	 * Same as {@link #getGeoObject()} method, but complies to the {@link StyledFeaturesInterface} 
+	 * Same as {@link #getGeoObject()} method, but complies to the
+	 * {@link StyledFeaturesInterface}. The associated {@link Filter} is NOT
+	 * automatically applied.
+	 * 
 	 * @see {@link StyledFeaturesInterface}
+	 * @see #getFeatureCollectionFiltered()
 	 */
 	@Override
-	public FeatureCollection<SimpleFeatureType,SimpleFeature> getFeatureCollection() {
+	public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection() {
 		return getGeoObject();
 	}
 
 	/**
+	 * Same as {@link #getGeoObject()} method, but complies to the
+	 * {@link StyledFeaturesInterface}. The associated {@link Filter} is
+	 * automatically applied by creating a {@link SubFeatureCollection}.
+	 * 
+	 * @see {@link StyledFeaturesInterface}
+	 * @see #getFeatureCollectionFiltered()
+	 */
+	@Override
+	public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
+		final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection();
+		if (filter == Filter.EXCLUDE)
+			return new EmptyFeatureCollection(fc.getSchema());
+		if (filter == Filter.INCLUDE)
+			return fc;
+		return fc.subCollection(filter);
+	}
+
+	/**
 	 * Returns a virtual {@link FeatureSource} to access the
 	 * {@link FeatureCollection}. Once created, it will be reused until
 	 * {@link #uncache()} is called.<br/>
+	 * 
 	 * @see {@link StyledFeaturesInterface}
 	 */
 	@Override
-	public FeatureSource<SimpleFeatureType,SimpleFeature> getFeatureSource() {
+	public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() {
 		if (featureSource == null) {
 			CollectionDataStore store = new CollectionDataStore(getGeoObject());
 			try {
@@ -385,4 +422,20 @@
 		return featureSource;
 	}
 
+	@Override
+	public Filter getFilter() {
+		return filter;
+	}
+
+	@Override
+	public void setFilter(Filter filter) {
+		this.filter = filter;
+	}
+
+	@Override
+	public SimpleFeatureType getSchema() {
+		return getGeoObject().getSchema();
+	}
+
+
 }

Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeaturesInterface.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeaturesInterface.java	2009-10-02 14:16:12 UTC (rev 425)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeaturesInterface.java	2009-10-02 17:20:00 UTC (rev 426)
@@ -33,6 +33,7 @@
 import org.geotools.feature.FeatureCollection;
 import org.opengis.feature.simple.SimpleFeature;
 import org.opengis.feature.simple.SimpleFeatureType;
+import org.opengis.filter.Filter;
 
 /**
  * This Interface combines all styled layers that are running on
@@ -48,12 +49,51 @@
 	public abstract AttributeMetadataMap getAttributeMetaDataMap();
 
 	/**
-	 * @return The features of this layer as a {@link FeatureSource}.
+	 * @return The features of this layer as a {@link FeatureSource}. The filter
+	 *         is NOT automatically applied.
 	 */
 	public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource();
 
 	/**
-	 * @return The features of this layer as a {@link FeatureCollection}.
+	 * @return The features of this layer as a {@link FeatureCollection}. The
+	 *         filter is NOT automatically applied.
 	 */
 	public abstract FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection();
+
+	/**
+	 * @return The features of this layer as a {@link FeatureCollection}. The
+	 *         associated Filter is automatically applied.
+	 */
+	public abstract FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered();
+
+	/**
+	 * Stores Filter that is NOT automatically applied. <code>null</code> is not
+	 * allowed, use Filter.INCLUDE.
+	 */
+	public void setFilter(Filter filter);
+
+	/**
+	 * Returns the Filter a filter that is associated with this
+	 * {@link StyledFeaturesInterface} Never shall return <code>null</code>, but
+	 * rather Filter.INCLUDE.
+	 */
+	public Filter getFilter();
+
+	/**
+	 * Returns the underlying GeoTools Object. The filter is NOT applied.
+	 * 
+	 * @throws RuntimeException
+	 * 
+	 * @deprected Please use {@link #getFeatureSource()} or
+	 *            {@link #getFeatureCollection()} so you save a cast
+	 */
+	public T getGeoObject();
+
+	/**
+	 * @return As the fastest way to get the Schema is depending on the
+	 *         underlying geoObject (FeatureSource or FeatureCollection), this
+	 *         method shall be implemented in the classes.
+	 */
+	public abstract SimpleFeatureType getSchema();
+
 }



More information about the Schmitzm-commits mailing list