001    /*----------------    FILE HEADER  ------------------------------------------
002    
003     This file is part of deegree.
004     Copyright (C) 2001-2007 by:
005     EXSE, Department of Geography, University of Bonn
006     http://www.giub.uni-bonn.de/deegree/
007     lat/lon GmbH
008     http://www.lat-lon.de
009    
010     This library is free software; you can redistribute it and/or
011     modify it under the terms of the GNU Lesser General Public
012     License as published by the Free Software Foundation; either
013     version 2.1 of the License, or (at your option) any later version.
014    
015     This library is distributed in the hope that it will be useful,
016     but WITHOUT ANY WARRANTY; without even the implied warranty of
017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
018     Lesser General Public License for more details.
019    
020     You should have received a copy of the GNU Lesser General Public
021     License along with this library; if not, write to the Free Software
022     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
023    
024     Contact:
025    
026     Andreas Poth
027     lat/lon GmbH
028     Aennchenstraße 19
029     53177 Bonn
030     Germany
031     E-Mail: poth@lat-lon.de
032    
033     Prof. Dr. Klaus Greve
034     Department of Geography
035     University of Bonn
036     Meckenheimer Allee 166
037     53115 Bonn
038     Germany
039     E-Mail: greve@giub.uni-bonn.de
040     
041     ---------------------------------------------------------------------------*/
042    package org.deegree.tools.app3d;
043    
044    import java.io.File;
045    import java.io.FileOutputStream;
046    import java.net.URL;
047    import java.util.HashMap;
048    import java.util.Properties;
049    
050    import org.deegree.framework.xml.XMLFragment;
051    import org.deegree.framework.xml.XSLTDocument;
052    
053    /**
054     * Utility program for converting a CityGML documents in KML.
055     * At the moment just Buildings are supported.
056     *
057     * @version $Revision: 1.2 $
058     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
059     * @author last edited by: $Author: poth $
060     *
061     * @version 1.0. $Revision: 1.2 $, $Date: 2007/01/23 19:42:39 $
062     *
063     * @since 2.0
064     */
065    public class CityGML2KML {
066        
067        private static URL xslt = CityGML2KML.class.getResource( "citygml2kml.xsl" );
068            
069        public static void main( String[] args ) throws Exception {
070            
071            Properties map = new Properties();
072            for ( int i = 0; i < args.length; i += 2 ) {
073                map.put( args[i], args[i + 1] );
074            }
075            
076            if ( map.getProperty( "-sourceFile" ) == null ) {
077                System.out.println( "parameter -sourceFile must be set" );
078                return;
079            }
080            if ( map.getProperty( "-outFile" ) == null ) {
081                System.out.println( "parameter -outFile must be set" );
082                return;
083            }
084            
085            HashMap<String,String> params = new HashMap<String,String>();
086            if ( map.get( "-sourceCRS" ) != null ) {
087                params.put( "SRCCRS", map.getProperty( "-sourceCRS" ) ); 
088            } else {
089                System.out.println( "use default source CRS (-sourceCRS EPSG:31467)" );
090            }
091            
092            XSLTDocument outXSLSheet = new XSLTDocument();
093            outXSLSheet.load( xslt );
094                    
095            XMLFragment doc = new XMLFragment(  );
096            doc.load( new File( map.getProperty( "-sourceFile" )  ).toURL() );
097                    
098            XMLFragment resultDocument = 
099                outXSLSheet.transform( doc, XMLFragment.DEFAULT_URL, null, params );
100                            
101            FileOutputStream fos = new FileOutputStream( map.getProperty( "-outFile" ) );
102            resultDocument.write( fos );
103            fos.close();
104        }
105        
106    }
107    
108    /*********************************************************************
109    Changes to this class. What the people have been up to:
110    $Log: CityGML2KML.java,v $
111    
112    ***********************************************************************/