001: /*
002: * The Unified Mapping Platform (JUMP) is an extensible, interactive GUI
003: * for visualizing and manipulating spatial features with geometry and attributes.
004: *
005: * Copyright (C) 2003 Vivid Solutions
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License
009: * as published by the Free Software Foundation; either version 2
010: * of the License, or (at your option) any later version.
011: *
012: * This program is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
015: * GNU General Public License for more details.
016: *
017: * You should have received a copy of the GNU General Public License
018: * along with this program; if not, write to the Free Software
019: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
020: *
021: * For more information, contact:
022: *
023: * Vivid Solutions
024: * Suite #1A
025: * 2328 Government Street
026: * Victoria BC V8T 5G5
027: * Canada
028: *
029: * (250)385-6040
030: * www.vividsolutions.com
031: */
032:
033: package com.vividsolutions.jump.io;
034:
035: import java.io.IOException;
036: import java.io.Writer;
037: import java.util.Iterator;
038:
039: import com.vividsolutions.jump.feature.Feature;
040: import com.vividsolutions.jump.feature.FeatureCollection;
041:
042: /**
043: * WKTWriter is a {@link JUMPWriter} specialized to write WTK (Well Known Text) files.
044: *
045: * <p>
046: * DataProperties for the JUMPWriter
047: * write(featureSchema,DataProperties) interface:<br>
048: * </p>
049: *
050: * <p>
051: * <table border='1' cellspacing='0' cellpadding='4'>
052: * <tr>
053: * <th>Parameter</th>
054: * <th>Meaning</th>
055: * </tr>
056: * <tr>
057: * <td>OutputFile or DefaultValue</td>
058: * <td>File name for output .wkt file</td>
059: * </tr>
060: * </table>
061: * <br>
062: * </p>
063: */
064: public class WKTWriter implements JUMPWriter {
065: private FUTURE_JTS_WKTWriter wktWriter = new FUTURE_JTS_WKTWriter();
066:
067: /**constuctor*/
068: public WKTWriter() {
069: }
070:
071: /**
072: * Main method - writes a list of wkt features (no attributes).
073: *
074: * @param featureCollection features to write
075: * @param dp 'OutputFile' or 'DefaultValue' to specify the output file.
076: */
077: public void write(FeatureCollection featureCollection,
078: DriverProperties dp) throws IllegalParametersException,
079: Exception {
080: String outputFname;
081:
082: outputFname = dp.getProperty("File");
083:
084: if (outputFname == null) {
085: outputFname = dp.getProperty("DefaultValue");
086: }
087:
088: if (outputFname == null) {
089: throw new IllegalParametersException(
090: "call to WKTWrite.write() has DataProperties w/o a OutputFile specified");
091: }
092:
093: java.io.Writer w;
094:
095: w = new java.io.FileWriter(outputFname);
096: this .write(featureCollection, w);
097: w.close();
098: }
099:
100: /**
101: * Function that actually does the writing
102: *@param featureCollection features to write
103: *@param writer where to write
104: */
105: public void write(FeatureCollection featureCollection, Writer writer)
106: throws IOException {
107: for (Iterator i = featureCollection.iterator(); i.hasNext();) {
108: Feature feature = (Feature) i.next();
109: wktWriter.writeFormatted(feature.getGeometry(), writer);
110:
111: if (i.hasNext()) {
112: writer.write("\n\n");
113: }
114: }
115: }
116: }
|