/[schmitzm]/branches/2.1/src/skrueger/geotools/labelsearch/LabelSearch.java
ViewVC logotype

Diff of /branches/2.1/src/skrueger/geotools/labelsearch/LabelSearch.java

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

trunk/src/skrueger/geotools/labelsearch/LabelSearch.java revision 244 by alfonx, Wed Jul 29 09:33:33 2009 UTC branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/LabelSearch.java revision 341 by alfonx, Mon Aug 31 10:16:40 2009 UTC
# Line 2  Line 2 
2   * Copyright (c) 2009 Martin O. J. Schmitz.   * Copyright (c) 2009 Martin O. J. Schmitz.
3   *   *
4   * This file is part of the SCHMITZM library - a collection of utility   * This file is part of the SCHMITZM library - a collection of utility
5   * classes based on Java 1.6, focussing (not only) on Java Swing   * classes based on Java 1.6, focusing (not only) on Java Swing
6   * and the Geotools library.   * and the Geotools library.
7   *   *
8   * The SCHMITZM project is hosted at:   * The SCHMITZM project is hosted at:
# Line 38  import java.util.Locale; Line 38  import java.util.Locale;
38    
39  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
40  import org.geotools.data.DefaultQuery;  import org.geotools.data.DefaultQuery;
41  import org.geotools.feature.AttributeType;  import org.geotools.data.FeatureSource;
 import org.geotools.feature.Feature;  
42  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
 import org.geotools.feature.FeatureType;  
43  import org.geotools.map.MapLayer;  import org.geotools.map.MapLayer;
44  import org.geotools.styling.Style;  import org.geotools.styling.Style;
45  import org.geotools.styling.TextSymbolizer;  import org.geotools.styling.TextSymbolizer;
46    import org.opengis.feature.simple.SimpleFeature;
47    import org.opengis.feature.simple.SimpleFeatureType;
48    import org.opengis.feature.type.AttributeDescriptor;
49  import org.opengis.filter.Filter;  import org.opengis.filter.Filter;
50  import org.opengis.filter.expression.Expression;  import org.opengis.filter.expression.Expression;
51  import org.opengis.filter.expression.PropertyName;  import org.opengis.filter.expression.PropertyName;
# Line 81  public class LabelSearch { Line 82  public class LabelSearch {
82                  this.mapPane = mapPane;                  this.mapPane = mapPane;
83          }          }
84    
85          private AttributeType getLabelAttribute(final TextSymbolizer ts,          /**
86                          final FeatureType schema) {           * The Attribute that provides the labels for this text symbolizer.
87             */
88            private AttributeDescriptor getLabelAttribute(final TextSymbolizer ts,
89                            final SimpleFeatureType schema) {
90                  if (ts == null) {                  if (ts == null) {
91                          // This layer has no labels                          // This layer has no labels
92                          return null;                          return null;
93                  }                  }
94                    
95                  final Expression labelExp = ts.getLabel();                  final Expression labelExp = ts.getLabel();
96                  if (labelExp instanceof PropertyName) {                  if (labelExp instanceof PropertyName) {
97                          final PropertyName pn = (PropertyName) labelExp;                          final PropertyName pn = (PropertyName) labelExp;
98                          final String propertyName = pn.getPropertyName();                          final String propertyName = pn.getPropertyName();
99                          return schema.getAttributeType(propertyName);                          return schema.getDescriptor(propertyName);
100                  } else {                  } else {
101                          // When does this happen                          // When does this happen
102                            throw new RuntimeException("labelExp "+labelExp+" IS NOT instanceof PropertyName!");
103                  }                  }
104    
                 return null;  
105          }          }
106    
107          public List<SearchResult> search(final String string) {          public List<SearchResult> search(final String string) {
# Line 121  public class LabelSearch { Line 126  public class LabelSearch {
126                                          continue;                                          continue;
127                                  }                                  }
128    
129                                  final String typeName = ml.getFeatureSource().getSchema()                                  // 26 CAST!
130                                                  .getTypeName();                                  final FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = (FeatureSource<SimpleFeatureType, SimpleFeature>) ml.getFeatureSource();
131                                    
132                                    final String typeName = featureSource.getSchema()
133                                                    .getName().getLocalPart();
134    
135                                  // Expression labelExp = ts.getLabel();                                  // Expression labelExp = ts.getLabel();
136                                  // ff.like(labelExp, "*"+searchMe+"*");                                  // ff.like(labelExp, "*"+searchMe+"*");
# Line 131  public class LabelSearch { Line 139  public class LabelSearch {
139                                  // new DefaultQuery(typeName, ff.like(labelExp,                                  // new DefaultQuery(typeName, ff.like(labelExp,
140                                  // "*"+searchMe+"*"), properties));                                  // "*"+searchMe+"*"), properties));
141    
142                                  final FeatureCollection features = ml.getFeatureSource().getFeatures(                                  final FeatureCollection<SimpleFeatureType, SimpleFeature> features = featureSource.getFeatures(
143                                                  new DefaultQuery(typeName, Filter.INCLUDE));                                                  new DefaultQuery(typeName, Filter.INCLUDE));
144    
145                                  // new MemoryDataStore().getFeatureSource(typeName)                                  // new MemoryDataStore().getFeatureSource(typeName)
# Line 141  public class LabelSearch { Line 149  public class LabelSearch {
149                                   * support case insensitivity and i don't find a lower or UPPER                                   * support case insensitivity and i don't find a lower or UPPER
150                                   * function.                                   * function.
151                                   */                                   */
152                                  final Iterator<Feature> fi = features.iterator();                                  final Iterator<SimpleFeature> fi = features.iterator();
153                                  while (fi.hasNext()) {                                  while (fi.hasNext()) {
154                                          final Feature f = fi.next();                                          final SimpleFeature f = fi.next();
155    
156                                          final TextSymbolizer ts = StylingUtil.getTextSymbolizer(ml                                          final TextSymbolizer ts = StylingUtil.getTextSymbolizer(ml
157                                                          .getStyle(), f);                                                          .getStyle(), f);
158                                          if (ts == null)                                          if (ts == null)
159                                                  continue;                                                  continue;
160    
161                                          final AttributeType labelAttribute = getLabelAttribute(ts, ml                                          final AttributeDescriptor labelAttribute = getLabelAttribute(ts, featureSource.getSchema());
                                                         .getFeatureSource().getSchema());  
162    
163                                          if (labelAttribute == null) {                                          if (labelAttribute == null) {
164                                                  continue;                                                  continue;
# Line 204  public class LabelSearch { Line 211  public class LabelSearch {
211                  return hits;                  return hits;
212          }          }
213    
214          protected SearchResult createSearchResult(final Feature f, final String title,          protected SearchResult createSearchResult(final SimpleFeature f, final String title,
215                          final String inTitle, MapLayer ml) {                          final String inTitle, MapLayer ml) {
216                  return new SearchResultFeature(f, title, inTitle, mapPane, ml);                  return new SearchResultFeature(f, title, inTitle, mapPane, ml);
217          }          }

Legend:
Removed from v.244  
changed lines
  Added in v.341

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26