/[schmitzm]/trunk/src/skrueger/geotools/StyledFeatureCollection.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/StyledFeatureCollection.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/skrueger/geotools/StyledFeatureCollection.java revision 221 by alfonx, Tue Jul 14 14:40:52 2009 UTC branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollection.java revision 464 by alfonx, Tue Oct 13 13:22:31 2009 UTC
# Line 1  Line 1 
1  package skrueger.geotools;  /*******************************************************************************
2     * Copyright (c) 2009 Martin O. J. Schmitz.
3  import java.io.IOException;   *
4  import java.net.URL;   * This file is part of the SCHMITZM library - a collection of utility
5  import java.util.HashMap;   * classes based on Java 1.6, focusing (not only) on Java Swing
6  import java.util.Map;   * and the Geotools library.
7     *
8  import javax.swing.ImageIcon;   * The SCHMITZM project is hosted at:
9     * http://wald.intevation.org/projects/schmitzm/
10  import org.geotools.data.FeatureSource;   *
11  import org.geotools.data.collection.CollectionDataStore;   * This program is free software; you can redistribute it and/or
12  import org.geotools.feature.AttributeType;   * modify it under the terms of the GNU Lesser General Public License
13  import org.geotools.feature.FeatureCollection;   * as published by the Free Software Foundation; either version 3
14  import org.geotools.feature.FeatureType;   * of the License, or (at your option) any later version.
15  import org.geotools.styling.Style;   *
16     * This program is distributed in the hope that it will be useful,
17  import schmitzm.geotools.feature.FeatureUtil;   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  import skrueger.AttributeMetaData;   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  import skrueger.i8n.Translation;   * GNU General Public License for more details.
20     *
21  /**   * You should have received a copy of the GNU Lesser General Public License (license.txt)
22   * This class provides a simple implementation of {@link StyledMapInterface} for   * along with this program; if not, write to the Free Software
23   * {@link FeatureCollection}. The uncache functionality is not supported,   * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
24   * because this class bases on an existing {@link FeatureCollection} object in   * or try this link: http://www.gnu.org/licenses/lgpl.html
25   * memory.   *
26   *   * Contributors:
27   * @author <a href="mailto:[email protected]">Martin Schmitz</a>   *     Martin O. J. Schmitz - initial API and implementation
28   *         (University of Bonn/Germany)   *     Stefan A. Krüger - additional utility classes
29   * @version 1.0   ******************************************************************************/
30   */  package skrueger.geotools;
31  public class StyledFeatureCollection extends  
32                  AbstractStyledMap<FeatureCollection> implements  import java.io.IOException;
33                  StyledFeatureCollectionInterface {  import java.net.URL;
34    
35          /** Holds the meta data for displaying a legend. */  import javax.swing.ImageIcon;
36          protected Map<Integer, AttributeMetaData> attrMetaData = null;  
37    import org.geotools.data.FeatureSource;
38          /**  import org.geotools.data.collection.CollectionDataStore;
39           * We be filled with a "virtual" {@link FeatureSource} on demand.  import org.geotools.data.store.EmptyFeatureCollection;
40           */  import org.geotools.feature.FeatureCollection;
41          private FeatureSource featureSource = null;  import org.geotools.feature.collection.SubFeatureCollection;
42    import org.geotools.styling.Style;
43          /**  import org.opengis.feature.simple.SimpleFeature;
44           * Creates a styled {@link FeatureCollection} with language-specific  import org.opengis.feature.simple.SimpleFeatureType;
45           * informations.  import org.opengis.feature.type.AttributeDescriptor;
46           *  import org.opengis.filter.Filter;
47           * @param fc  
48           *            the {@link FeatureCollection}  import schmitzm.geotools.feature.FeatureUtil;
49           * @param id  import skrueger.AttributeMetadata;
50           *            a unique ID for the object  import skrueger.i8n.Translation;
51           * @param title  
52           *            a (language-specific) short description  /**
53           * @param desc   * This class provides a simple implementation of {@link StyledLayerInterface}
54           *            a (language-specific) long description   * for {@link FeatureCollection}. The uncache functionality is not supported,
55           * @param keywords   * because this class bases on an existing {@link FeatureCollection} object in
56           *            (language-specific) keywords for the geo objects   * memory.
57           * @param style   *
58           *            a display style (if {@code null}, a default style is created)   * @author <a href="mailto:[email protected]">Martin Schmitz</a>
59           * @param attrMetaData   *         (University of Bonn/Germany)
60           *            meta data for displaying a legend   * @version 1.0
61           * @param icon   */
62           *            an icon for the object (can be {@code null})  public class StyledFeatureCollection
63           * @exception IllegalArgumentException                  extends
64           *                if {@code null} is given as ID or geo object                  AbstractStyledLayer<FeatureCollection<SimpleFeatureType, SimpleFeature>>
65           */                  implements StyledFeatureCollectionInterface {
66          public StyledFeatureCollection(FeatureCollection fc, String id,  
67                          Translation title, Translation desc, Translation keywords,          /** Holds the meta data for displaying a legend. */
68                          Style style, Map<Integer, AttributeMetaData> attrMetaData,          protected AttributeMetadataMap attrMetaData = null;
69                          ImageIcon icon) {  
70                  super(fc, fc.getBounds(), fc.getSchema().getDefaultGeometry()          /**
71                                  .getCoordinateSystem(), id, title, desc, keywords, style, icon);           * We be filled with a "virtual" {@link FeatureSource} on demand.
72                  setAttributeMetaData(attrMetaData);           */
73          }          private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = null;
74    
75          /**          /**
76           * Creates a styled {@link FeatureCollection} with language-specific           * A Filter that will be applied internally applied to this
77           * informations.           * FeatureCollection
78           *           **/
79           * @param fc          private Filter filter = Filter.INCLUDE;
80           *            the {@link FeatureCollection}  
81           * @param id          /**
82           *            a unique ID for the object           * Creates a styled {@link FeatureCollection} with language-specific
83           * @param title           * informations.
84           *            a (language-specific) short description           *
85           * @param desc           * @param fc
86           *            a (language-specific) long description           *            the {@link FeatureCollection}
87           * @param keywords           * @param id
88           *            (language-specific) keywords for the geo objects           *            a unique ID for the object
89           * @param style           * @param title
90           *            a display style with attribute meta data information           *            a (language-specific) short description
91           * @param icon           * @param desc
92           *            an icon for the object (can be {@code null})           *            a (language-specific) long description
93           * @exception IllegalArgumentException           * @param keywords
94           *                if {@code null} is given as ID or geo object           *            (language-specific) keywords for the geo objects
95           */           * @param style
96          public StyledFeatureCollection(FeatureCollection fc, String id,           *            a display style (if {@code null}, a default style is created)
97                          Translation title, Translation desc, Translation keywords,           * @param attrMetaData
98                          StyledMapStyle<Map<Integer, AttributeMetaData>> style,           *            meta data for displaying a legend
99                          ImageIcon icon) {           * @param icon
100                  super(fc, fc.getBounds(), fc.getSchema().getDefaultGeometry()           *            an icon for the object (can be {@code null})
101                                  .getCoordinateSystem(), id, title, desc, keywords,           * @exception IllegalArgumentException
102                                  style != null ? style.getGeoObjectStyle() : null, icon);           *                if {@code null} is given as ID or geo object
103                  setAttributeMetaData(style != null ? style.getMetaData() : null);           */
104          }          public StyledFeatureCollection(
105                            FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
106          /**                          Translation title, Translation desc, Translation keywords,
107           * Creates a styled {@link FeatureCollection} with a language-specific                          Style style, AttributeMetadataMap attrMetaData, ImageIcon icon) {
108           * title, no long description, no keywords, default attribute meta data and                  super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()
109           * no icon.                                  .getCoordinateReferenceSystem(), id, title, desc, keywords,
110           *                                  style, icon);
111           * @param fc                  setAttributeMetaData(attrMetaData);
112           *            the {@link FeatureCollection}          }
113           * @param id  
114           *            a unique ID for the object          /**
115           * @param title           * Creates a styled {@link FeatureCollection} with language-specific
116           *            a short description           * informations.
117           * @param style           *
118           *            a display style (if {@code null}, a default style is created)           * @param fc
119           * @exception IllegalArgumentException           *            the {@link FeatureCollection}
120           *                if {@code null} is given as ID or geo object           * @param id
121           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)           *            a unique ID for the object
122           */           * @param title
123          public StyledFeatureCollection(FeatureCollection fc, String id,           *            a (language-specific) short description
124                          Translation title, Style style) {           * @param desc
125                  this(fc, id, title, null, null, style, null, null);           *            a (language-specific) long description
126          }           * @param keywords
127             *            (language-specific) keywords for the geo objects
128          /**           * @param style
129           * Creates a styled {@link FeatureCollection} with non-translated           *            a display style with attribute meta data information
130           * informations.           * @param icon
131           *           *            an icon for the object (can be {@code null})
132           * @param fc           * @exception IllegalArgumentException
133           *            the {@link FeatureCollection}           *                if {@code null} is given as ID or geo object
134           * @param id           */
135           *            a unique ID for the object          public StyledFeatureCollection(
136           * @param title                          FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
137           *            a short description                          Translation title, Translation desc, Translation keywords,
138           * @param desc                          StyledLayerStyle<AttributeMetadataMap> style, ImageIcon icon) {
139           *            a long description                  super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()
140           * @param keywords                                  .getCoordinateReferenceSystem(), id, title, desc, keywords,
141           *            keywords for the geo objects                                  style != null ? style.getGeoObjectStyle() : null, icon);
142           * @param style                  setAttributeMetaData(style != null ? style.getMetaData() : null);
143           *            a display style (if {@code null}, a default style is created)          }
144           * @param attrMetaData  
145           *            meta data for displaying a legend          /**
146           * @param icon           * Creates a styled {@link FeatureCollection} with a language-specific
147           *            an icon for the object (can be {@code null})           * title, no long description, no keywords, default attribute meta data and
148           * @exception IllegalArgumentException           * no icon.
149           *                if {@code null} is given as ID or geo object           *
150           */           * @param fc
151          public StyledFeatureCollection(FeatureCollection fc, String id,           *            the {@link FeatureCollection}
152                          String title, String desc, String keywords, Style style,           * @param id
153                          Map<Integer, AttributeMetaData> attrMetaData, ImageIcon icon) {           *            a unique ID for the object
154                  this(fc, id, (Translation) null, null, null, style, attrMetaData, icon);           * @param title
155                  setTitle(title);           *            a short description
156                  setDesc(desc);           * @param style
157                  setKeywords(keywords);           *            a display style (if {@code null}, a default style is created)
158          }           * @exception IllegalArgumentException
159             *                if {@code null} is given as ID or geo object
160          /**           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
161           * Creates a styled {@link FeatureCollection} with non-translated           */
162           * informations.          public StyledFeatureCollection(
163           *                          FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
164           * @param fc                          Translation title, Style style) {
165           *            the {@link FeatureCollection}                  this(fc, id, title, null, null, style, null, null);
166           * @param id          }
167           *            a unique ID for the object  
168           * @param title          /**
169           *            a short description           * Creates a styled {@link FeatureCollection} with non-translated
170           * @param desc           * informations.
171           *            a long description           *
172           * @param keywords           * @param fc
173           *            keywords for the geo objects           *            the {@link FeatureCollection}
174           * @param style           * @param id
175           *            a display style with attribute meta data information           *            a unique ID for the object
176           * @param icon           * @param title
177           *            an icon for the object (can be {@code null})           *            a short description
178           * @exception IllegalArgumentException           * @param desc
179           *                if {@code null} is given as ID or geo object           *            a long description
180           */           * @param keywords
181          public StyledFeatureCollection(FeatureCollection fc, String id,           *            keywords for the geo objects
182                          String title, String desc, String keywords,           * @param style
183                          StyledMapStyle<Map<Integer, AttributeMetaData>> style,           *            a display style (if {@code null}, a default style is created)
184                          ImageIcon icon) {           * @param attrMetaData
185                  this(fc, id, title, desc, keywords, style != null ? style           *            meta data for displaying a legend
186                                  .getGeoObjectStyle() : null, style != null ? style           * @param icon
187                                  .getMetaData() : null, icon);           *            an icon for the object (can be {@code null})
188          }           * @exception IllegalArgumentException
189             *                if {@code null} is given as ID or geo object
190          /**           */
191           * Creates a styled {@link FeatureCollection} with a non-translated title,          public StyledFeatureCollection(
192           * no long description, no keywords, default attribute meta data and no                          FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
193           * icon.                          String title, String desc, String keywords, Style style,
194           *                          AttributeMetadataMap attrMetaData, ImageIcon icon) {
195           * @param fc                  this(fc, id, (Translation) null, null, null, style, attrMetaData, icon);
196           *            the {@link FeatureCollection}                  setTitle(title);
197           * @param id                  setDesc(desc);
198           *            a unique ID for the object                  setKeywords(keywords);
199           * @param title          }
200           *            a short description  
201           * @param style          /**
202           *            a display style (if {@code null}, a default style is created)           * Creates a styled {@link FeatureCollection} with non-translated
203           * @exception IllegalArgumentException           * informations.
204           *                if {@code null} is given as ID or geo object           *
205           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)           * @param fc
206           */           *            the {@link FeatureCollection}
207          public StyledFeatureCollection(FeatureCollection fc, String id,           * @param id
208                          String title, Style style) {           *            a unique ID for the object
209                  this(fc, id, title, null, null, style, null, null);           * @param title
210          }           *            a short description
211             * @param desc
212          /**           *            a long description
213           * Creates a styled {@link FeatureCollection} with a non-translated title,           * @param keywords
214           * no long description, no keywords, default attribute meta data and no           *            keywords for the geo objects
215           * icon.           * @param style
216           *           *            a display style with attribute meta data information
217           * @param fc           * @param icon
218           *            the {@link FeatureCollection}           *            an icon for the object (can be {@code null})
219           * @param id           * @exception IllegalArgumentException
220           *            a unique ID for the object           *                if {@code null} is given as ID or geo object
221           * @param title           */
222           *            a short description          public StyledFeatureCollection(
223           * @param style                          FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
224           *            a display style (if {@code null}, a default style is created)                          String title, String desc, String keywords,
225           * @exception IllegalArgumentException                          StyledLayerStyle<AttributeMetadataMap> style, ImageIcon icon) {
226           *                if {@code null} is given as ID or geo object                  this(fc, id, title, desc, keywords, style != null ? style
227           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)                                  .getGeoObjectStyle() : null, style != null ? style
228           */                                  .getMetaData() : null, icon);
229          public StyledFeatureCollection(FeatureCollection fc, String id,          }
230                          String title, StyledMapStyle<Map<Integer, AttributeMetaData>> style) {  
231                  this(fc, id, title, null, null, style != null ? style          /**
232                                  .getGeoObjectStyle() : null, style != null ? style           * Creates a styled {@link FeatureCollection} with a non-translated title,
233                                  .getMetaData() : null, null);           * no long description, no keywords, default attribute meta data and no
234          }           * icon.
235             *
236          /**           * @param fc
237           * Creates a default style for the {@link FeatureCollection}.           *            the {@link FeatureCollection}
238           *           * @param id
239           * @see FeatureUtil#createDefaultStyle(FeatureCollection)           *            a unique ID for the object
240           */           * @param title
241          protected Style createDefaultStyle() {           *            a short description
242                  return FeatureUtil.createDefaultStyle(geoObject);           * @param style
243          }           *            a display style (if {@code null}, a default style is created)
244             * @exception IllegalArgumentException
245          /**           *                if {@code null} is given as ID or geo object
246           * Returns the meta data needed for displaying a legend.           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
247           */           */
248          public Map<Integer, AttributeMetaData> getAttributeMetaDataMap() {          public StyledFeatureCollection(
249                  return attrMetaData;                          FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
250          }                          String title, Style style) {
251                    this(fc, id, title, null, null, style, null, null);
252          /**          }
253           * Sets the meta data needed for displaying a legend. If {@code legendData}  
254           * is {@code null} an empty map is set, so          /**
255           * {@link #getAttributeMetaDataMap()} never returns {@code null}.           * Creates a styled {@link FeatureCollection} with a non-translated title,
256           *           * no long description, no keywords, default attribute meta data and no
257           * @param attrMetaData           * icon.
258           *            map of attribute meta data           *
259           */           * @param fc
260          public void setAttributeMetaData(           *            the {@link FeatureCollection}
261                          Map<Integer, AttributeMetaData> attrMetaData) {           * @param id
262                  this.attrMetaData = (attrMetaData != null) ? attrMetaData           *            a unique ID for the object
263                                  : createDefaultAttributeMetaDataMap(geoObject);           * @param title
264          }           *            a short description
265             * @param style
266          /**           *            a display style (if {@code null}, a default style is created)
267           * Creates non-translated default meta data for a {@link FeatureCollection}           * @exception IllegalArgumentException
268           * with all attributes visible and no unit set.           *                if {@code null} is given as ID or geo object
269           *           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
270           * @param fc           */
271           *            a {@link FeatureCollection}          public StyledFeatureCollection(
272           */                          FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
273          public static Map<Integer, AttributeMetaData> createDefaultAttributeMetaDataMap(                          String title, StyledLayerStyle<AttributeMetadataMap> style) {
274                          FeatureCollection fc) {                  this(fc, id, title, null, null, style != null ? style
275                  HashMap<Integer, AttributeMetaData> metaDataMap = new HashMap<Integer, AttributeMetaData>();                                  .getGeoObjectStyle() : null, style != null ? style
276                  FeatureType ftype = fc.getSchema();                                  .getMetaData() : null, null);
277                  for (int i = 0; i < ftype.getAttributeCount(); i++) {          }
278                          AttributeType aType = ftype.getAttributeType(i);  
279                          if (aType != ftype.getDefaultGeometry())          /**
280                                  metaDataMap.put(i, new AttributeMetaData(i, // Column no.           * Creates a default style for the {@link FeatureCollection}.
281                                                  true, // visible           *
282                                                  new Translation(aType.getName()), // Column name           * @see FeatureUtil#createDefaultStyle(FeatureCollection)
283                                                  new Translation(), // description           */
284                                                  "" // Unit          protected Style createDefaultStyle() {
285                                  ));                  return FeatureUtil.createDefaultStyle(geoObject);
286                  }          }
287                  return metaDataMap;  
288          }          /**
289             * Returns the meta data needed for displaying a legend.
290          /**           */
291           * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and          public AttributeMetadataMap getAttributeMetaDataMap() {
292           * {@link #attrMetaData} to {@code null}.                  return attrMetaData;
293           */          }
294          public void dispose() {  
295                  this.geoObject = null;          /**
296                  this.envelope = null;           * Sets the meta data needed for displaying a legend. If {@code legendData}
297                  this.crs = null;           * is {@code null} an empty map is set, so
298                  this.attrMetaData = null;           * {@link #getAttributeMetaDataMap()} never returns {@code null}.
299          }           *
300             * @param attrMetaData
301          /**           *            map of attribute meta data
302           * Tests whether the geo object is disposed.           */
303           */          public void setAttributeMetaData(AttributeMetadataMap attrMetaData) {
304          public boolean isDisposed() {                  this.attrMetaData = (attrMetaData != null) ? attrMetaData
305                  return geoObject == null;                                  : createDefaultAttributeMetaDataMap(geoObject);
306          }          }
307    
308          /**          /**
309           * Does nothing, because the {@link AbstractStyledMap} bases on existing           * Creates non-translated default meta data for a {@link FeatureCollection}
310           * objects (in memory) which can not be uncached and reloaded.           * with all attributes visible and no unit set.
311           */           *
312          public void uncache() {           * @param fc
313             *            a {@link FeatureCollection}
314                  /** It will be recreated on the next getFetureSource() **/           */
315                  featureSource = null;          public static AttributeMetadataMap createDefaultAttributeMetaDataMap(
316                            FeatureCollection<SimpleFeatureType, SimpleFeature> fc) {
317                  LOGGER                  AttributeMetadataMap metaDataMap = new AttributeMetadataMap();
318                                  .warn("Uncache onyl uncached any virtual FeatureSource. Object remains in memory.");                  SimpleFeatureType ftype = fc.getSchema();
319          }                  for (int i = 0; i < ftype.getAttributeCount(); i++) {
320                            AttributeDescriptor aDesc = ftype.getAttributeDescriptors().get(i);
321          /*                          if (aDesc != ftype.getGeometryDescriptor())
322           * (non-Javadoc)                                  metaDataMap.put(aDesc.getName(), new AttributeMetadata(aDesc.getName(),
323           *                                                  true, // visible
324           * @see skrueger.geotools.StyledMapInterface#getInfoURL()                                                  new Translation(aDesc.getLocalName()), // Column name
325           */                                                  new Translation(aDesc.getLocalName()), // description
326          public URL getInfoURL() {                                                  "" // Unit
327                  return null;                                  ));
328          }                  }
329                    return metaDataMap;
330          /**          }
331           * Same as {@link #getGeoObject()} method, but complies to the {@link StyledFeatureInterface}  
332           * @see {@link StyledFeatureInterface}          /**
333           */           * Simply sets the {@link #geoObject}, {@link #crs}, {@link #envelope} and
334          @Override           * {@link #attrMetaData} to {@code null}.
335          public FeatureCollection getFeatureCollection() {           */
336                  return getGeoObject();          public void dispose() {
337          }                  this.geoObject = null;
338                    this.envelope = null;
339          /**                  this.crs = null;
340           * Returns a virtual {@link FeatureSource} to access the                  this.attrMetaData = null;
341           * {@link FeatureCollection}. Once created, it will be reused until          }
342           * {@link #uncache()} is called.<br/>  
343           * @see {@link StyledFeatureInterface}          /**
344           */           * Tests whether the geo object is disposed.
345          @Override           */
346          public FeatureSource getFeatureSource() {          public boolean isDisposed() {
347                  if (featureSource == null) {                  return geoObject == null;
348                          CollectionDataStore store = new CollectionDataStore(getGeoObject());          }
349                          try {  
350                                  featureSource = store.getFeatureSource(store.getTypeNames()[0]);          /**
351                          } catch (IOException e) {           * Does nothing, because the {@link AbstractStyledLayer} bases on existing
352                                  throw new RuntimeException(           * objects (in memory) which can not be uncached and reloaded.
353                                                  "Could not create a FeatureSource from the CollectionDataStore:",           */
354                                                  e);          public void uncache() {
355                          }  
356                  }                  /** It will be recreated on the next getFetureSource() **/
357                  return featureSource;                  featureSource = null;
358          }  
359                    LOGGER
360  }                                  .warn("Uncache onyl uncached any virtual FeatureSource. Object remains in memory.");
361            }
362    
363            /*
364             * (non-Javadoc)
365             *
366             * @see skrueger.geotools.StyledLayerInterface#getInfoURL()
367             */
368            public URL getInfoURL() {
369                    return null;
370            }
371    
372            /**
373             * Same as {@link #getGeoObject()} method, but complies to the
374             * {@link StyledFeaturesInterface}. The associated {@link Filter} is NOT
375             * automatically applied.
376             *
377             * @see {@link StyledFeaturesInterface}
378             * @see #getFeatureCollectionFiltered()
379             */
380            @Override
381            public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection() {
382                    return getGeoObject();
383            }
384    
385            /**
386             * Same as {@link #getGeoObject()} method, but complies to the
387             * {@link StyledFeaturesInterface}. The associated {@link Filter} is
388             * automatically applied by creating a {@link SubFeatureCollection}.
389             *
390             * @see {@link StyledFeaturesInterface}
391             * @see #getFeatureCollectionFiltered()
392             */
393            @Override
394            public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
395                    final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection();
396                    if (filter == Filter.EXCLUDE)
397                            return new EmptyFeatureCollection(fc.getSchema());
398                    if (filter == Filter.INCLUDE)
399                            return fc;
400                    return fc.subCollection(filter);
401            }
402    
403            /**
404             * Returns a virtual {@link FeatureSource} to access the
405             * {@link FeatureCollection}. Once created, it will be reused until
406             * {@link #uncache()} is called.<br/>
407             *
408             * @see {@link StyledFeaturesInterface}
409             */
410            @Override
411            public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() {
412                    if (featureSource == null) {
413                            CollectionDataStore store = new CollectionDataStore(getGeoObject());
414                            try {
415                                    featureSource = store.getFeatureSource(store.getTypeNames()[0]);
416                            } catch (IOException e) {
417                                    throw new RuntimeException(
418                                                    "Could not create a FeatureSource from the CollectionDataStore:",
419                                                    e);
420                            }
421                    }
422                    return featureSource;
423            }
424    
425            @Override
426            public Filter getFilter() {
427                    return filter;
428            }
429    
430            @Override
431            public void setFilter(Filter filter) {
432                    this.filter = filter;
433            }
434    
435            @Override
436            public SimpleFeatureType getSchema() {
437                    return getGeoObject().getSchema();
438            }
439    
440    
441    }

Legend:
Removed from v.221  
changed lines
  Added in v.464

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26