/[schmitzm]/trunk/src/skrueger/geotools/StyledLayerUtil.java
ViewVC logotype

Diff of /trunk/src/skrueger/geotools/StyledLayerUtil.java

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

revision 1225 by alfonx, Wed Nov 3 17:05:42 2010 UTC revision 1270 by alfonx, Sun Nov 14 00:25:52 2010 UTC
# Line 45  import java.io.FileWriter; Line 45  import java.io.FileWriter;
45  import java.net.URL;  import java.net.URL;
46  import java.text.DecimalFormat;  import java.text.DecimalFormat;
47  import java.util.ArrayList;  import java.util.ArrayList;
48    import java.util.Collections;
49  import java.util.List;  import java.util.List;
50  import java.util.Map;  import java.util.Map;
51  import java.util.Set;  import java.util.Set;
# Line 84  import org.opengis.feature.simple.Simple Line 85  import org.opengis.feature.simple.Simple
85  import org.opengis.feature.type.AttributeDescriptor;  import org.opengis.feature.type.AttributeDescriptor;
86  import org.opengis.feature.type.GeometryDescriptor;  import org.opengis.feature.type.GeometryDescriptor;
87  import org.opengis.feature.type.Name;  import org.opengis.feature.type.Name;
88    import org.opengis.filter.FilterFactory2;
89  import org.opengis.parameter.GeneralParameterValue;  import org.opengis.parameter.GeneralParameterValue;
90    
91    import schmitzm.geotools.FilterUtil;
92  import schmitzm.geotools.JTSUtil;  import schmitzm.geotools.JTSUtil;
93  import schmitzm.geotools.feature.FeatureUtil;  import schmitzm.geotools.feature.FeatureUtil;
94  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
# Line 99  import skrueger.AttributeMetadataInterfa Line 102  import skrueger.AttributeMetadataInterfa
102  import skrueger.RasterLegendData;  import skrueger.RasterLegendData;
103  import skrueger.i8n.Translation;  import skrueger.i8n.Translation;
104    
105    import com.vividsolutions.jts.geom.Geometry;
106    
107  /**  /**
108   * This class provides static helper methods for dealing with   * This class provides static helper methods for dealing with
109   * {@link StyledLayerInterface} stuff.   * {@link StyledLayerInterface} stuff.
# Line 113  public class StyledLayerUtil { Line 118  public class StyledLayerUtil {
118          private static final SAXBuilder SAX_BUILDER = new SAXBuilder();          private static final SAXBuilder SAX_BUILDER = new SAXBuilder();
119          private static final XMLOutputter XML_OUTPUTTER = new XMLOutputter();          private static final XMLOutputter XML_OUTPUTTER = new XMLOutputter();
120    
121            /**
122             * Is appended to the name of a rule, this rule shall not be shown in the
123             * legend
124             */
125            public final static String HIDE_IN_LAYER_LEGEND_HINT = "HIDE_IN_LEGEND";
126    
127          /** URL for Atlas XML schema */          /** URL for Atlas XML schema */
128          public static final String AMLURI = "http://www.wikisquare.de/AtlasML";          public static final String AMLURI = "http://www.wikisquare.de/AtlasML";
129          /** Name of the XML Element for the attribute meta data map */          /** Name of the XML Element for the attribute meta data map */
# Line 125  public class StyledLayerUtil { Line 136  public class StyledLayerUtil {
136          public static final String ELEM_NAME_RASTERLEGEND = "rasterLegendItem";          public static final String ELEM_NAME_RASTERLEGEND = "rasterLegendItem";
137          /** Name of the XML Element for a translation */          /** Name of the XML Element for a translation */
138          public static final String ELEM_NAME_TRANSLATION = "translation";          public static final String ELEM_NAME_TRANSLATION = "translation";
139            private static FilterFactory2 ff = FilterUtil.FILTER_FAC2;
140    
141          /**          /**
142           * Creates a Geotools {@link MapLayer} from an object. If the object is a           * Creates a Geotools {@link MapLayer} from an object. If the object is a
# Line 923  public class StyledLayerUtil { Line 935  public class StyledLayerUtil {
935          }          }
936    
937          /**          /**
          * *If appended to the name of a rule, this rule shall not be shown in the  
          * legend  
          */  
         public final static String HIDE_IN_LAYER_LEGEND_HINT = "HIDE_IN_LEGEND";  
   
         /**  
938           * Creates a {@link JPanel} that shows a legend for a list of           * Creates a {@link JPanel} that shows a legend for a list of
939           * {@link FeatureTypeStyle}s and a targeted featureType           * {@link FeatureTypeStyle}s and a targeted featureType
940           *           *
941           * @param style           * @param style
942           *            The Style to presented in this legend           *            The Style to presented in this legend
943           * @param featureType           * @param featureType
944           *            If this a legend for Point, Polygon or Line?           *            If this a legend for Point, Polygon or Line? Or ANY or NONE?
945           *           *
946           * @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a>           * @author <a href="mailto:[email protected]">Stefan Alfons Tzeggai</a>
947           */           */
# Line 949  public class StyledLayerUtil { Line 955  public class StyledLayerUtil {
955                          return new JPanel();                          return new JPanel();
956                  }                  }
957    
                 final List<FeatureTypeStyle> list = style.featureTypeStyles();  
   
