001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/io/arcinfo_raster/ArcInfoTextRasterWriter.java $
002 /*---------------- FILE HEADER ------------------------------------------
003
004 This file is part of deegree.
005 Copyright (C) 2001-2008 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.io.arcinfo_raster;
044
045 import java.io.FileOutputStream;
046 import java.io.IOException;
047 import java.io.PrintWriter;
048
049 import org.deegree.model.coverage.grid.WorldFile;
050
051 /**
052 * writes a raster in ArcInfo text format:<br>
053 *
054 * <pre>
055 * ncols 1600
056 * nrows 1600
057 * xllcorner 3540000
058 * yllcorner 5730000
059 * cellsize 25
060 * NODATA_value -9999
061 * 120.4 132.5 99.9 ... 98.32
062 * 122.5 111.6 110.9 ... 88.77
063 * ...
064 * 234.23 233.4 265.9 ... 334.7
065 * </pre>
066 *
067 *
068 * @version $Revision: 9342 $
069 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
070 * @author last edited by: $Author: apoth $
071 *
072 * @version 1.0. $Revision: 9342 $, $Date: 2007-12-27 13:32:57 +0100 (Do, 27 Dez 2007) $
073 *
074 * @since 2.0
075 */
076 public class ArcInfoTextRasterWriter {
077
078 private String outFile;
079
080 private float[][] data;
081
082 private WorldFile wf;
083
084 private double noData = -9999;
085
086 /**
087 * it will be assumed that -9999 indicates noData values
088 *
089 * @param outFile
090 * name of the output file
091 * @param data
092 * data to write
093 * @param wf
094 * metadata describing spatial location and resolution
095 */
096 public ArcInfoTextRasterWriter( String outFile, float[][] data, WorldFile wf ) {
097 this( outFile, data, wf, -9999 );
098 }
099
100 /**
101 *
102 * @param outFile
103 * name of the output file
104 * @param data
105 * data to write
106 * @param wf
107 * metadata describing spatial location and resolution
108 * @param noData
109 * value used for marking noData values
110 */
111 public ArcInfoTextRasterWriter( String outFile, float[][] data, WorldFile wf, double noData ) {
112 this.outFile = outFile;
113 this.data = data;
114 this.wf = wf;
115 this.noData = noData;
116 }
117
118 /**
119 * writes data to file
120 *
121 * @throws IOException
122 */
123 public void write()
124 throws IOException {
125 PrintWriter pw = new PrintWriter( new FileOutputStream( outFile ) );
126 pw.println( "ncols " + data[0].length );
127 pw.println( "nrows " + data.length );
128 pw.println( "xllcorner " + wf.getEnvelope().getMin().getX() );
129 pw.println( "yllcorner " + wf.getEnvelope().getMin().getY() );
130 pw.println( "cellsize " + wf.getResx() );
131 pw.println( "nodata_value " + noData );
132 for ( int i = 0; i < data.length; i++ ) {
133 for ( int j = 0; j < data[i].length; j++ ) {
134 pw.print( data[i][j] );
135 pw.print( ' ' );
136 }
137 pw.println();
138 }
139 pw.close();
140 }
141
142 }