    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_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: 21672 $
    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: 21672 $, $Date: 2009-12-29 09:44:20 +0100 (Di, 29. Dez 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 grDesc
    086         * @param description
    087         * @param envelope
    088         * @param format
    089         */
    090        public OracleGeoRasterGridCoverageReader( GeoRasterDescription grDesc, CoverageOffering description,
    091                                                  Envelope envelope, Format format ) {
    092            super( grDesc, description, envelope, format );
    093        }
    094
    095        /**
    096         *
    097         */
    098        public void dispose()
    099                                throws IOException {
    100
    101        }
    102
    103        /**
    104         * reads a GridCoverage from a Oracle 10g GeoRaster
    105         *
    106         * @param parameters
    107         *            -
    108         */
    109        public GridCoverage read( GeneralParameterValueIm[] parameters )
    110                                throws InvalidParameterNameException, InvalidParameterValueException,
    111                                ParameterNotFoundException, IOException {
    112
    113            float width = -1;
    114            float height = -1;
    115            for ( int i = 0; i < parameters.length; i++ ) {
    116                OperationParameterIm op = (OperationParameterIm) parameters[i].getDescriptor();
    117                String name = op.getName();
    118                if ( name.equalsIgnoreCase( "WIDTH" ) ) {
    119                    Object o = op.getDefaultValue();
    120                    width = ( (Integer) o ).intValue();
    121                } else if ( name.equalsIgnoreCase( "HEIGHT" ) ) {
    122                    Object o = op.getDefaultValue();
    123                    height = ( (Integer) o ).intValue();
    124                }
    125            }
    126
    127            /*
    128             * creating an intersection is not needed, because the oracle raster exporter creates a new image in requested
    129             * size.
    130             */
    131            Object[] o = getEnvelopes();
    132
    133            GeoRasterDescription grDesc = (GeoRasterDescription) getSource();
    134
    135            RenderedImage img = null;
    136            try {
    137                img = GeoRasterReader.exportRaster( grDesc, (Envelope) o[0], width, height );
    138            } catch ( Exception e ) {
    139                LOG.logError( "could not read GeoRaster: ", e );
    140                throw new IOException( "could not read GeoRaster: " + e.getMessage() );
    141            }
    142
    143            CoverageOffering co = (CoverageOffering) description.clone();
    144            co.setLonLatEnvelope( (LonLatEnvelope) o[1] );
    145
    146            return new ImageGridCoverage( co, (Envelope) o[0], (BufferedImage) img );
    147
    148        }
    149
    150        /**
    151         * returns the region in native and LonLatEnvelope of the request.
    152         *
    153         * @return returns the region in native and LonLatEnvelope of the request.
    154         */
    155        private Object[] getEnvelopes() {
    156
    157            CodeList[] cl = description.getSupportedCRSs().getNativeSRSs();
    158            String code = cl[0].getCodes()[0];
    159
    160            LonLatEnvelope lonLatEnvelope = calcLonLatEnvelope( envelope, code );
    161
    162            return new Object[] { envelope, lonLatEnvelope };
    163        }
    164    }