/[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 405 by alfonx, Mon Sep 14 15:43:28 2009 UTC revision 420 by alfonx, Thu Oct 1 20:22:48 2009 UTC
# Line 44  import java.io.FileNotFoundException; Line 44  import java.io.FileNotFoundException;
44  import java.io.FileWriter;  import java.io.FileWriter;
45  import java.net.URL;  import java.net.URL;
46  import java.text.DecimalFormat;  import java.text.DecimalFormat;
 import java.util.HashMap;  
47  import java.util.List;  import java.util.List;
48  import java.util.Map;  import java.util.Map;
 import java.util.SortedMap;  
 import java.util.TreeMap;  
49    
50  import javax.swing.BorderFactory;  import javax.swing.BorderFactory;
51  import javax.swing.Box;  import javax.swing.Box;
# Line 63  import org.geotools.coverage.grid.GridGe Line 60  import org.geotools.coverage.grid.GridGe
60  import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;  import org.geotools.coverage.grid.io.AbstractGridCoverage2DReader;
61  import org.geotools.coverage.grid.io.AbstractGridFormat;  import org.geotools.coverage.grid.io.AbstractGridFormat;
62  import org.geotools.feature.FeatureCollection;  import org.geotools.feature.FeatureCollection;
 import org.geotools.gce.imagepyramid.ImagePyramidReader;  
63  import org.geotools.geometry.jts.ReferencedEnvelope;  import org.geotools.geometry.jts.ReferencedEnvelope;
64  import org.geotools.map.DefaultMapLayer;  import org.geotools.map.DefaultMapLayer;
65  import org.geotools.map.MapLayer;  import org.geotools.map.MapLayer;
# Line 79  import org.jdom.Document; Line 75  import org.jdom.Document;
75  import org.jdom.Element;  import org.jdom.Element;
76  import org.jdom.input.SAXBuilder;  import org.jdom.input.SAXBuilder;
77  import org.jdom.output.XMLOutputter;  import org.jdom.output.XMLOutputter;
78    import org.opengis.feature.simple.SimpleFeature;
79  import org.opengis.feature.simple.SimpleFeatureType;  import org.opengis.feature.simple.SimpleFeatureType;
80  import org.opengis.parameter.GeneralParameterValue;  import org.opengis.parameter.GeneralParameterValue;
81    
82  import schmitzm.geotools.JTSUtil;  import schmitzm.geotools.JTSUtil;
83    import schmitzm.geotools.feature.FeatureUtil;
84  import schmitzm.geotools.styling.StylingUtil;  import schmitzm.geotools.styling.StylingUtil;
85  import schmitzm.io.IOUtil;  import schmitzm.io.IOUtil;
86  import schmitzm.lang.LangUtil;  import schmitzm.lang.LangUtil;
# Line 244  public class StyledLayerUtil { Line 242  public class StyledLayerUtil {
242           *            indicated whether the visible or invisible entries are           *            indicated whether the visible or invisible entries are
243           *            returned           *            returned
244           */           */
245          public static SortedMap<Integer, AttributeMetaData> getVisibleAttributeMetaData(          public static AttributeMetadataMap getVisibleAttributeMetaData(
246                          Map<Integer, AttributeMetaData> amdMap, boolean visible) {                          Map<Integer, AttributeMetaData> amdMap, boolean visible) {
247                  SortedMap<Integer, AttributeMetaData> filteredMap = new TreeMap<Integer, AttributeMetaData>();                  AttributeMetadataMap filteredMap = new AttributeMetadataMap();
248                  for (AttributeMetaData amd : amdMap.values())                  for (AttributeMetaData amd : amdMap.values())
249                          if (amd.isVisible())                          if (amd.isVisible())
250                                  filteredMap.put(amd.getColIdx(), amd);                                  filteredMap.put(amd.getColIdx(), amd);
# Line 289  public class StyledLayerUtil { Line 287  public class StyledLayerUtil {
287           * @param element           * @param element
288           *            {@link Element} to parse           *            {@link Element} to parse
289           */           */
290          public static Map<Integer, AttributeMetaData> parseAttributeMetaDataMap(          public static AttributeMetadataMap parseAttributeMetaDataMap(
291                          final Element element) {                          final Element element) {
292                  HashMap<Integer, AttributeMetaData> metaData = new HashMap<Integer, AttributeMetaData>();                  AttributeMetadataMap metaData = new AttributeMetadataMap();
293                  List<Element> attributesElements = element                  List<Element> attributesElements = element
294                                  .getChildren(ELEM_NAME_ATTRIBUTE);                                  .getChildren(ELEM_NAME_ATTRIBUTE);
295                  for (Element attibuteElement : attributesElements) {                  for (Element attibuteElement : attributesElements) {
# Line 308  public class StyledLayerUtil { Line 306  public class StyledLayerUtil {
306           *            {@link URL} to parse           *            {@link URL} to parse
307           * @see #parseAttributeMetaData(Element)           * @see #parseAttributeMetaData(Element)
308           */           */
309          public static Map<Integer, AttributeMetaData> loadAttributeMetaDataMap(          public static AttributeMetadataMap loadAttributeMetaDataMap(
310                          final URL documentUrl) throws Exception {                          final URL documentUrl) throws Exception {
311                  Document document = SAX_BUILDER.build(documentUrl);                  Document document = SAX_BUILDER.build(documentUrl);
312                  return parseAttributeMetaDataMap(document.getRootElement());                  return parseAttributeMetaDataMap(document.getRootElement());
# Line 342  public class StyledLayerUtil { Line 340  public class StyledLayerUtil {
340           *            map of attribute meta data           *            map of attribute meta data
341           */           */
342          public static Element createAttributeMetaDataMapElement(          public static Element createAttributeMetaDataMapElement(
343                          final Map<Integer, AttributeMetaData> amdMap) {                          final AttributeMetadataMap amdMap) {
344                  final Element element = new Element(ELEM_NAME_AMD, AMLURI);                  final Element element = new Element(ELEM_NAME_AMD, AMLURI);
345                  for (AttributeMetaData amd : amdMap.values())                  for (AttributeMetaData amd : amdMap.values())
346                          element.addContent(createAttributeMetaDataElement(amd));                          element.addContent(createAttributeMetaDataElement(amd));
# Line 358  public class StyledLayerUtil { Line 356  public class StyledLayerUtil {
356           *            {@link URL} to store the XML           *            {@link URL} to store the XML
357           */           */
358          public static void saveAttributeMetaDataMap(          public static void saveAttributeMetaDataMap(
359                          final Map<Integer, AttributeMetaData> amdMap, final URL documentUrl)                          final AttributeMetadataMap amdMap, final URL documentUrl)
360                          throws Exception {                          throws Exception {
361                  // Create XML-Document                  // Create XML-Document
362                  final FileWriter out = new FileWriter(new File(documentUrl.toURI()));                  final FileWriter out = new FileWriter(new File(documentUrl.toURI()));
# Line 625  public class StyledLayerUtil { Line 623  public class StyledLayerUtil {
623                  }                  }
624                  if (styledObject instanceof StyledFeatureCollectionInterface                  if (styledObject instanceof StyledFeatureCollectionInterface
625                                  && (style.getMetaData() instanceof Map || style.getMetaData() == null)) {                                  && (style.getMetaData() instanceof Map || style.getMetaData() == null)) {
626                          Map<Integer, AttributeMetaData> sourceAmd = (Map<Integer, AttributeMetaData>) style                          AttributeMetadataMap sourceAmd = (AttributeMetadataMap) style
627                                          .getMetaData();                                          .getMetaData();
628                          Map<Integer, AttributeMetaData> destAmd = ((StyledFeatureCollectionInterface) styledObject)                          AttributeMetadataMap destAmd = ((StyledFeatureCollectionInterface) styledObject)
629                                          .getAttributeMetaDataMap();                                          .getAttributeMetaDataMap();
630                          if (destAmd != null && sourceAmd != null) {                          if (destAmd != null && sourceAmd != null) {
631                                  destAmd.clear();                                  destAmd.clear();
# Line 853  public class StyledLayerUtil { Line 851  public class StyledLayerUtil {
851                                  // KOMPILIERBAR!!                                  // KOMPILIERBAR!!
852                          } else if (metaData instanceof Map) {                          } else if (metaData instanceof Map) {
853                                  saveAttributeMetaDataMap(                                  saveAttributeMetaDataMap(
854                                                  (Map<Integer, AttributeMetaData>) metaData, IOUtil                                                  (AttributeMetadataMap) metaData, IOUtil
855                                                                  .changeUrlExt(geoObjectURL, mdExt));                                                                  .changeUrlExt(geoObjectURL, mdExt));
856                          } else                          } else
857                                  throw new UnsupportedOperationException(                                  throw new UnsupportedOperationException(
# Line 980  public class StyledLayerUtil { Line 978  public class StyledLayerUtil {
978                                  hbox.add(iconLabel);                                  hbox.add(iconLabel);
979                                  hbox.add(Box.createHorizontalStrut(3));                                  hbox.add(Box.createHorizontalStrut(3));
980    
                                 // ****************************************************************************  
                                 // The labeltext is read from the SLD. Its either the title  
                                 // directly, or interpreted as OneLine Code  
                                 // ****************************************************************************  
                                 // final String rawText =  
                                 // rule.getDescription().getTitle().toString();  
                                 final String rawText = rule.getDescription().getTitle()  
                                                 .toString();  
   
981                                  Translation labelT = new Translation();                                  Translation labelT = new Translation();
982                                  labelT.fromOneLine(rawText);                                  labelT.fromOneLine(rule.getDescription().getTitle());
983    
984                                  final JLabel classTitleLabel = new JLabel(labelT.toString());                                  final JLabel classTitleLabel = new JLabel(labelT.toString());
985                                  hbox.add(classTitleLabel);                                  hbox.add(classTitleLabel);
# Line 1020  public class StyledLayerUtil { Line 1009  public class StyledLayerUtil {
1009                   */                   */
1010                  ColorModel colorModel = null;                  ColorModel colorModel = null;
1011                  if (!isStyleable(styledRaster)                  if (!isStyleable(styledRaster)
1012                                  || (isStyleable(styledRaster) && styledRaster.getStyle() != null)) {                                  || (isStyleable(styledRaster) && styledRaster.getStyle() == null)) {
1013                          colorModel = getColorModel(styledRaster);                          colorModel = getColorModel(styledRaster);
1014                  }                  }
1015    
# Line 1118  public class StyledLayerUtil { Line 1107  public class StyledLayerUtil {
1107                                          graphics.setColor(color);                                          graphics.setColor(color);
1108                                          graphics.fillRect(0, 0, ICON_SIZE.width, ICON_SIZE.height);                                          graphics.fillRect(0, 0, ICON_SIZE.width, ICON_SIZE.height);
1109                                  } catch (Exception e) {                                  } catch (Exception e) {
1110                                          LOGGER.debug("Dann nehmen wir halt den GridCoverageRenderer", e);                                          LOGGER.debug(
1111                                                            "Dann nehmen wir halt den GridCoverageRenderer", e);
1112                                          colorModel = null;                                          colorModel = null;
1113                                  }                                  }
1114                          }                          }
# Line 1197  public class StyledLayerUtil { Line 1187  public class StyledLayerUtil {
1187           * Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May           * Extracts the {@link ColorModel} of any {@link StyledRasterInterface}. May
1188           * return <code>null</code> if the geoobject can not be accessed.           * return <code>null</code> if the geoobject can not be accessed.
1189           */           */
1190            @SuppressWarnings("unchecked")
1191          public static ColorModel getColorModel(StyledRasterInterface<?> styledGrid) {          public static ColorModel getColorModel(StyledRasterInterface<?> styledGrid) {
1192                  ColorModel colorModel = null;                  ColorModel colorModel = null;
1193                  try {                  try {
# Line 1204  public class StyledLayerUtil { Line 1195  public class StyledLayerUtil {
1195                          if (geoObject instanceof GridCoverage2D) {                          if (geoObject instanceof GridCoverage2D) {
1196                                  GridCoverage2D cov = (GridCoverage2D) geoObject;                                  GridCoverage2D cov = (GridCoverage2D) geoObject;
1197                                  colorModel = cov.getRenderedImage().getColorModel();                                  colorModel = cov.getRenderedImage().getColorModel();
1198                          } else if (geoObject instanceof ImagePyramidReader) {                          } else if (styledGrid instanceof StyledRasterPyramidInterface) {
1199    
1200                                  Parameter readGG = new Parameter(                                  Parameter readGG = new Parameter(
1201                                                  AbstractGridFormat.READ_GRIDGEOMETRY2D);                                                  AbstractGridFormat.READ_GRIDGEOMETRY2D);
# Line 1213  public class StyledLayerUtil { Line 1204  public class StyledLayerUtil {
1204                                                  styledGrid.getEnvelope(), styledGrid.getCrs());                                                  styledGrid.getEnvelope(), styledGrid.getCrs());
1205    
1206                                  readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(                                  readGG.setValue(new GridGeometry2D(new GeneralGridEnvelope(
1207                                                  new Rectangle(0, 0, 10, 10)), mapExtend));                                                  new Rectangle(0, 0, 1, 1)), mapExtend));
1208    
1209                                    FeatureCollection<SimpleFeatureType, SimpleFeature> rFc = (FeatureCollection<SimpleFeatureType, SimpleFeature>) geoObject;
1210    
1211                                  final AbstractGridCoverage2DReader aReader = (AbstractGridCoverage2DReader) geoObject;                                  final AbstractGridCoverage2DReader aReader = (AbstractGridCoverage2DReader) FeatureUtil
1212                                                    .getWrappedGeoObject(rFc);
1213                                  GridCoverage2D cov = (GridCoverage2D) aReader                                  GridCoverage2D cov = (GridCoverage2D) aReader
1214                                                  .read(new GeneralParameterValue[] { readGG });                                                  .read(new GeneralParameterValue[] { readGG });
1215                                  colorModel = cov.getRenderedImage().getColorModel();                                  colorModel = cov.getRenderedImage().getColorModel();
1216                          }                          }
1217                  } catch (Exception e) {                  } catch (Exception e) {
1218                          LOGGER.error("Error reading the colormodel from " + styledGrid);                          LOGGER.error("Error reading the colormodel from " + styledGrid, e);
1219                          return null;                          return null;
1220                  }                  }
1221                  return colorModel;                  return colorModel;

Legend:
Removed from v.405  
changed lines
  Added in v.420

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26