001 //$HeadURL$
002 /*---------------- FILE HEADER ------------------------------------------
003 This file is part of deegree.
004 Copyright (C) 2001-2008 by:
005 Department of Geography, University of Bonn
006 http://www.giub.uni-bonn.de/deegree/
007 lat/lon GmbH
008 http://www.lat-lon.de
009
010 This library is free software; you can redistribute it and/or
011 modify it under the terms of the GNU Lesser General Public
012 License as published by the Free Software Foundation; either
013 version 2.1 of the License, or (at your option) any later version.
014 This library is distributed in the hope that it will be useful,
015 but WITHOUT ANY WARRANTY; without even the implied warranty of
016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
017 Lesser General Public License for more details.
018 You should have received a copy of the GNU Lesser General Public
019 License along with this library; if not, write to the Free Software
020 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021 Contact:
022
023 Andreas Poth
024 lat/lon GmbH
025 Aennchenstr. 19
026 53177 Bonn
027 Germany
028 E-Mail: poth@lat-lon.de
029
030 Prof. Dr. Klaus Greve
031 Department of Geography
032 University of Bonn
033 Meckenheimer Allee 166
034 53115 Bonn
035 Germany
036 E-Mail: greve@giub.uni-bonn.de
037 ---------------------------------------------------------------------------*/
038 package org.deegree.tools.raster;
039
040 import java.awt.image.BufferedImage;
041 import java.io.IOException;
042 import java.io.InputStream;
043 import java.sql.Connection;
044 import java.util.Properties;
045
046 import org.deegree.framework.util.FileUtils;
047 import org.deegree.framework.util.ImageUtils;
048 import org.deegree.io.DBConnectionPool;
049 import org.deegree.io.oraclegeoraster.GeoRasterReader;
050 import org.deegree.model.spatialschema.Envelope;
051 import org.deegree.model.spatialschema.GeometryFactory;
052
053 /**
054 * Utitliy program to export an image from Oracle 10g GeoRaster Database
055 *
056 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
057 * @author last edited by: $Author: poth $
058 *
059 * @version. $Revision: 6251 $, $Date: 2007-03-19 16:59:28 +0100 (Mo, 19 Mrz 2007) $
060 */
061 public class OracleGeoRasterExporter {
062
063 /**
064 * @param args
065 * @throws Exception
066 */
067 public static void main( String[] args )
068 throws Exception {
069 Properties map = new Properties();
070 for ( int i = 0; i < args.length; i += 2 ) {
071 if ( args[i].equals( "-h" ) || args[i].equals( "-?" ) ) {
072 printHelp();
073 System.exit( 0 );
074 }
075 map.put( args[i], args[i + 1] );
076 }
077 validate( map );
078
079 DBConnectionPool pool = DBConnectionPool.getInstance();
080
081 Connection con = pool.acquireConnection( map.getProperty( "-driver" ), map.getProperty( "-url" ),
082 map.getProperty( "-user" ), map.getProperty( "-password" ) );
083
084 try {
085 Envelope env = GeometryFactory.createEnvelope( map.getProperty( "-envelope" ), null );
086 int level = Integer.parseInt( map.getProperty( "-level" ) );
087 BufferedImage bi = (BufferedImage) GeoRasterReader.exportRaster( con,
088 env,
089 map.getProperty( "-rdtName" ).toUpperCase(),
090 map.getProperty( "-imageTableName" ).toUpperCase(),
091 map.getProperty( "-georColName" ).toUpperCase(),
092 map.getProperty( "-identification" ),
093 level );
094 ImageUtils.saveImage( bi, map.getProperty( "-outFile" ), 1 );
095 } catch ( Exception e ) {
096 throw e;
097 } finally {
098 con.close();
099 System.exit( 0 );
100 }
101
102 }
103
104 /**
105 * prints help text read from OracleGeoRasterExporterHelp.txt
106 * @throws IOException
107 */
108 private static void printHelp()
109 throws IOException {
110 InputStream is = OracleGeoRasterExporter.class.getResourceAsStream( "OracleGeoRasterExporterHelp.txt" );
111 String s = FileUtils.readTextFile( is ).toString();
112 System.out.println( s );
113 }
114
115 /**
116 * validates that all required parameters has been set
117 * @param map
118 * @return true if valid
119 */
120 private static boolean validate( Properties map ) {
121 if ( map.getProperty( "-driver" ) == null ) {
122 System.out.println( "-driver must be defined" );
123 return false;
124 }
125 if ( map.getProperty( "-url" ) == null ) {
126 System.out.println( "-url must be defined" );
127 return false;
128 }
129 if ( map.getProperty( "-user" ) == null ) {
130 map.put( "-user", "" );
131 }
132 if ( map.getProperty( "-password" ) == null ) {
133 map.put( "-password", "" );
134 }
135 if ( map.getProperty( "-rdtName" ) == null ) {
136 System.out.println( "-rdtName must be defined" );
137 return false;
138 }
139 if ( map.getProperty( "-imageTableName" ) == null ) {
140 System.out.println( "-imageTableName must be defined" );
141 return false;
142 }
143 if ( map.getProperty( "-georColName" ) == null ) {
144 System.out.println( "-georColName must be defined" );
145 return false;
146 }
147 if ( map.getProperty( "-envelope" ) == null ) {
148 System.out.println( "-envelope must be defined" );
149 return false;
150 }
151 if ( map.getProperty( "-level" ) == null ) {
152 System.out.println( "-level must be defined" );
153 return false;
154 }
155 if ( map.getProperty( "-outFile" ) == null ) {
156 System.out.println( "-outFile must be defined" );
157 return false;
158 }
159 if ( map.getProperty( "-identification" ) == null ) {
160 System.out.println( "-identification must be defined" );
161 return false;
162 }
163
164 return true;
165
166 }
167
168 }