/[schmitzm]/branches/1.0-gt2-2.6/src/skrueger/geotools/labelsearch/LabelSearch.java
ViewVC logotype

Diff of /branches/1.0-gt2-2.6/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 417 by alfonx, Fri Sep 25 16:34:10 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 113  public class LabelSearch { Line 118  public class LabelSearch {
118                                  if (!ml.isVisible())                                  if (!ml.isVisible())
119                                          continue;                                          continue;
120    
121                                  final List<TextSymbolizer> allTS = StylingUtil.getTextSymbolizers(ml                                  final List<TextSymbolizer> allTS = StylingUtil.getVisibleTextSymbolizers(ml
122                                                  .getStyle());                                                  .getStyle());
123                                  if (allTS.size() == 0) {                                  if (allTS.size() == 0) {
124                                          // A layer without any TextSymbolizer doesn't have to be                                          // A layer without any TextSymbolizer doesn't have to be
125                                          // searched any more.                                          // searched any more.
126                                          continue;                                          continue;
127                                  }                                  }
128                                    
129                                  final String typeName = ml.getFeatureSource().getSchema()                                  final FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = (FeatureSource<SimpleFeatureType, SimpleFeature>) ml.getFeatureSource();
130                                                  .getTypeName();                                  
131                                    final String typeName = featureSource.getSchema()
132                                                    .getName().getLocalPart();
133    
134                                  // Expression labelExp = ts.getLabel();                                  // Expression labelExp = ts.getLabel();
135                                  // ff.like(labelExp, "*"+searchMe+"*");                                  // ff.like(labelExp, "*"+searchMe+"*");
# Line 131  public class LabelSearch { Line 138  public class LabelSearch {
138                                  // new DefaultQuery(typeName, ff.like(labelExp,                                  // new DefaultQuery(typeName, ff.like(labelExp,
139                                  // "*"+searchMe+"*"), properties));                                  // "*"+searchMe+"*"), properties));
140    
141                                  final FeatureCollection features = ml.getFeatureSource().getFeatures(                                  final FeatureCollection<SimpleFeatureType, SimpleFeature> features = featureSource.getFeatures(
142                                                  new DefaultQuery(typeName, Filter.INCLUDE));                                                  new DefaultQuery(typeName, Filter.INCLUDE));
143    
144                                  // new MemoryDataStore().getFeatureSource(typeName)                                  // new MemoryDataStore().getFeatureSource(typeName)
# Line 150  public class LabelSearch { Line 157  public class LabelSearch {
157                                          if (ts == null)                                          if (ts == null)
158                                                  continue;                                                  continue;
159    
160                                          final AttributeType labelAttribute = getLabelAttribute(ts, ml                                          // TODO Evaluate the Rule that belongs to the TextSymbolizer against the feature...
161                                                          .getFeatureSource().getSchema());                                          final AttributeDescriptor labelAttribute = getLabelAttribute(ts, featureSource.getSchema());
162    
163                                          if (labelAttribute == null) {                                          if (labelAttribute == null) {
164                                                  continue;                                                  continue;

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26