001: //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/graphics/LazyRasterLayer.java $
002: /*---------------- FILE HEADER ------------------------------------------
003:
004: This file is part of deegree.
005: Copyright (C) 2001-2008 by:
006: EXSE, Department of Geography, University of Bonn
007: http://www.giub.uni-bonn.de/deegree/
008: lat/lon GmbH
009: http://www.lat-lon.de
010:
011: This library is free software; you can redistribute it and/or
012: modify it under the terms of the GNU Lesser General Public
013: License as published by the Free Software Foundation; either
014: version 2.1 of the License, or (at your option) any later version.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: Contact:
026:
027: Andreas Poth
028: lat/lon GmbH
029: Aennchenstr. 19
030: 53177 Bonn
031: Germany
032: E-Mail: poth@lat-lon.de
033:
034: Prof. Dr. Klaus Greve
035: Department of Geography
036: University of Bonn
037: Meckenheimer Allee 166
038: 53115 Bonn
039: Germany
040: E-Mail: greve@giub.uni-bonn.de
041:
042: ---------------------------------------------------------------------------*/
043: package org.deegree.graphics;
044:
045: import java.io.IOException;
046: import java.util.ArrayList;
047: import java.util.List;
048:
049: import org.deegree.framework.log.ILogger;
050: import org.deegree.framework.log.LoggerFactory;
051: import org.deegree.io.JDBCConnection;
052: import org.deegree.io.oraclegeoraster.GeoRasterDescription;
053: import org.deegree.model.coverage.grid.Format;
054: import org.deegree.model.coverage.grid.GridCoverage;
055: import org.deegree.model.coverage.grid.GridCoverageExchange;
056: import org.deegree.model.coverage.grid.GridCoverageReader;
057: import org.deegree.model.crs.CRSFactory;
058: import org.deegree.model.crs.CoordinateSystem;
059: import org.deegree.model.crs.UnknownCRSException;
060: import org.deegree.model.spatialschema.Envelope;
061: import org.deegree.model.spatialschema.GeometryFactory;
062: import org.deegree.ogcwebservices.InvalidParameterValueException;
063: import org.deegree.ogcwebservices.wcs.configuration.Directory;
064: import org.deegree.ogcwebservices.wcs.configuration.DirectoryResolution;
065: import org.deegree.ogcwebservices.wcs.configuration.Extension;
066: import org.deegree.ogcwebservices.wcs.configuration.File;
067: import org.deegree.ogcwebservices.wcs.configuration.FileResolution;
068: import org.deegree.ogcwebservices.wcs.configuration.OracleGeoRasterResolution;
069: import org.deegree.ogcwebservices.wcs.configuration.Resolution;
070: import org.deegree.ogcwebservices.wcs.configuration.Shape;
071: import org.deegree.ogcwebservices.wcs.configuration.ShapeResolution;
072: import org.deegree.ogcwebservices.wcs.describecoverage.CoverageOffering;
073:
074: /**
075: *
076: *
077: *
078: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
079: * @author last edited by: $Author: apoth $
080: *
081: * @version $Revision: 10225 $, $Date: 2008-02-21 05:42:03 -0800 (Thu, 21 Feb 2008) $
082: */
083: public class LazyRasterLayer extends AbstractLayer {
084:
085: private ILogger LOG = LoggerFactory
086: .getLogger(LazyRasterLayer.class);
087:
088: private Extension resource;
089:
090: private CoverageOffering coverageOffering;
091:
092: /**
093: *
094: * @param name
095: * @param coverageOffering
096: * @throws Exception
097: */
098: public LazyRasterLayer(String name,
099: CoverageOffering coverageOffering) throws Exception {
100: super (name);
101: this .coverageOffering = coverageOffering;
102: resource = coverageOffering.getExtension();
103: }
104:
105: /**
106: *
107: * @param name
108: * @param crs
109: * @param coverageOffering
110: * @throws Exception
111: */
112: public LazyRasterLayer(String name, CoordinateSystem crs,
113: CoverageOffering coverageOffering) throws Exception {
114: super (name, crs);
115: this .coverageOffering = coverageOffering;
116: if (coverageOffering != null) {
117: resource = coverageOffering.getExtension();
118: }
119: }
120:
121: /**
122: * @param crs
123: * @throws Exception
124: *
125: */
126: public void setCoordinatesSystem(CoordinateSystem crs)
127: throws Exception {
128: // not supported yet
129: }
130:
131: /*
132: * (non-Javadoc)
133: *
134: * @see org.deegree.graphics.AbstractLayer#getBoundingBox()
135: */
136: @Override
137: public Envelope getBoundingBox() {
138: return coverageOffering.getDomainSet().getSpatialDomain()
139: .getEnvelops()[0];
140: }
141:
142: /**
143: *
144: * @param envelope
145: * @param resolution
146: * @return
147: * @throws IOException
148: * @throws InvalidParameterValueException
149: */
150: public GridCoverage getRaster(Envelope envelope, double resolution)
151: throws InvalidParameterValueException, IOException {
152:
153: Resolution[] resolutions = resource.getResolutions(resolution);
154:
155: String nativeCRS = coverageOffering.getSupportedCRSs()
156: .getNativeSRSs()[0].getCodes()[0];
157: CoordinateSystem crs;
158: try {
159: crs = CRSFactory.create(nativeCRS);
160: } catch (UnknownCRSException e) {
161: throw new InvalidParameterValueException(e);
162: }
163: envelope = GeometryFactory.createEnvelope(envelope.getMin(),
164: envelope.getMax(), crs);
165:
166: GridCoverageReader reader = null;
167: if (resolutions[0] instanceof FileResolution) {
168: reader = getFileReader(resolutions, envelope);
169: } else if (resolutions[0] instanceof ShapeResolution) {
170: reader = getShapeReader(resolutions, envelope);
171: } else if (resolutions[0] instanceof DirectoryResolution) {
172: reader = getDirectoryReader(resolutions, envelope);
173: } else if (resolutions[0] instanceof OracleGeoRasterResolution) {
174: reader = getOracleGeoRasterReader(resolutions, envelope);
175: } else {
176: throw new InvalidParameterValueException(
177: "not supported coverage resolution: "
178: + resolutions[0].getClass().getName());
179: }
180: return reader.read(null);
181: }
182:
183: /**
184: *
185: * @param resolutions
186: * @param env
187: * @return
188: * @throws IOException
189: * @throws InvalidParameterValueException
190: */
191: private GridCoverageReader getDirectoryReader(
192: Resolution[] resolutions, Envelope env) throws IOException,
193: InvalidParameterValueException {
194:
195: LOG.logInfo("reading coverage from directories");
196:
197: Directory[] dirs = ((DirectoryResolution) resolutions[0])
198: .getDirectories(env);
199:
200: GridCoverageExchange gce = new GridCoverageExchange(null);
201: Format format = new Format(coverageOffering
202: .getSupportedFormats().getNativeFormat());
203:
204: return gce.getReader(dirs, coverageOffering, env, format);
205: }
206:
207: /**
208: *
209: * @param resolutions
210: * @param env
211: * @return
212: * @throws IOException
213: * @throws InvalidParameterValueException
214: */
215: private GridCoverageReader getFileReader(Resolution[] resolutions,
216: Envelope env) throws IOException,
217: InvalidParameterValueException {
218:
219: LOG.logInfo("reading coverage from files");
220:
221: File[] files = ((FileResolution) resolutions[0]).getFiles();
222: List<File> list = new ArrayList<File>();
223: for (int i = 0; i < files.length; i++) {
224: Envelope fileEnv = files[i].getEnvelope();
225: if (fileEnv.intersects(env)) {
226: list.add(files[i]);
227: }
228: }
229: files = list.toArray(new File[list.size()]);
230:
231: GridCoverageExchange gce = new GridCoverageExchange(null);
232: Format format = new Format(coverageOffering
233: .getSupportedFormats().getNativeFormat());
234:
235: return gce.getReader(files, coverageOffering, env, format);
236: }
237:
238: /**
239: *
240: * @param resolutions
241: * @param env
242: * @return
243: * @throws InvalidParameterValueException
244: * @throws IOException
245: */
246: private GridCoverageReader getOracleGeoRasterReader(
247: Resolution[] resolutions, Envelope env)
248: throws InvalidParameterValueException, IOException {
249:
250: LOG.logInfo("reading coverage from oracle georaster");
251:
252: JDBCConnection jdbc = ((OracleGeoRasterResolution) resolutions[0])
253: .getJDBCConnection();
254: String table = ((OracleGeoRasterResolution) resolutions[0])
255: .getTable();
256: String rdtTable = ((OracleGeoRasterResolution) resolutions[0])
257: .getRdtTable();
258: String column = ((OracleGeoRasterResolution) resolutions[0])
259: .getColumn();
260: String identification = ((OracleGeoRasterResolution) resolutions[0])
261: .getIdentification();
262: int level = ((OracleGeoRasterResolution) resolutions[0])
263: .getLevel();
264: GeoRasterDescription grd = new GeoRasterDescription(jdbc,
265: table, rdtTable, column, identification, level);
266:
267: GridCoverageExchange gce = new GridCoverageExchange(null);
268: Format format = new Format(coverageOffering
269: .getSupportedFormats().getNativeFormat());
270:
271: return gce.getReader(grd, coverageOffering, env, format);
272:
273: }
274:
275: /**
276: *
277: * @param resolutions
278: * @param env
279: * @return
280: * @throws IOException
281: * @throws InvalidParameterValueException
282: */
283: private GridCoverageReader getShapeReader(Resolution[] resolutions,
284: Envelope env) throws IOException,
285: InvalidParameterValueException {
286:
287: LOG.logInfo("reading coverage from shapes");
288:
289: Shape shape = ((ShapeResolution) resolutions[0]).getShape();
290:
291: GridCoverageExchange gce = new GridCoverageExchange(null);
292: Format format = new Format(coverageOffering
293: .getSupportedFormats().getNativeFormat());
294: return gce.getReader(shape, coverageOffering, env, format);
295:
296: }
297:
298: }
|