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

revision 322 by alfonx, Wed Aug 26 14:12:17 2009 UTC revision 341 by alfonx, Mon Aug 31 10:16:40 2009 UTC
# 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;
42  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
 import org.opengis.feature.simple.SimpleFeature;  
 import org.opengis.feature.simple.SimpleFeatureType;  
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             * The Attribute that provides the labels for this text symbolizer.
87             */
88            private AttributeDescriptor getLabelAttribute(final TextSymbolizer ts,
89                          final SimpleFeatureType schema) {                          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 150  public class LabelSearch { Line 158  public class LabelSearch {
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;

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26