001 //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/tools/raster/WorldFiles2GML.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.io.File; 039 import java.io.FileOutputStream; 040 import java.io.IOException; 041 import java.net.URI; 042 import java.net.URISyntaxException; 043 import java.util.List; 044 import java.util.Properties; 045 046 import org.deegree.datatypes.QualifiedName; 047 import org.deegree.datatypes.Types; 048 import org.deegree.framework.util.ConvenienceFileFilter; 049 import org.deegree.framework.util.StringTools; 050 import org.deegree.model.coverage.grid.WorldFile; 051 import org.deegree.model.feature.FeatureCollection; 052 import org.deegree.model.feature.FeatureFactory; 053 import org.deegree.model.feature.FeatureProperty; 054 import org.deegree.model.feature.GMLFeatureAdapter; 055 import org.deegree.model.feature.schema.FeatureType; 056 import org.deegree.model.feature.schema.PropertyType; 057 import org.deegree.model.spatialschema.Geometry; 058 import org.deegree.model.spatialschema.GeometryException; 059 import org.deegree.model.spatialschema.GeometryFactory; 060 import org.deegree.tools.shape.GML2Shape_new; 061 062 /** 063 * 064 * 065 * 066 * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a> 067 * @author last edited by: $Author: mschneider $ 068 * 069 * @version $Revision: 18195 $, $Date: 2009-06-18 17:55:39 +0200 (Do, 18 Jun 2009) $ 070 */ 071 public class WorldFiles2GML { 072 073 private File[] files; 074 075 private WorldFile.TYPE wft; 076 077 /** 078 * @param files 079 * @param wft 080 */ 081 public WorldFiles2GML( File[] files, WorldFile.TYPE wft ) { 082 this.files = files; 083 this.wft = wft; 084 } 085 086 private FeatureType createFeatureType() 087 throws URISyntaxException { 088 089 PropertyType[] ftps = new PropertyType[2]; 090 091 QualifiedName qn = new QualifiedName( "app", "name", new URI( "http://www.deegree.org/app" ) ); 092 ftps[0] = FeatureFactory.createSimplePropertyType( qn, Types.VARCHAR, true ); 093 094 qn = new QualifiedName( "app", "geom", new URI( "http://www.deegree.org/app" ) ); 095 ftps[1] = FeatureFactory.createSimplePropertyType( qn, Types.GEOMETRY, true ); 096 097 qn = new QualifiedName( "app", "WorldFiles", new URI( "http://www.deegree.org/app" ) ); 098 return FeatureFactory.createFeatureType( qn, false, ftps ); 099 } 100 101 /** 102 * @return a feature collection 103 * @throws IOException 104 * @throws GeometryException 105 * @throws URISyntaxException 106 */ 107 public FeatureCollection perform() 108 throws IOException, GeometryException, URISyntaxException { 109 FeatureType ft = createFeatureType(); 110 FeatureCollection fc = FeatureFactory.createFeatureCollection( "FC", 200 ); 111 for ( int i = 0; i < files.length; i++ ) { 112 WorldFile wf = WorldFile.readWorldFile( files[i].getAbsolutePath(), wft ); 113 Geometry geom = GeometryFactory.createSurface( wf.getEnvelope(), null ); 114 FeatureProperty[] fps = new FeatureProperty[2]; 115 116 QualifiedName qn = new QualifiedName( "app", "name", new URI( "http://www.deegree.org/app" ) ); 117 fps[0] = FeatureFactory.createFeatureProperty( qn, files[i].getAbsoluteFile() ); 118 qn = new QualifiedName( "app", "geom", new URI( "http://www.deegree.org/app" ) ); 119 fps[1] = FeatureFactory.createFeatureProperty( qn, geom ); 120 fc.add( FeatureFactory.createFeature( "id" + i, ft, fps ) ); 121 } 122 return fc; 123 } 124 125 /** 126 * @param args 127 * @throws Exception 128 */ 129 public static void main( String[] args ) 130 throws Exception { 131 132 Properties props = new Properties(); 133 for ( int i = 0; i < args.length; i += 2 ) { 134 props.put( args[i], args[i + 1] ); 135 } 136 137 WorldFile.TYPE wft = WorldFile.TYPE.CENTER; 138 if ( "outer".equals( props.get( "-type" ) ) ) { 139 wft = WorldFile.TYPE.OUTER; 140 } 141 System.out.println( wft ); 142 List<String> ext = StringTools.toList( props.getProperty( "-ext" ), ",", true ); 143 ConvenienceFileFilter ff = new ConvenienceFileFilter( ext, true ); 144 File dir = new File( props.getProperty( "-rootDir" ) ); 145 File[] files = dir.listFiles( ff ); 146 WorldFiles2GML wf2g = new WorldFiles2GML( files, wft ); 147 FeatureCollection fc = wf2g.perform(); 148 149 GMLFeatureAdapter ada = new GMLFeatureAdapter( true ); 150 FileOutputStream fos = new FileOutputStream( dir.getAbsolutePath() + "/gml.xml" ); 151 ada.export( fc, fos ); 152 fos.close(); 153 154 GML2Shape_new rws = new GML2Shape_new( dir.getAbsolutePath() + "/gml.xml", dir.getAbsolutePath() + "/gml" ); 155 rws.read(); 156 rws.write(); 157 158 System.out.println( "finished" ); 159 160 } 161 162 }