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

branches/1.0-gt2-2.6/src/skrueger/geotools/StyledFeatureCollection.java revision 331 by mojays, Wed Aug 26 16:22:38 2009 UTC trunk/src/skrueger/geotools/StyledFeatureCollection.java revision 1203 by alfonx, Tue Nov 2 22:53:55 2010 UTC
# Line 25  Line 25 
25   *   *
26   * Contributors:   * Contributors:
27   *     Martin O. J. Schmitz - initial API and implementation   *     Martin O. J. Schmitz - initial API and implementation
28   *     Stefan A. Krüger - additional utility classes   *     Stefan A. Tzeggai - additional utility classes
29   ******************************************************************************/   ******************************************************************************/
30  package skrueger.geotools;  package skrueger.geotools;
31    
32  import java.io.IOException;  import java.io.IOException;
33  import java.net.URL;  import java.net.URL;
 import java.util.HashMap;  
 import java.util.Map;  
34    
35  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
36    
37  import org.geotools.data.FeatureSource;  import org.geotools.data.FeatureSource;
38  import org.geotools.data.collection.CollectionDataStore;  import org.geotools.data.collection.CollectionDataStore;
39    import org.geotools.data.store.EmptyFeatureCollection;
40  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
41    import org.geotools.feature.NameImpl;
42    import org.geotools.feature.collection.SubFeatureCollection;
43    import org.geotools.geometry.jts.ReferencedEnvelope;
44  import org.geotools.styling.Style;  import org.geotools.styling.Style;
45  import org.opengis.feature.simple.SimpleFeature;  import org.opengis.feature.simple.SimpleFeature;
46  import org.opengis.feature.simple.SimpleFeatureType;  import org.opengis.feature.simple.SimpleFeatureType;
47  import org.opengis.feature.type.AttributeDescriptor;  import org.opengis.feature.type.AttributeDescriptor;
48    import org.opengis.filter.Filter;
49    
50  import schmitzm.geotools.feature.FeatureUtil;  import schmitzm.geotools.feature.FeatureUtil;
51  import skrueger.AttributeMetaData;  import skrueger.AttributeMetadataImpl;
52  import skrueger.i8n.Translation;  import skrueger.i8n.Translation;
53    
54  /**  /**
55   * This class provides a simple implementation of {@link StyledLayerInterface} for   * This class provides a simple implementation of {@link StyledLayerInterface}
56   * {@link FeatureCollection}. The uncache functionality is not supported,   * for {@link FeatureCollection}. The uncache functionality is not supported,
57   * because this class bases on an existing {@link FeatureCollection} object in   * because this class bases on an existing {@link FeatureCollection} object in
58   * memory.   * memory.
59   *   *
# Line 58  import skrueger.i8n.Translation; Line 61  import skrueger.i8n.Translation;
61   *         (University of Bonn/Germany)   *         (University of Bonn/Germany)
62   * @version 1.0   * @version 1.0
63   */   */
64  public class StyledFeatureCollection extends  public class StyledFeatureCollection
65                  AbstractStyledLayer<FeatureCollection<SimpleFeatureType, SimpleFeature> > implements                  extends
66                  StyledFeatureCollectionInterface {                  AbstractStyledLayer<FeatureCollection<SimpleFeatureType, SimpleFeature>>
67                    implements StyledFeatureCollectionInterface {
68    
69          /** Holds the meta data for displaying a legend. */          /** Holds the meta data for displaying a legend. */
70          protected Map<Integer, AttributeMetaData> attrMetaData = null;          protected AttributeMetadataMap<AttributeMetadataImpl> attrMetaData = null;
71    
72          /**          /**
73           * We be filled with a "virtual" {@link FeatureSource} on demand.           * We be filled with a "virtual" {@link FeatureSource} on demand.
# Line 71  public class StyledFeatureCollection ext Line 75  public class StyledFeatureCollection ext
75          private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = null;          private FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = null;
76    
77          /**          /**
78             * A Filter that will be applied internally applied to this
79             * FeatureCollection
80             **/
81            private Filter filter = Filter.INCLUDE;
82    
83            /**
84           * Creates a styled {@link FeatureCollection} with language-specific           * Creates a styled {@link FeatureCollection} with language-specific
85           * informations.           * informations.
86           *           *
# Line 93  public class StyledFeatureCollection ext Line 103  public class StyledFeatureCollection ext
103           * @exception IllegalArgumentException           * @exception IllegalArgumentException
104           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
105           */           */
106          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,          public StyledFeatureCollection(
107                            FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
108                          Translation title, Translation desc, Translation keywords,                          Translation title, Translation desc, Translation keywords,
109                          Style style, Map<Integer, AttributeMetaData> attrMetaData,                          Style style, AttributeMetadataMap attrMetaData, ImageIcon icon) {
                         ImageIcon icon) {  
110                  super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()                  super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()
111                                  .getCoordinateReferenceSystem(), id, title, desc, keywords, style, icon);                                  .getCoordinateReferenceSystem(), id, title, desc, keywords,
112                                    style, icon);
113                  setAttributeMetaData(attrMetaData);                  setAttributeMetaData(attrMetaData);
114          }          }
115    
# Line 123  public class StyledFeatureCollection ext Line 134  public class StyledFeatureCollection ext
134           * @exception IllegalArgumentException           * @exception IllegalArgumentException
135           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
136           */           */
137          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,          public StyledFeatureCollection(
138                            FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
139                          Translation title, Translation desc, Translation keywords,                          Translation title, Translation desc, Translation keywords,
140                          StyledLayerStyle<Map<Integer, AttributeMetaData>> style,                          StyledLayerStyle<AttributeMetadataMap> style, ImageIcon icon) {
                         ImageIcon icon) {  
141                  super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()                  super(fc, fc.getBounds(), fc.getSchema().getGeometryDescriptor()
142                                  .getCoordinateReferenceSystem(), id, title, desc, keywords,                                  .getCoordinateReferenceSystem(), id, title, desc, keywords,
143                                  style != null ? style.getGeoObjectStyle() : null, icon);                                  style != null ? style.getGeoObjectStyle() : null, icon);
# Line 150  public class StyledFeatureCollection ext Line 161  public class StyledFeatureCollection ext
161           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
162           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
163           */           */
164          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,          public StyledFeatureCollection(
165                            FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
166                          Translation title, Style style) {                          Translation title, Style style) {
167                  this(fc, id, title, null, null, style, null, null);                  this(fc, id, title, null, null, style, null, null);
168          }          }
# Line 178  public class StyledFeatureCollection ext Line 190  public class StyledFeatureCollection ext
190           * @exception IllegalArgumentException           * @exception IllegalArgumentException
191           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
192           */           */
193          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,          public StyledFeatureCollection(
194                            FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
195                          String title, String desc, String keywords, Style style,                          String title, String desc, String keywords, Style style,
196                          Map<Integer, AttributeMetaData> attrMetaData, ImageIcon icon) {                          AttributeMetadataMap attrMetaData, ImageIcon icon) {
197                  this(fc, id, (Translation) null, null, null, style, attrMetaData, icon);                  this(fc, id, (Translation) null, null, null, style, attrMetaData, icon);
198                  setTitle(title);                  setTitle(title);
199                  setDesc(desc);                  setDesc(desc);
# Line 208  public class StyledFeatureCollection ext Line 221  public class StyledFeatureCollection ext
221           * @exception IllegalArgumentException           * @exception IllegalArgumentException
222           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
223           */           */
224          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,          public StyledFeatureCollection(
225                            FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
226                          String title, String desc, String keywords,                          String title, String desc, String keywords,
227                          StyledLayerStyle<Map<Integer, AttributeMetaData>> style,                          StyledLayerStyle<AttributeMetadataMap> style, ImageIcon icon) {
                         ImageIcon icon) {  
228                  this(fc, id, title, desc, keywords, style != null ? style                  this(fc, id, title, desc, keywords, style != null ? style
229                                  .getGeoObjectStyle() : null, style != null ? style                                  .getGeoObjectStyle() : null, style != null ? style
230                                  .getMetaData() : null, icon);                                  .getMetaData() : null, icon);
# Line 234  public class StyledFeatureCollection ext Line 247  public class StyledFeatureCollection ext
247           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
248           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
249           */           */
250          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,          public StyledFeatureCollection(
251                            FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
252                          String title, Style style) {                          String title, Style style) {
253                  this(fc, id, title, null, null, style, null, null);                  this(fc, id, title, null, null, style, null, null);
254          }          }
# Line 256  public class StyledFeatureCollection ext Line 270  public class StyledFeatureCollection ext
270           *                if {@code null} is given as ID or geo object           *                if {@code null} is given as ID or geo object
271           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)           * @see #createDefaultAttributeMetaDataMap(FeatureCollection)
272           */           */
273          public StyledFeatureCollection(FeatureCollection<SimpleFeatureType,SimpleFeature> fc, String id,          public StyledFeatureCollection(
274                          String title, StyledLayerStyle<Map<Integer, AttributeMetaData>> style) {                          FeatureCollection<SimpleFeatureType, SimpleFeature> fc, String id,
275                            String title, StyledLayerStyle<AttributeMetadataMap> style) {
276                  this(fc, id, title, null, null, style != null ? style                  this(fc, id, title, null, null, style != null ? style
277                                  .getGeoObjectStyle() : null, style != null ? style                                  .getGeoObjectStyle() : null, style != null ? style
278                                  .getMetaData() : null, null);                                  .getMetaData() : null, null);
# Line 275  public class StyledFeatureCollection ext Line 290  public class StyledFeatureCollection ext
290          /**          /**
291           * Returns the meta data needed for displaying a legend.           * Returns the meta data needed for displaying a legend.
292           */           */
293          public Map<Integer, AttributeMetaData> getAttributeMetaDataMap() {          public AttributeMetadataMap getAttributeMetaDataMap() {
294                  return attrMetaData;                  return attrMetaData;
295          }          }
296    
# Line 287  public class StyledFeatureCollection ext Line 302  public class StyledFeatureCollection ext
302           * @param attrMetaData           * @param attrMetaData
303           *            map of attribute meta data           *            map of attribute meta data
304           */           */
305          public void setAttributeMetaData(          public void setAttributeMetaData(AttributeMetadataMap attrMetaData) {
                         Map<Integer, AttributeMetaData> attrMetaData) {  
306                  this.attrMetaData = (attrMetaData != null) ? attrMetaData                  this.attrMetaData = (attrMetaData != null) ? attrMetaData
307                                  : createDefaultAttributeMetaDataMap(geoObject);                                  : createDefaultAttributeMetaDataMap(geoObject);
308          }          }
# Line 300  public class StyledFeatureCollection ext Line 314  public class StyledFeatureCollection ext
314           * @param fc           * @param fc
315           *            a {@link FeatureCollection}           *            a {@link FeatureCollection}
316           */           */
317          public static Map<Integer, AttributeMetaData> createDefaultAttributeMetaDataMap(          public static AttributeMetadataMap createDefaultAttributeMetaDataMap(
318                          FeatureCollection<SimpleFeatureType,SimpleFeature> fc) {                          FeatureCollection<SimpleFeatureType, SimpleFeature> fc) {
319                  HashMap<Integer, AttributeMetaData> metaDataMap = new HashMap<Integer, AttributeMetaData>();                  AttributeMetadataMap metaDataMap = new AttributeMetadataImplMap();
320                  SimpleFeatureType ftype = fc.getSchema();                  SimpleFeatureType ftype = fc.getSchema();
321                  for (int i = 0; i < ftype.getAttributeCount(); i++) {                  for (int i = 0; i < ftype.getAttributeCount(); i++) {
322                          AttributeDescriptor aType = ftype.getAttributeDescriptors().get(i);                          AttributeDescriptor aDesc = ftype.getAttributeDescriptors().get(i);
323                          if (aType != ftype.getGeometryDescriptor())                          if ( !FeatureUtil.isGeometryAttribute(aDesc) )
324                                  metaDataMap.put(i, new AttributeMetaData(i, // Column no.                                  metaDataMap.put(aDesc.getName(), new AttributeMetadataImpl( new NameImpl( aDesc.getName().getNamespaceURI(), aDesc.getName().getLocalPart()),
325                                                  true, // visible                                                  true, // visible
326                                                  new Translation(aType.getLocalName()), // Column name                                                  new Translation(aDesc.getLocalName()), // Column name
327                                                  new Translation(), // description                                                  new Translation(aDesc.getLocalName()), // description
328                                                  "" // Unit                                                  "" // Unit
329                                  ));                                  ));
330                  }                  }
# Line 358  public class StyledFeatureCollection ext Line 372  public class StyledFeatureCollection ext
372          }          }
373    
374          /**          /**
375           * Same as {@link #getGeoObject()} method, but complies to the {@link StyledFeaturesInterface}           * Same as {@link #getGeoObject()} method, but complies to the
376             * {@link StyledFeaturesInterface}. The associated {@link Filter} is NOT
377             * automatically applied.
378             *
379           * @see {@link StyledFeaturesInterface}           * @see {@link StyledFeaturesInterface}
380             * @see #getFeatureCollectionFiltered()
381           */           */
382          @Override          @Override
383          public FeatureCollection<SimpleFeatureType,SimpleFeature> getFeatureCollection() {          public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollection() {
384                  return getGeoObject();                  return getGeoObject();
385          }          }
386    
387          /**          /**
388             * Same as {@link #getGeoObject()} method, but complies to the
389             * {@link StyledFeaturesInterface}. The associated {@link Filter} is
390             * automatically applied by creating a {@link SubFeatureCollection}.
391             *
392             * @see {@link StyledFeaturesInterface}
393             * @see #getFeatureCollectionFiltered()
394             */
395            @Override
396            public FeatureCollection<SimpleFeatureType, SimpleFeature> getFeatureCollectionFiltered() {
397                    final FeatureCollection<SimpleFeatureType, SimpleFeature> fc = getFeatureCollection();
398                    if (filter == Filter.EXCLUDE)
399                            return new EmptyFeatureCollection(fc.getSchema());
400                    if (filter == Filter.INCLUDE)
401                            return fc;
402                    return fc.subCollection(filter);
403            }
404    
405            /**
406           * Returns a virtual {@link FeatureSource} to access the           * Returns a virtual {@link FeatureSource} to access the
407           * {@link FeatureCollection}. Once created, it will be reused until           * {@link FeatureCollection}. Once created, it will be reused until
408           * {@link #uncache()} is called.<br/>           * {@link #uncache()} is called.<br/>
409             *
410           * @see {@link StyledFeaturesInterface}           * @see {@link StyledFeaturesInterface}
411           */           */
412          @Override          @Override
413          public FeatureSource<SimpleFeatureType,SimpleFeature> getFeatureSource() {          public FeatureSource<SimpleFeatureType, SimpleFeature> getFeatureSource() {
414                  if (featureSource == null) {                  if (featureSource == null) {
415                          CollectionDataStore store = new CollectionDataStore(getGeoObject());                          CollectionDataStore store = new CollectionDataStore(getGeoObject());
416                          try {                          try {
# Line 387  public class StyledFeatureCollection ext Line 424  public class StyledFeatureCollection ext
424                  return featureSource;                  return featureSource;
425          }          }
426    
427            @Override
428            public Filter getFilter() {
429                    return filter;
430            }
431    
432            @Override
433            public void setFilter(Filter filter) {
434                    this.filter = filter;
435            }
436    
437            @Override
438            public SimpleFeatureType getSchema() {
439                    return getGeoObject().getSchema();
440            }
441    
442    
443            @Override
444            public ReferencedEnvelope getReferencedEnvelope() {
445                    return new ReferencedEnvelope(getEnvelope(), getCrs());
446            }
447    
448  }  }

Legend:
Removed from v.331  
changed lines
  Added in v.1203

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26