958                  final JPanel panel = new JPanel(new MigLayout("wrap 2", "[]:3:[]"));                  final JPanel panel = new JPanel(new MigLayout("wrap 2", "[]:3:[]"));
   
959                  if (style == null) {                  if (style == null) {
960                          // No Style => no legend                          // No Style => no legend
961                          return panel;                          return panel;
962                  }                  }
963    
964                  for (final FeatureTypeStyle ftStyle : list) {                  // Reversing the list, because a point that is painted above a polygon
965                    // should be higher in the list.
966                    final List<FeatureTypeStyle> ftsList = style.featureTypeStyles();
967                    Collections.reverse(ftsList);
968                    for (final FeatureTypeStyle ftStyle : ftsList) {
969    
970                            // // Try to import the FeatureType into an AtlasStyler RuleList to
971                            // // determine whether this RL is actually disabled.
972                            // StylingUtil.sldToString(ftStyle).contains(RL_DISABLED_FILTER.toString())
973                            // return;
974    
975                          // One child-node for every rule                          // One child-node for every rule
976                          final List<Rule> rules = ftStyle.rules();                          final List<Rule> rules = ftStyle.rules();
# Line 966  public class StyledLayerUtil { Line 978  public class StyledLayerUtil {
978    
979                                  // Check if this RULE shall actually appear in the legend                                  // Check if this RULE shall actually appear in the legend
980                                  if (rule.getName() != null                                  if (rule.getName() != null
981                                                  && rule.getName().endsWith(HIDE_IN_LAYER_LEGEND_HINT))                                                  && rule.getName().contains(HIDE_IN_LAYER_LEGEND_HINT))
982                                          continue;                                          continue;
983    
984                                  /**                                  /**
# Line 1179  public class StyledLayerUtil { Line 1191  public class StyledLayerUtil {
1191                                          throw new RuntimeException("need a reader...");                                          throw new RuntimeException("need a reader...");
1192                                  //                                  //
1193    
1194                                  final GridCoverage2D cov = (GridCoverage2D) aReader                                  final GridCoverage2D cov = aReader
1195                                                  .read(new GeneralParameterValue[] { readGG });                                                  .read(new GeneralParameterValue[] { readGG });
1196                                  colorModel = cov.getRenderedImage().getColorModel();                                  colorModel = cov.getRenderedImage().getColorModel();
1197                          }                          }
# Line 1363  public class StyledLayerUtil { Line 1375  public class StyledLayerUtil {
1375                  }                  }
1376                  return nicelyFormatted;                  return nicelyFormatted;
1377          }          }
1378    
1379            /**
1380             * Creates a new {@link AttributeMetadataMap} with instances of
1381             * {@link AttributeMetadataInterface} for every non-geometry attribute.
1382             * Default NODATA values (like "" for String) are set.
1383             */
1384            public static AttributeMetadataMap<AttributeMetadataImpl> createDefaultAttributeMetadataMap(
1385                            SimpleFeatureType schema) {
1386                    AttributeMetadataImplMap attMap = new AttributeMetadataImplMap();
1387    
1388                    for (int i = 0; i < schema.getAttributeCount(); i++) {
1389                            AttributeDescriptor attDesc = schema.getDescriptor(i);
1390    
1391                            if (Geometry.class.isAssignableFrom(attDesc.getType().getBinding())) {
1392                                    // Ignore the Geometry column
1393                                    continue;
1394                            }
1395    
1396                            // TODO AttributeMetadataAS would be nicer, which would not work
1397                            // with Translations ;-)
1398                            AttributeMetadataImpl attMetaData = new AttributeMetadataImpl(
1399                                            new NameImpl(attDesc.getName().getNamespaceURI(), attDesc
1400                                                            .getName().getLocalPart()), attMap.getLanguages());
1401    
1402                            if (String.class.isAssignableFrom(attDesc.getType().getBinding())) {
1403                                    // For Strings we add the "" as NODATA values
1404                                    attMetaData.addNodataValue("");
1405                            }
1406    
1407                            attMap.put(attDesc.getName(), attMetaData);
1408                    }
1409                    return attMap;
1410            }
1411  }  }

Legend:
Removed from v.1225  
changed lines
  Added in v.1270

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26