001: /*
002: * Geotools2 - OpenSource mapping toolkit
003: * http://geotools.org
004: * (C) 2002, 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: */
017: package org.geotools.gce.arcgrid;
018:
019: import it.geosolutions.imageio.plugins.arcgrid.spi.AsciiGridsImageReaderSpi;
020:
021: import java.io.IOException;
022: import java.util.HashMap;
023: import java.util.logging.Level;
024: import java.util.logging.Logger;
025:
026: import org.geotools.coverage.grid.io.AbstractGridFormat;
027: import org.geotools.coverage.grid.io.imageio.GeoToolsWriteParams;
028: import org.geotools.data.DataSourceException;
029: import org.geotools.factory.Hints;
030: import org.geotools.parameter.DefaultParameterDescriptor;
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.parameter.GeneralParameterDescriptor;
037:
038: /**
039: * An implementation a {@link Format} for the ASCII grid ESRI and GRASS format.
040: *
041: * @author Daniele Romagnoli
042: * @author Simone Giannecchini (simboss)
043: */
044: public final class ArcGridFormat extends AbstractGridFormat implements
045: Format {
046: /**
047: * Logger.
048: *
049: */
050: private final static Logger LOGGER = org.geotools.util.logging.Logging
051: .getLogger("org.geotools.gce.arcgrid");
052:
053: /** Indicates whether the arcgrid data must be written in GRASS format */
054: public static final DefaultParameterDescriptor GRASS = new DefaultParameterDescriptor(
055: "GRASS",
056: "Indicates whether the arcgrid data has to be written in GRASS format",
057: Boolean.FALSE, true);
058:
059: /** Indicates whether we ask the plugin to resample the coverage to have dx==dy */
060: public static final DefaultParameterDescriptor FORCE_CELLSIZE = new DefaultParameterDescriptor(
061: "FORCE_CELLSIZE",
062: "Indicates whether the input coverage has to be resampled to have dx==dyt",
063: Boolean.FALSE, false);
064:
065: /** Caching the {@link AsciiGridsImageReaderSpi} factory. */
066: private final AsciiGridsImageReaderSpi spi = new AsciiGridsImageReaderSpi();
067:
068: /**
069: * Creates an instance and sets the metadata.
070: */
071: public ArcGridFormat() {
072: if (LOGGER.isLoggable(Level.FINE))
073: LOGGER.fine("Creating a new ArcGriFormat.");
074: setInfo();
075: }
076:
077: /**
078: * Sets the metadata information.
079: */
080: private void setInfo() {
081: HashMap info = new HashMap();
082:
083: info.put("name", "ArcGrid");
084: info.put("description", "Arc Grid Coverage Format");
085: info.put("vendor", "Geotools");
086: info.put("docURL",
087: "http://gdal.velocet.ca/projects/aigrid/index.html");
088: info.put("version", "1.0");
089: mInfo = info;
090:
091: // writing parameters
092: writeParameters = new ParameterGroup(
093: new DefaultParameterDescriptorGroup(mInfo,
094: new GeneralParameterDescriptor[] { GRASS,
095: GEOTOOLS_WRITE_PARAMS, FORCE_CELLSIZE }));
096:
097: // reading parameters
098: readParameters = new ParameterGroup(
099: new DefaultParameterDescriptorGroup(
100: mInfo,
101: new GeneralParameterDescriptor[] { READ_GRIDGEOMETRY2D }));
102: }
103:
104: /**
105: * @see org.geotools.data.coverage.grid.AbstractGridFormat#getReader(Object
106: * source)
107: */
108: public GridCoverageReader getReader(Object source) {
109: return getReader(source, null);
110: }
111:
112: /**
113: * @see org.geotools.data.coverage.grid.AbstractGridFormat#createWriter(java.lang.Object
114: * destination)
115: */
116: public GridCoverageWriter getWriter(Object destination) {
117: try {
118: return new ArcGridWriter(destination);
119: } catch (DataSourceException e) {
120: if (LOGGER.isLoggable(Level.SEVERE))
121: LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
122: throw new RuntimeException(e);
123: }
124: }
125:
126: /**
127: * @see org.geotools.data.coverage.grid.AbstractGridFormat#createWriter(java.lang.Object
128: * destination,Hints hints)
129: */
130: public GridCoverageWriter getWriter(Object destination, Hints hints) {
131: try {
132: return new ArcGridWriter(destination, hints);
133: } catch (DataSourceException e) {
134: if (LOGGER.isLoggable(Level.SEVERE))
135: LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
136: throw new RuntimeException(e);
137: }
138: }
139:
140: /**
141: * @see org.geotools.data.coverage.grid.AbstractGridFormat#accepts(Object
142: * input)
143: */
144: public boolean accepts(Object input) {
145: try {
146: return spi.canDecodeInput(input);
147: } catch (IOException e) {
148: if (LOGGER.isLoggable(Level.FINE))
149: LOGGER.log(Level.FINE, e.getLocalizedMessage(), e);
150: return false;
151: }
152: }
153:
154: /**
155: * @see org.geotools.data.coverage.grid.AbstractGridFormat#getReader(Object,
156: * Hints)
157: */
158: public GridCoverageReader getReader(Object source, Hints hints) {
159: try {
160: return new ArcGridReader(source, hints);
161: } catch (DataSourceException e) {
162: if (LOGGER.isLoggable(Level.SEVERE))
163: LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e);
164: throw new RuntimeException(e);
165: }
166: }
167:
168: /**
169: * Retrieves the default instance for the {@link ArcGridFormat} of the
170: * {@link GeoToolsWriteParams} to control the writing process.
171: *
172: * @return a default instance for the {@link ArcGridFormat} of the
173: * {@link GeoToolsWriteParams} to control the writing process.
174: */
175: public GeoToolsWriteParams getDefaultImageIOWriteParameters() {
176:
177: return new ArcGridWriteParams();
178: }
179: }
|