001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/graphics/LazyRasterLayer.java $ 002 /*---------------- FILE HEADER ------------------------------------------ 003 004 This file is part of deegree. 005 Copyright (C) 2001-2006 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: bezema $ 080 * 081 * @version $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $ 082 */ 083 public class LazyRasterLayer extends AbstractLayer { 084 085 private ILogger LOG = LoggerFactory.getLogger( LazyRasterLayer.class ); 086 087 private Extension resource; 088 089 private CoverageOffering coverageOffering; 090 091 /** 092 * 093 * @param name 094 * @param coverageOffering 095 * @throws Exception 096 */ 097 public LazyRasterLayer( String name, CoverageOffering coverageOffering ) throws Exception { 098 super( name ); 099 this.coverageOffering = coverageOffering; 100 resource = coverageOffering.getExtension(); 101 } 102 103 /** 104 * 105 * @param name 106 * @param crs 107 * @param coverageOffering 108 * @throws Exception 109 */ 110 public LazyRasterLayer( String name, CoordinateSystem crs, CoverageOffering coverageOffering ) 111 throws Exception { 112 super( name, crs ); 113 this.coverageOffering = coverageOffering; 114 resource = coverageOffering.getExtension(); 115 } 116 117 /** 118 * @param crs 119 * @throws Exception 120 * 121 */ 122 public void setCoordinatesSystem( CoordinateSystem crs ) 123 throws Exception { 124 // not supported yet 125 } 126 127 128 129 /* (non-Javadoc) 130 * @see org.deegree.graphics.AbstractLayer#getBoundingBox() 131 */ 132 @Override 133 public Envelope getBoundingBox() { 134 return coverageOffering.getDomainSet().getSpatialDomain().getEnvelops()[0]; 135 } 136 137 /** 138 * 139 * @param envelope 140 * @param resolution 141 * @return 142 * @throws IOException 143 * @throws InvalidParameterValueException 144 */ 145 public GridCoverage getRaster( Envelope envelope, double resolution ) 146 throws InvalidParameterValueException, IOException { 147 148 Resolution[] resolutions = resource.getResolutions( resolution ); 149 150 String nativeCRS = coverageOffering.getSupportedCRSs().getNativeSRSs()[0].getCodes()[0]; 151 CoordinateSystem crs; 152 try { 153 crs = CRSFactory.create( nativeCRS ); 154 } catch ( UnknownCRSException e ) { 155 throw new InvalidParameterValueException( e ); 156 } 157 envelope = GeometryFactory.createEnvelope( envelope.getMin(), envelope.getMax(), crs ); 158 159 GridCoverageReader reader = null; 160 if ( resolutions[0] instanceof FileResolution ) { 161 reader = getFileReader( resolutions, envelope ); 162 } else if ( resolutions[0] instanceof ShapeResolution ) { 163 reader = getShapeReader( resolutions, envelope ); 164 } else if ( resolutions[0] instanceof DirectoryResolution ) { 165 reader = getDirectoryReader( resolutions, envelope ); 166 } else if ( resolutions[0] instanceof OracleGeoRasterResolution ) { 167 reader = getOracleGeoRasterReader( resolutions, envelope ); 168 } else { 169 throw new InvalidParameterValueException( "not supported coverage resolution: " + 170 resolutions[0].getClass().getName() ); 171 } 172 return reader.read( null ); 173 } 174 175 /** 176 * 177 * @param resolutions 178 * @param env 179 * @return 180 * @throws IOException 181 * @throws InvalidParameterValueException 182 */ 183 private GridCoverageReader getDirectoryReader( Resolution[] resolutions, Envelope env ) 184 throws IOException, InvalidParameterValueException { 185 186 LOG.logInfo( "reading coverage from directories" ); 187 188 Directory[] dirs = ( (DirectoryResolution) resolutions[0] ).getDirectories( env ); 189 190 GridCoverageExchange gce = new GridCoverageExchange( null ); 191 Format format = new Format( coverageOffering.getSupportedFormats().getNativeFormat() ); 192 193 return gce.getReader( dirs, coverageOffering, env, format ); 194 } 195 196 /** 197 * 198 * @param resolutions 199 * @param env 200 * @return 201 * @throws IOException 202 * @throws InvalidParameterValueException 203 */ 204 private GridCoverageReader getFileReader( Resolution[] resolutions, Envelope env ) 205 throws IOException, InvalidParameterValueException { 206 207 LOG.logInfo( "reading coverage from files" ); 208 209 File[] files = ( (FileResolution) resolutions[0] ).getFiles(); 210 List list = new ArrayList(); 211 for ( int i = 0; i < files.length; i++ ) { 212 Envelope fileEnv = files[i].getEnvelope(); 213 if ( fileEnv.intersects( env ) ) { 214 list.add( files[i] ); 215 } 216 } 217 files = (File[]) list.toArray( new File[list.size()] ); 218 219 GridCoverageExchange gce = new GridCoverageExchange( null ); 220 Format format = new Format( coverageOffering.getSupportedFormats().getNativeFormat() ); 221 222 return gce.getReader( files, coverageOffering, env, format ); 223 } 224 225 /** 226 * 227 * @param resolutions 228 * @param env 229 * @return 230 * @throws InvalidParameterValueException 231 * @throws IOException 232 */ 233 private GridCoverageReader getOracleGeoRasterReader( Resolution[] resolutions, Envelope env ) 234 throws InvalidParameterValueException, IOException { 235 236 LOG.logInfo( "reading coverage from oracle georaster" ); 237 238 JDBCConnection jdbc = ( (OracleGeoRasterResolution) resolutions[0] ).getJDBCConnection(); 239 String table = ( (OracleGeoRasterResolution) resolutions[0] ).getTable(); 240 String rdtTable = ( (OracleGeoRasterResolution) resolutions[0] ).getRdtTable(); 241 String column = ( (OracleGeoRasterResolution) resolutions[0] ).getColumn(); 242 String identification = ( (OracleGeoRasterResolution) resolutions[0] ).getIdentification(); 243 int level = ( (OracleGeoRasterResolution) resolutions[0] ).getLevel(); 244 GeoRasterDescription grd = new GeoRasterDescription( jdbc, table, rdtTable, column, 245 identification, level ); 246 247 GridCoverageExchange gce = new GridCoverageExchange( null ); 248 Format format = new Format( coverageOffering.getSupportedFormats().getNativeFormat() ); 249 250 return gce.getReader( grd, coverageOffering, env, format ); 251 252 } 253 254 /** 255 * 256 * @param resolutions 257 * @param env 258 * @return 259 * @throws IOException 260 * @throws InvalidParameterValueException 261 */ 262 private GridCoverageReader getShapeReader( Resolution[] resolutions, Envelope env ) 263 throws IOException, InvalidParameterValueException { 264 265 LOG.logInfo( "reading coverage from shapes" ); 266 267 Shape shape = ( (ShapeResolution) resolutions[0] ).getShape(); 268 269 GridCoverageExchange gce = new GridCoverageExchange( null ); 270 Format format = new Format( coverageOffering.getSupportedFormats().getNativeFormat() ); 271 return gce.getReader( shape, coverageOffering, env, format ); 272 273 } 274 275 } 276 277 /********************************************************************* 278 <code> 279 Changes to this class. What the people have been up to: 280 $Log$ 281 Revision 1.6 2007/03/06 11:22:15 wanhoff 282 Fixed Javadoc (@param) 283 284 Revision 1.5 2007/02/09 17:28:00 poth 285 *** empty log message *** 286 287 Revision 1.4 2006/11/27 09:07:52 poth 288 JNI integration of proj4 has been removed. The CRS functionality now will be done by native deegree code. 289 290 Revision 1.3 2006/05/31 17:53:33 poth 291 bug fix 292 293 Revision 1.2 2006/05/31 17:23:59 poth 294 first implementation of LazyRasterLayer 295 296 Revision 1.1 2006/05/24 08:05:03 poth 297 initial load up 298 </code> 299 300 ********************************************************************** */