001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2007, Geotools Project Managment Committee (PMC)
005: * (C) 2007, GeoSolutions S.A.S.
006: *
007: * This library is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU Lesser General Public
009: * License as published by the Free Software Foundation;
010: * version 2.1 of the License.
011: *
012: * This library is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: */
018: package org.geotools.gce.ecw;
019:
020: import it.geosolutions.imageio.plugins.ecw.ECWImageReaderSpi;
021:
022: import java.io.IOException;
023: import java.util.HashMap;
024: import java.util.logging.Level;
025: import java.util.logging.Logger;
026:
027: import org.geotools.coverage.grid.io.AbstractGridFormat;
028: import org.geotools.coverage.grid.io.imageio.GeoToolsWriteParams;
029: import org.geotools.data.DataSourceException;
030: import org.geotools.factory.Hints;
031: import org.geotools.parameter.DefaultParameterDescriptorGroup;
032: import org.geotools.parameter.ParameterGroup;
033: import org.opengis.coverage.grid.Format;
034: import org.opengis.coverage.grid.GridCoverageReader;
035: import org.opengis.coverage.grid.GridCoverageWriter;
036: import org.opengis.geometry.MismatchedDimensionException;
037: import org.opengis.parameter.GeneralParameterDescriptor;
038:
039: /**
040: * An implementation a {@link Format} for the ECW format.
041: *
042: * @author Daniele Romagnoli, GeoSolutions
043: * @author Simone Giannecchini, GeoSolutions
044: */
045: public final class ECWFormat extends AbstractGridFormat implements
046: Format {
047: /**
048: * Logger.
049: */
050: private final static Logger LOGGER = org.geotools.util.logging.Logging
051: .getLogger("org.geotools.gce.ecw");
052:
053: /** Caching the {@link ECWImageReaderSpi} factory. */
054: private final ECWImageReaderSpi spi = new ECWImageReaderSpi();
055:
056: /**
057: * Creates an instance and sets the metadata.
058: */
059: public ECWFormat() {
060: if (LOGGER.isLoggable(Level.FINE))
061: LOGGER.fine("Creating a new ECWFormat.");
062: setInfo();
063: }
064:
065: /**
066: * Sets the metadata information.
067: */
068: private void setInfo() {
069: HashMap info = new HashMap();
070:
071: info.put("name", "ECW");
072: info.put("description", "ECW Coverage Format");
073: info.put("vendor", "Geotools");
074: info.put("docURL", "");//TODO: set something
075: info.put("version", "1.0");
076: mInfo = info;
077:
078: // writing parameters
079: writeParameters = null;
080:
081: // reading parameters
082: readParameters = new ParameterGroup(
083: new DefaultParameterDescriptorGroup(
084: mInfo,
085: new GeneralParameterDescriptor[] { READ_GRIDGEOMETRY2D }));
086: }
087:
088: /**
089: * @see org.geotools.data.coverage.grid.AbstractGridFormat#getReader(Object
090: * source)
091: */
092: public GridCoverageReader getReader(Object source) {
093: return getReader(source, null);
094: }
095:
096: /**
097: * @see org.geotools.data.coverage.grid.AbstractGridFormat#createWriter(java.lang.Object
098: * destination)
099: */
100: public GridCoverageWriter getWriter(Object destination) {
101: throw new UnsupportedOperationException(
102: "This plugin does not support writing");
103: }
104:
105: /**
106: * @see org.geotools.data.coverage.grid.AbstractGridFormat#createWriter(java.lang.Object
107: * destination,Hints hints)
108: */
109: public GridCoverageWriter getWriter(Object destination, Hints hints) {
110: throw new UnsupportedOperationException(
111: "This plugin does not support writing");
112: }
113:
114: /**
115: * @see org.geotools.data.coverage.grid.AbstractGridFormat#accepts(Object
116: * input)
117: */
118: public boolean accepts(Object input) {
119: try {
120: return spi.canDecodeInput(input);
121: } catch (IOException e) {
122: if (LOGGER.isLoggable(Level.FINE))
123: LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
124: return false;
125: }
126: }
127:
128: /**
129: * @see org.geotools.data.coverage.grid.AbstractGridFormat#getReader(Object,
130: * Hints)
131: */
132: public GridCoverageReader getReader(Object source, Hints hints) {
133: try {
134: return new ECWReader(source, hints);
135: } catch (MismatchedDimensionException e) {
136: final RuntimeException re = new RuntimeException();
137: re.initCause(e);
138: throw re;
139: } catch (DataSourceException e) {
140: final RuntimeException re = new RuntimeException();
141: re.initCause(e);
142: throw re;
143: }
144: }
145:
146: public GeoToolsWriteParams getDefaultImageIOWriteParameters() {
147: throw new UnsupportedOperationException(
148: "This plugin does not support writing parameters");
149: }
150: }
|