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.data.coverage.grid;
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: * @deprecated use
059: * {@link org.geotools.coverage.grid.io.AbstractGridFormat}
060: * instead.
061: */
062: public abstract class AbstractGridFormat implements Format {
063:
064: /**
065: * The Map object is used by the information methods(such as getName()) as a
066: * data source. The keys in the Map object (for the associated method) are
067: * as follows: getName() key = "name" value type=String getDescription() key =
068: * "description" value type=String getVendor() key = "vendor" value
069: * type=String getDocURL() key = "docURL" value type=String getVersion() key =
070: * "version" value type=String Naturally, any methods that are overridden
071: * need not have an entry in the Map
072: */
073: protected Map mInfo;
074:
075: /**
076: * {@link ParameterValueGroup} that controls the reading process for a
077: * {@link GridCoverageReader} through the
078: * {@link GridCoverageReader#read(org.opengis.parameter.GeneralParameterValue[])}
079: * method.
080: */
081: protected ParameterValueGroup readParameters;
082:
083: /**
084: * {@link ParameterValueGroup} that controls the writing process for a
085: * {@link GridCoverageWriter} through the
086: * {@link GridCoverageWriter#write(org.opengis.coverage.grid.GridCoverage, org.opengis.parameter.GeneralParameterValue[])}
087: * method.
088: */
089: protected ParameterValueGroup writeParameters;
090:
091: /**
092: * Default {@link CoordinateReferenceSystem} used by all the plugins.
093: */
094: private static CoordinateReferenceSystem crs;
095: static {
096: try {
097: crs = CRS.decode("EPSG:4326", true);
098: } catch (NoSuchAuthorityCodeException e) {
099: crs = DefaultGeographicCRS.WGS84;
100: } catch (FactoryException e) {
101: crs = DefaultGeographicCRS.WGS84;
102: }
103: }
104:
105: /**
106: * This {@link GeneralParameterValue} cacn be provided to the
107: * {@link GridCoverageReader}s through the
108: * {@link GridCoverageReader#read(GeneralParameterValue[])} methid in order
109: * to pick up the best matching resolution level and (soon) the best
110: * matching area.
111: */
112: public static final DefaultParameterDescriptor READ_GRIDGEOMETRY2D = new DefaultParameterDescriptor(
113: "ReadGridGeometry2D", GridGeometry2D.class, null, null);
114:
115: /**
116: * This {@link GeneralParameterValue} cacn be provided to the
117: * {@link GridCoverageWriter}s through the
118: * {@link GridCoverageWriter#write(org.opengis.coverage.grid.GridCoverage, GeneralParameterValue[])}
119: * method in order to control the writing process in terms of compression,
120: * tiling, etc.
121: */
122: public static final DefaultParameterDescriptor GEOTOOLS_WRITE_PARAMS = new DefaultParameterDescriptor(
123: "WriteParameters", GeoToolsWriteParams.class, null, null);
124:
125: /**
126: * @see org.opengis.coverage.grid.Format#getName()
127: */
128: public String getName() {
129: return (String) mInfo.get("name");
130: }
131:
132: /**
133: * @see org.opengis.coverage.grid.Format#getDescription()
134: */
135: public String getDescription() {
136: return (String) mInfo.get("description");
137: }
138:
139: /**
140: * @see org.opengis.coverage.grid.Format#getVendor()
141: */
142: public String getVendor() {
143: return (String) mInfo.get("vendor");
144: }
145:
146: /**
147: * @see org.opengis.coverage.grid.Format#getDocURL()
148: */
149: public String getDocURL() {
150: return (String) mInfo.get("docURL");
151: }
152:
153: /**
154: * @see org.opengis.coverage.grid.Format#getVersion()
155: */
156: public String getVersion() {
157: return (String) mInfo.get("version");
158: }
159:
160: /**
161: * Gets a {@link GridCoverageReader} for this format able to create
162: * coverages out of the <code>source</code> object.
163: *
164: * <p>
165: * In case this {@link Format} cannot reader the provided
166: * <code>source</code> object <code>null</code> is returned.
167: *
168: * @param source
169: * The source object to parse.
170: * @return A reader for this {@link Format} or null.
171: */
172: abstract public GridCoverageReader getReader(Object source);
173:
174: /**
175: *
176: * Gets a {@link GridCoverageReader} for this format able to create
177: * coverages out of the <code>source</code> object using the provided
178: * <code>hints</code>.
179: *
180: * <p>
181: * In case this {@link Format} cannot reader the provided
182: * <code>source</code> object <code>null</code> is returned.
183: *
184: * @param source
185: * The source object to parse. *
186: * @param hints
187: * The {@link Hints} to use when trying to instantiate this
188: * reader.
189: * @return A reader for this {@link Format} or null.
190: */
191: abstract public GridCoverageReader getReader(Object source,
192: Hints hints);
193:
194: /**
195: * Retrieves a {@link GridCoverageWriter} suitable for writing to the
196: * provided <code>destination</code> with this format.
197: *
198: * <p>
199: * In case no writers are availaible <code>null</code> is returned.
200: *
201: * @param destination
202: * The destinatin where to write.
203: * @return A {@link GridCoverageWriter} suitable for writing to the provided
204: * <code>destination</code> with this format.
205: */
206: abstract public GridCoverageWriter getWriter(Object destination);
207:
208: /**
209: * Tells me if this {@link Format} can read the provided <code>input</code>.
210: *
211: *
212: * @param input
213: * The input object to test for suitablilty.
214: * @return True if this format can read this object, False otherwise.
215: */
216: public abstract boolean accepts(Object input);
217:
218: /**
219: * @see org.geotools.data.coverage.grid.Format#equals(org.geotools.data.coverage.grid.Format)
220: */
221: public boolean equals(Format f) {
222: if (f.getClass() == getClass()) {
223: return true;
224: }
225: return false;
226: }
227:
228: /*
229: * (non-Javadoc)
230: *
231: * @see org.opengis.coverage.grid.Format#getReadParameters()
232: */
233: public ParameterValueGroup getReadParameters() {
234: return this .readParameters;
235: }
236:
237: /*
238: * (non-Javadoc)
239: *
240: * @see org.opengis.coverage.grid.Format#getWriteParameters()
241: */
242: public ParameterValueGroup getWriteParameters() {
243: return this .writeParameters;
244: }
245:
246: /**
247: * getDefaultCRS
248: *
249: * This method provides the user with a default crs WGS84
250: */
251: static public CoordinateReferenceSystem getDefaultCRS() {
252: return crs;
253: }
254:
255: /**
256: * Returns an instance of {@link ImageWriteParam} that can be used to
257: * control a subsequent
258: * {@link GridCoverageWriter#write(org.opengis.coverage.grid.GridCoverage, org.opengis.parameter.GeneralParameterValue[])};
259: * <p>
260: * Be careful with using the {@link ImageWriteParam} since their usage is
261: * still experimental.
262: *
263: * @return an instance of {@link ImageWriteParam}.
264: */
265: public abstract GeoToolsWriteParams getDefaultImageIOWriteParameters();
266: }
|