001: // $HeadURL: https://svn.wald.intevation.org/svn/deegree/base/trunk/src/org/deegree/tools/shape/Shape2GML_new.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: 53115 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: ---------------------------------------------------------------------------*/
044: package org.deegree.tools.shape;
045:
046: import java.io.FileOutputStream;
047: import java.io.IOException;
048:
049: import org.deegree.framework.log.ILogger;
050: import org.deegree.framework.log.LoggerFactory;
051: import org.deegree.io.dbaseapi.DBaseException;
052: import org.deegree.io.shpapi.shape_new.ShapeFile;
053: import org.deegree.io.shpapi.shape_new.ShapeFileReader;
054: import org.deegree.io.shpapi.shape_new.ShapeGeometryException;
055: import org.deegree.model.feature.FeatureCollection;
056: import org.deegree.model.feature.FeatureException;
057: import org.deegree.model.feature.GMLFeatureAdapter;
058:
059: /**
060: *
061: *
062: * @version $Revision: 9346 $
063: * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
064: * @author last edited by: $Author: apoth $
065: *
066: * @version 1.0. $Revision: 9346 $, $Date: 2007-12-27 08:39:07 -0800 (Thu, 27 Dec 2007) $
067: *
068: * @since 1.1
069: */
070: public class Shape2GML_new {
071:
072: private static final ILogger LOG = LoggerFactory
073: .getLogger(Shape2GML_new.class);
074:
075: private String inFile = null;
076:
077: private String outFile = null;
078:
079: /**
080: * Creates a new instance of Shape2GML
081: *
082: * @param inFile
083: * @param outFile
084: */
085: public Shape2GML_new(String inFile, String outFile) {
086: if (inFile.endsWith(".shp")) {
087: inFile = inFile.substring(0, inFile.lastIndexOf("."));
088: }
089: this .inFile = inFile;
090: this .outFile = outFile;
091: }
092:
093: private FeatureCollection read() throws IOException, DBaseException {
094:
095: LOG.logInfo("Reading " + inFile + " ... ");
096:
097: // open shape file
098: ShapeFileReader reader = new ShapeFileReader(inFile);
099: ShapeFile sf = reader.read();
100:
101: return sf.getFeatureCollection();
102: }
103:
104: private void write(FeatureCollection fc) throws IOException,
105: FeatureException {
106: LOG.logInfo("Writing " + outFile + " ... ");
107: FileOutputStream fos = new FileOutputStream(outFile);
108: new GMLFeatureAdapter().export(fc, fos);
109: fos.close();
110: }
111:
112: /**
113: * @param args
114: * the command line arguments
115: */
116: public static void main(String[] args) {
117:
118: try {
119: if (args == null || args.length < 2) {
120: System.out
121: .println("Usage: java -cp ... ...Shape2GML_new <inputfile basename> <outputfile>");
122: System.exit(1);
123: }
124:
125: Shape2GML_new s2g = new Shape2GML_new(args[0], args[1]);
126: s2g.write(s2g.read());
127: LOG.logInfo("Done.");
128: } catch (IOException e) {
129: e.printStackTrace();
130: LOG.logError("An IO error occured.", e);
131: } catch (FeatureException e) {
132: e.printStackTrace();
133: LOG.logError("Features could not be created.", e);
134: } catch (ShapeGeometryException e) {
135: e.printStackTrace();
136: LOG.logError(
137: "Some error occured while converting Geometries.",
138: e);
139: } catch (DBaseException e) {
140: e.printStackTrace();
141: LOG.logError("The .dbf could not be read.", e);
142: }
143: }
144:
145: }
|