001 //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.3_testing/src/org/deegree/model/coverage/grid/oracle/OracleGeoRasterGridCoverageReader.java $
002
003 /*----------------------------------------------------------------------------
004 This file is part of deegree, http://deegree.org/
005 Copyright (C) 2001-2009 by:
006 Department of Geography, University of Bonn
007 and
008 lat/lon GmbH
009 and
010 grit GmbH
011 http://www.grit.de
012
013 This library is free software; you can redistribute it and/or modify it under
014 the terms of the GNU Lesser General Public License as published by the Free
015 Software Foundation; either version 2.1 of the License, or (at your option)
016 any later version.
017 This library is distributed in the hope that it will be useful, but WITHOUT
018 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
019 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
020 details.
021 You should have received a copy of the GNU Lesser General Public License
022 along with this library; if not, write to the Free Software Foundation, Inc.,
023 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024
025 Contact information:
026
027 lat/lon GmbH
028 Aennchenstr. 19, 53177 Bonn
029 Germany
030 http://lat-lon.de/
031
032 Department of Geography, University of Bonn
033 Prof. Dr. Klaus Greve
034 Postfach 1147, 53001 Bonn
035 Germany
036 http://www.geographie.uni-bonn.de/deegree/
037
038 e-mail: info@deegree.org
039 ----------------------------------------------------------------------------*/
040
041 package org.deegree.model.coverage.grid.oracle;
042
043 import java.awt.image.BufferedImage;
044 import java.awt.image.RenderedImage;
045 import java.io.IOException;
046
047 import org.deegree.datatypes.CodeList;
048 import org.deegree.datatypes.parameter.GeneralParameterValueIm;
049 import org.deegree.datatypes.parameter.InvalidParameterNameException;
050 import org.deegree.datatypes.parameter.InvalidParameterValueException;
051 import org.deegree.datatypes.parameter.OperationParameterIm;
052 import org.deegree.datatypes.parameter.ParameterNotFoundException;
053 import org.deegree.framework.log.ILogger;
054 import org.deegree.framework.log.LoggerFactory;
055 import org.deegree.io.oraclegeoraster.GeoRasterDescription;
056 import org.deegree.io.oraclegeoraster.GeoRasterReader;
057 import org.deegree.model.coverage.grid.AbstractGridCoverageReader;
058 import org.deegree.model.coverage.grid.Format;
059 import org.deegree.model.coverage.grid.GridCoverage;
060 import org.deegree.model.coverage.grid.ImageGridCoverage;
061 import org.deegree.model.spatialschema.Envelope;
062 import org.deegree.ogcwebservices.LonLatEnvelope;
063 import org.deegree.ogcwebservices.wcs.describecoverage.CoverageOffering;
064
065 /**
066 * Reader for Coverages stored in Oracle 10g GeoRaster format
067 *
068 *
069 * @version $Revision: 20437 $
070 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
071 * @author <a href="mailto:reichhelm@grit.de">Stephan Reichhelm</a>
072 * @author <a href="mailto:lipski@grit.de">Eryk Lipski</a>
073 * @author last edited by: $Author: apoth $
074 *
075 * @version 1.0. $Revision: 20437 $, $Date: 2009-10-29 09:49:03 +0100 (Do, 29. Okt 2009) $
076 *
077 * @since 2.0
078 */
079 public class OracleGeoRasterGridCoverageReader extends AbstractGridCoverageReader {
080
081 private static final ILogger LOG = LoggerFactory.getLogger( OracleGeoRasterGridCoverageReader.class );
082
083 /**
084 *
085 * @param jdbc
086 * description of the JDBC connection to a Orable DB
087 * @param table
088 * name of the table storing the GeoRaster
089 * @param column
090 * name of the column the target GeoRaster is stored
091 * @param identification
092 * a SQL where clause that identifies the target georaster
093 * @param description
094 * @param envelope
095 * @param format
096 */
097 public OracleGeoRasterGridCoverageReader( GeoRasterDescription grDesc,
098 CoverageOffering description, Envelope envelope,
099 Format format ) {
100 super( grDesc, description, envelope, format );
101 }
102
103 public void dispose()
104 throws IOException {
105
106 }
107
108 /**
109 * reads a GridCoverage from a Oracle 10g GeoRaster
110 *
111 * @param parameters -
112 */
113 public GridCoverage read( GeneralParameterValueIm[] parameters )
114 throws InvalidParameterNameException, InvalidParameterValueException,
115 ParameterNotFoundException, IOException {
116
117 float width = -1;
118 float height = -1;
119 for ( int i = 0; i < parameters.length; i++ ) {
120 OperationParameterIm op = (OperationParameterIm) parameters[i].getDescriptor();
121 String name = op.getName();
122 if ( name.equalsIgnoreCase( "WIDTH" ) ) {
123 Object o = op.getDefaultValue();
124 width = ( (Integer) o ).intValue();
125 } else if ( name.equalsIgnoreCase( "HEIGHT" ) ) {
126 Object o = op.getDefaultValue();
127 height = ( (Integer) o ).intValue();
128 }
129 }
130
131 /*
132 * creating an intersection is not needed, because the oracle raster exporter creates a new image in
133 * requested size.
134 */
135 Object[] o = getEnvelopes();
136
137 GeoRasterDescription grDesc = (GeoRasterDescription) getSource();
138
139 RenderedImage img = null;
140 try {
141 img = GeoRasterReader.exportRaster( grDesc, (Envelope) o[0], width, height );
142 } catch ( Exception e ) {
143 LOG.logError( "could not read GeoRaster: ", e );
144 throw new IOException( "could not read GeoRaster: " + e.getMessage() );
145 }
146
147 CoverageOffering co = (CoverageOffering) description.clone();
148 co.setLonLatEnvelope( (LonLatEnvelope) o[1] );
149
150 return new ImageGridCoverage( co, (Envelope) o[0], (BufferedImage) img );
151
152 }
153
154 /**
155 * returns the region in native and LonLatEnvelope of the request.
156 *
157 * @return returns the region in native and LonLatEnvelope of the request.
158 */
159 private Object[] getEnvelopes() {
160
161 CodeList[] cl = description.getSupportedCRSs().getNativeSRSs();
162 String code = cl[0].getCodes()[0];
163
164 LonLatEnvelope lonLatEnvelope = calcLonLatEnvelope( envelope, code );
165
166 return new Object[] { envelope, lonLatEnvelope };
167 }
168 }