001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/tools/raster/WorldFiles2GML.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree.
005     Copyright (C) 2001-2007 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.tools.raster;
044    
045    import java.io.File;
046    import java.io.IOException;
047    import java.net.URI;
048    import java.net.URISyntaxException;
049    import java.util.List;
050    import java.util.Properties;
051    
052    import org.deegree.datatypes.QualifiedName;
053    import org.deegree.datatypes.Types;
054    import org.deegree.framework.util.ConvenienceFileFilter;
055    import org.deegree.framework.util.StringTools;
056    import org.deegree.model.coverage.grid.WorldFile;
057    import org.deegree.model.feature.FeatureCollection;
058    import org.deegree.model.feature.FeatureFactory;
059    import org.deegree.model.feature.FeatureProperty;
060    import org.deegree.model.feature.GMLFeatureAdapter;
061    import org.deegree.model.feature.schema.FeatureType;
062    import org.deegree.model.feature.schema.PropertyType;
063    import org.deegree.model.spatialschema.Geometry;
064    import org.deegree.model.spatialschema.GeometryException;
065    import org.deegree.model.spatialschema.GeometryFactory;
066    
067    /**
068     * 
069     * 
070     *
071     * @version $Revision: 6259 $
072     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
073     * @author last edited by: $Author: bezema $
074     *
075     * @version 1.0. $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $
076     *
077     * @since 2.0
078     */
079    public class WorldFiles2GML {
080        
081        private File[] files;
082        private WorldFile.TYPE wft;
083        
084        public WorldFiles2GML(File[] files, WorldFile.TYPE wft) {
085            this.files = files;
086            this.wft = wft;
087        }
088        
089        private FeatureType createFeatureType() throws URISyntaxException {
090            
091            PropertyType[] ftps = new PropertyType[2];
092            
093            QualifiedName qn = new QualifiedName( "app", "name", new URI( "http://www.deegree.org/app" ) );
094            ftps[0] = FeatureFactory.createSimplePropertyType( qn , Types.VARCHAR, true );
095            
096            qn = new QualifiedName( "app", "geom", new URI( "http://www.deegree.org/app" ) );
097            ftps[1] = FeatureFactory.createSimplePropertyType( qn , Types.GEOMETRY, true );
098            
099            qn = new QualifiedName( "app", "WorldFiles", new URI( "http://www.deegree.org/app" ) );
100            return FeatureFactory.createFeatureType( qn, false, ftps );
101        }
102        
103        public FeatureCollection perform() throws IOException, GeometryException, URISyntaxException {
104            FeatureType ft = createFeatureType();
105            FeatureCollection fc = FeatureFactory.createFeatureCollection( "FC", 200 );
106            for ( int i = 0; i < files.length; i++ ) {
107                WorldFile wf = WorldFile.readWorldFile( files[i].getAbsolutePath(), wft );
108                Geometry geom = GeometryFactory.createSurface( wf.getEnvelope(), null );
109                FeatureProperty[] fps = new FeatureProperty[2];
110                
111                QualifiedName qn = new QualifiedName( "app", "name", new URI( "http://www.deegree.org/app" ) );
112                fps[0] = FeatureFactory.createFeatureProperty( qn, files[i].getAbsoluteFile() );
113                qn = new QualifiedName( "app", "geom", new URI( "http://www.deegree.org/app" ) );
114                fps[1] = FeatureFactory.createFeatureProperty( qn, geom );
115                fc.add( FeatureFactory.createFeature( "id"+i, ft, fps ) );
116            }
117            return fc;
118        }
119    
120        /**
121         * @param args
122         */
123        public static void main( String[] args ) throws Exception {
124            
125            Properties props = new Properties();
126            for ( int i = 0; i < args.length; i += 2 ) {
127                props.put( args[i], args[i + 1] );
128            }
129    
130            WorldFile.TYPE wft = WorldFile.TYPE.CENTER;
131            if ( "outer".equals(  props.get( "-type") ) ) {
132                wft = WorldFile.TYPE.OUTER; 
133            }
134            System.out.println( wft );
135            List<String> ext = StringTools.toList( props.getProperty( "-ext" ), ",", true ); 
136            ConvenienceFileFilter ff = new ConvenienceFileFilter( ext, true );
137            File dir = new File( props.getProperty( "-rootDir" ) );
138            File[] files = dir.listFiles( ff );
139            WorldFiles2GML wf2g = new WorldFiles2GML( files, wft );
140            FeatureCollection fc = wf2g.perform();
141            
142            GMLFeatureAdapter ada = new GMLFeatureAdapter( true );
143            ada.export( fc, System.out );
144    
145        }
146    
147    }
148    
149    /*********************************************************************
150    <code>
151    Changes to this class. What the people have been up to:
152    $Log$
153    Revision 1.1  2007/03/15 21:19:42  poth
154    *** empty log message ***
155    
156    </code>
157    ********************************************************************** */