001: /*
002: * GeoTools - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2003-2006, GeoTools Project Managment Committee (PMC)
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation;
009: * version 2.1 of the License.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: */
016: package org.geotools.coverage.grid.io;
017:
018: import java.util.Map;
019:
020: import javax.imageio.ImageWriteParam;
021:
022: import org.geotools.coverage.grid.GridGeometry2D;
023: import org.geotools.coverage.grid.io.imageio.GeoToolsWriteParams;
024: import org.geotools.factory.Hints;
025: import org.geotools.parameter.DefaultParameterDescriptor;
026: import org.geotools.referencing.CRS;
027: import org.geotools.referencing.crs.DefaultGeographicCRS;
028: import org.opengis.coverage.grid.Format;
029: import org.opengis.coverage.grid.GridCoverageReader;
030: import org.opengis.coverage.grid.GridCoverageWriter;
031: import org.opengis.parameter.GeneralParameterValue;
032: import org.opengis.parameter.ParameterValueGroup;
033: import org.opengis.referencing.FactoryException;
034: import org.opengis.referencing.NoSuchAuthorityCodeException;
035: import org.opengis.referencing.crs.CoordinateReferenceSystem;
036:
037: /**
038: * AbstractGridFormat is a convenience class so subclasses only need to populate
039: * a Map class and set the read and write parameter fields.
040: *
041: *
042: *
043: * For example the ArcGridFormat has the following method which sets up all the
044: * required information: <code>private void setInfo(){ HashMap info=new
045: * HashMap(); info.put("name", "ArcGrid"); info.put("description", "Arc Grid
046: * Coverage Format"); info.put("vendor", "Geotools"); info.put("docURL",
047: * "http://gdal.velocet.ca/projects/aigrid/index.html"); info.put("version",
048: * "1.0"); mInfo=info; readParameters=new GeneralParameterDescriptor[2];
049: * readParameters[0]=ArcGridOperationParameter.getGRASSReadParam();
050: * readParameters[0]=ArcGridOperationParameter.getCompressReadParam();
051: * writeParameters=new GeneralParameterDescriptor[2];
052: * writeParameters[0]=ArcGridOperationParameter.getGRASSWriteParam();
053: * writeParameters[0]=ArcGridOperationParameter.getCompressWriteParam();
054: * }</code>
055: *
056: * @author jeichar
057: * @author Simone Giannecchini
058: * @source $URL:
059: * http://svn.geotools.org/geotools/branches/2.3.x/module/main/src/org/geotools/data/coverage/grid/AbstractGridFormat.java $
060: */
061: public abstract class AbstractGridFormat implements Format {
062:
063: /**
064: * The Map object is used by the information methods(such as getName()) as a
065: * data source. The keys in the Map object (for the associated method) are
066: * as follows: getName() key = "name" value type=String getDescription() key =
067: * "description" value type=String getVendor() key = "vendor" value
068: * type=String getDocURL() key = "docURL" value type=String getVersion() key =
069: * "version" value type=String Naturally, any methods that are overridden
070: * need not have an entry in the Map
071: */
072: protected Map mInfo;
073:
074: /**
075: * {@link ParameterValueGroup} that controls the reading process for a
076: * {@link GridCoverageReader} through the
077: * {@link GridCoverageReader#read(org.opengis.parameter.GeneralParameterValue[])}
078: * method.
079: */
080: protected ParameterValueGroup readParameters;
081:
082: /**
083: * {@link ParameterValueGroup} that controls the writing process for a
084: * {@link GridCoverageWriter} through the
085: * {@link GridCoverageWriter#write(org.opengis.coverage.grid.GridCoverage, org.opengis.parameter.GeneralParameterValue[])}
086: * method.
087: */
088: protected ParameterValueGroup writeParameters;
089:
090: /**
091: * Default {@link CoordinateReferenceSystem} used by all the plugins.
092: */
093: private static CoordinateReferenceSystem crs;
094: static {
095: try {
096: crs = CRS.decode("EPSG:4326", true);
097: } catch (NoSuchAuthorityCodeException e) {
098: crs = DefaultGeographicCRS.WGS84;
099: } catch (FactoryException e) {
100: crs = DefaultGeographicCRS.WGS84;
101: }
102: }
103:
104: /**
105: * This {@link GeneralParameterValue} cacn be provided to the
106: * {@link GridCoverageReader}s through the
107: * {@link GridCoverageReader#read(GeneralParameterValue[])} methid in order
108: * to pick up the best matching resolution level and (soon) the best
109: * matching area.
110: */
111: public static final DefaultParameterDescriptor READ_GRIDGEOMETRY2D = new DefaultParameterDescriptor(
112: "ReadGridGeometry2D", GridGeometry2D.class, null, null);
113:
114: /**
115: * This {@link GeneralParameterValue} cacn be provided to the
116: * {@link GridCoverageWriter}s through the
117: * {@link GridCoverageWriter#write(org.opengis.coverage.grid.GridCoverage, GeneralParameterValue[])}
118: * method in order to control the writing process in terms of compression,
119: * tiling, etc.
120: */
121: public static final DefaultParameterDescriptor GEOTOOLS_WRITE_PARAMS = new DefaultParameterDescriptor(
122: "WriteParameters", GeoToolsWriteParams.class, null, null);
123:
124: /**
125: * This {@link GeneralParameterValue} can be provided to the
126: * {@link GridCoverageReader}s through the
127: * {@link GridCoverageReader#read(GeneralParameterValue[])} method in order
128: * to specify the type of image read operation requested: using a JAI
129: * ImageRead operation (leveraging on Deferred Execution Model,
130: * Tile Caching,...), or the direct {@code ImageReader}'s read methods.
131: */
132: public static final DefaultParameterDescriptor USE_JAI_IMAGEREAD = new DefaultParameterDescriptor(
133: "UseJaiImageRead", Boolean.class, null, null);
134:
135: /**
136: * @see org.opengis.coverage.grid.Format#getName()
137: */
138: public String getName() {
139: return (String) mInfo.get("name");
140: }
141:
142: /**
143: * @see org.opengis.coverage.grid.Format#getDescription()
144: */
145: public String getDescription() {
146: return (String) mInfo.get("description");
147: }
148:
149: /**
150: * @see org.opengis.coverage.grid.Format#getVendor()
151: */
152: public String getVendor() {
153: return (String) mInfo.get("vendor");
154: }
155:
156: /**
157: * @see org.opengis.coverage.grid.Format#getDocURL()
158: */
159: public String getDocURL() {
160: return (String) mInfo.get("docURL");
161: }
162:
163: /**
164: * @see org.opengis.coverage.grid.Format#getVersion()
165: */
166: public String getVersion() {
167: return (String) mInfo.get("version");
168: }
169:
170: /**
171: * Gets a {@link GridCoverageReader} for this format able to create
172: * coverages out of the <code>source</code> object.
173: *
174: * <p>
175: * In case this {@link Format} cannot reader the provided
176: * <code>source</code> object <code>null</code> is returned.
177: *
178: * @param source
179: * The source object to parse.
180: * @return A reader for this {@link Format} or null.
181: */
182: abstract public GridCoverageReader getReader(Object source);
183:
184: /**
185: *
186: * Gets a {@link GridCoverageReader} for this format able to create
187: * coverages out of the <code>source</code> object using the provided
188: * <code>hints</code>.
189: *
190: * <p>
191: * In case this {@link Format} cannot reader the provided
192: * <code>source</code> object <code>null</code> is returned.
193: *
194: * @param source
195: * The source object to parse. *
196: * @param hints
197: * The {@link Hints} to use when trying to instantiate this
198: * reader.
199: * @return A reader for this {@link Format} or null.
200: */
201: abstract public GridCoverageReader getReader(Object source,
202: Hints hints);
203:
204: /**
205: * Retrieves a {@link GridCoverageWriter} suitable for writing to the
206: * provided <code>destination</code> with this format.
207: *
208: * <p>
209: * In case no writers are availaible <code>null</code> is returned.
210: *
211: * @param destination
212: * The destinatin where to write.
213: * @return A {@link GridCoverageWriter} suitable for writing to the provided
214: * <code>destination</code> with this format.
215: */
216: abstract public GridCoverageWriter getWriter(Object destination);
217:
218: /**
219: * Tells me if this {@link Format} can read the provided <code>input</code>.
220: *
221: *
222: * @param input
223: * The input object to test for suitablilty.
224: * @return True if this format can read this object, False otherwise.
225: */
226: public abstract boolean accepts(Object input);
227:
228: /**
229: * @see org.geotools.data.coverage.grid.Format#equals(org.geotools.data.coverage.grid.Format)
230: */
231: public boolean equals(Format f) {
232: if (f.getClass() == getClass()) {
233: return true;
234: }
235: return false;
236: }
237:
238: /**
239: * @see org.opengis.coverage.grid.Format#getReadParameters()
240: */
241: public ParameterValueGroup getReadParameters() {
242: if (this .readParameters == null)
243: throw new UnsupportedOperationException(
244: "This format does not support usage of read parameters.");
245: return (ParameterValueGroup) this .readParameters.clone();
246: }
247:
248: /**
249: * @see org.opengis.coverage.grid.Format#getWriteParameters()
250: */
251: public ParameterValueGroup getWriteParameters() {
252: if (this .writeParameters == null)
253: throw new UnsupportedOperationException(
254: "This format does not support usage of write parameters.");
255: return (ParameterValueGroup) this .writeParameters.clone();
256: }
257:
258: /**
259: * getDefaultCRS
260: *
261: * This method provides the user with a default crs WGS84
262: */
263: static public CoordinateReferenceSystem getDefaultCRS() {
264: return crs;
265: }
266:
267: /**
268: * Returns an instance of {@link ImageWriteParam} that can be used to
269: * control a subsequent
270: * {@link GridCoverageWriter#write(org.opengis.coverage.grid.GridCoverage, org.opengis.parameter.GeneralParameterValue[])};
271: * <p>
272: * Be careful with using the {@link ImageWriteParam} since their usage is
273: * still experimental.
274: *
275: * @return an instance of {@link ImageWriteParam}.
276: */
277: public abstract GeoToolsWriteParams getDefaultImageIOWriteParameters();
278: }
|