001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/tools/raster/ArcInfo2Tiff.java $ 002 /*---------------------------------------------------------------------------- 003 This file is part of deegree, http://deegree.org/ 004 Copyright (C) 2001-2009 by: 005 Department of Geography, University of Bonn 006 and 007 lat/lon GmbH 008 009 This library is free software; you can redistribute it and/or modify it under 010 the terms of the GNU Lesser General Public License as published by the Free 011 Software Foundation; either version 2.1 of the License, or (at your option) 012 any later version. 013 This library is distributed in the hope that it will be useful, but WITHOUT 014 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 015 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more 016 details. 017 You should have received a copy of the GNU Lesser General Public License 018 along with this library; if not, write to the Free Software Foundation, Inc., 019 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 020 021 Contact information: 022 023 lat/lon GmbH 024 Aennchenstr. 19, 53177 Bonn 025 Germany 026 http://lat-lon.de/ 027 028 Department of Geography, University of Bonn 029 Prof. Dr. Klaus Greve 030 Postfach 1147, 53001 Bonn 031 Germany 032 http://www.geographie.uni-bonn.de/deegree/ 033 034 e-mail: info@deegree.org 035 ----------------------------------------------------------------------------*/ 036 package org.deegree.tools.raster; 037 038 import java.awt.image.BufferedImage; 039 import java.io.File; 040 import java.util.Properties; 041 042 import org.deegree.framework.util.ImageUtils; 043 import org.deegree.io.arcinfo_raster.ArcInfoTextRasterReader; 044 import org.deegree.model.coverage.grid.WorldFile; 045 import org.deegree.processing.raster.converter.RawData2Image; 046 047 /** 048 * converts an ArcInfor raster file (text format): 049 * 050 * <pre> 051 * ncols 2404 052 * nrows 2307 053 * xllcorner 2627130 054 * yllcorner 5686612 055 * cellsize 10 056 * NODATA_value -9999 057 * 20636 20593 20569 20573 20571 20564 20564 20558 ... 058 * ... 059 * </pre> 060 * 061 * into a Tiff image that may have 16 or 32 bit pixel depth 062 * 063 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 064 * @author last edited by: $Author: aschmitz $ 065 * 066 * @version $Revision: 22547 $, $Date: 2010-02-16 10:22:39 +0100 (Di, 16 Feb 2010) $ 067 */ 068 public class ArcInfo2Tiff { 069 070 /** 071 * @param args 072 * @throws Exception 073 */ 074 public static void main( String[] args ) 075 throws Exception { 076 077 Properties map = new Properties(); 078 for ( int i = 0; i < args.length; i += 2 ) { 079 map.put( args[i], args[i + 1] ); 080 } 081 File arcInfo = new File( map.getProperty( "-inFile" ) ); 082 String o = map.getProperty( "-outFile" ); 083 if ( !o.toLowerCase().endsWith( ".tiff" ) && !o.toLowerCase().endsWith( ".tif" ) ) { 084 throw new Exception( "output image format must be tiff or tiff" ); 085 } 086 File out = new File( o ); 087 088 String depth = map.getProperty( "-type" ); 089 090 boolean outer = map.getProperty( "-refType" ) == null || map.getProperty( "-refType" ).equalsIgnoreCase( "outer" ); 091 092 ArcInfoTextRasterReader reader = new ArcInfoTextRasterReader( arcInfo ); 093 WorldFile wf = reader.readMetadata( !outer ); 094 o = o.substring( 0, o.lastIndexOf( '.' ) ); 095 WorldFile.writeWorldFile( wf, o ); 096 float[][] data = reader.readData(); 097 BufferedImage bi = RawData2Image.rawData2Image( data, "32".equals( depth ) ); 098 099 ImageUtils.saveImage( bi, out, 1 ); 100 } 101 102 }