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.mrsid;
019:
020: import it.geosolutions.imageio.plugins.mrsid.MrSIDImageReaderSpi;
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 MrSID format.
041: *
042: * @author Daniele Romagnoli, GeoSolutions
043: * @author Simone Giannecchini, GeoSolutions
044: */
045: public final class MrSIDFormat extends AbstractGridFormat implements
046: Format {
047: private final static Logger LOGGER = org.geotools.util.logging.Logging
048: .getLogger("org.geotools.gce.mrsid");
049:
050: /** Caching the {@link MrSIDImageReaderSpi} factory. */
051: private final MrSIDImageReaderSpi spi = new MrSIDImageReaderSpi();
052:
053: /**
054: * Creates an instance and sets the metadata.
055: */
056: public MrSIDFormat() {
057: if (LOGGER.isLoggable(Level.FINE))
058: LOGGER.fine("Creating a new MrSIDFormat.");
059: setInfo();
060: }
061:
062: /**
063: * Sets the metadata information.
064: */
065: private void setInfo() {
066: HashMap info = new HashMap();
067:
068: info.put("name", "MrSID");
069: info.put("description", "MrSID Coverage Format");
070: info.put("vendor", "Geotools");
071: info.put("docURL", "");//TODO: set something
072: info.put("version", "1.0");
073: mInfo = info;
074:
075: // writing parameters
076: writeParameters = null;
077:
078: // reading parameters
079: readParameters = new ParameterGroup(
080: new DefaultParameterDescriptorGroup(
081: mInfo,
082: new GeneralParameterDescriptor[] { READ_GRIDGEOMETRY2D }));
083: }
084:
085: /**
086: * @see org.geotools.data.coverage.grid.AbstractGridFormat#getReader(Object
087: * source)
088: */
089: public GridCoverageReader getReader(Object source) {
090: return getReader(source, null);
091: }
092:
093: /**
094: * @see org.geotools.data.coverage.grid.AbstractGridFormat#createWriter(java.lang.Object
095: * destination)
096: */
097: public GridCoverageWriter getWriter(Object destination) {
098: throw new UnsupportedOperationException(
099: "This plugin does not support writing at this time.");
100: }
101:
102: /**
103: * @see org.geotools.data.coverage.grid.AbstractGridFormat#createWriter(java.lang.Object
104: * destination,Hints hints)
105: */
106: public GridCoverageWriter getWriter(Object destination, Hints hints) {
107: throw new UnsupportedOperationException(
108: "This plugin does not support writing at this time.");
109: }
110:
111: /**
112: * @see org.geotools.data.coverage.grid.AbstractGridFormat#accepts(Object
113: * input)
114: */
115: public boolean accepts(Object input) {
116: try {
117: return spi.canDecodeInput(input);
118: } catch (IOException e) {
119: if (LOGGER.isLoggable(Level.FINE))
120: LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
121: return false;
122: }
123: }
124:
125: /**
126: * @see org.geotools.data.coverage.grid.AbstractGridFormat#getReader(Object,
127: * Hints)
128: */
129: public GridCoverageReader getReader(Object source, Hints hints) {
130: try {
131: return new MrSIDReader(source, hints);
132: } catch (MismatchedDimensionException e) {
133: final RuntimeException re = new RuntimeException();
134: re.initCause(e);
135: throw re;
136: } catch (DataSourceException e) {
137: final RuntimeException re = new RuntimeException();
138: re.initCause(e);
139: throw re;
140: }
141: }
142:
143: public GeoToolsWriteParams getDefaultImageIOWriteParameters() {
144: throw new UnsupportedOperationException(
145: "This plugin does not support writing at this time.");
146: }
147: }
|