/[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

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

Legend:
Removed from v.224  
changed lines
  Added in v.862

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26