001    /*----------------    FILE HEADER  ------------------------------------------
002    
003     This file is part of deegree.
004     Copyright (C) 2001-2008 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. At the moment just Buildings are
055     * 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 )
070                                throws Exception {
071    
072            Properties map = new Properties();
073            for ( int i = 0; i < args.length; i += 2 ) {
074                map.put( args[i], args[i + 1] );
075            }
076    
077            if ( map.getProperty( "-sourceFile" ) == null ) {
078                System.out.println( "parameter -sourceFile must be set" );
079                return;
080            }
081            if ( map.getProperty( "-outFile" ) == null ) {
082                System.out.println( "parameter -outFile must be set" );
083                return;
084            }
085    
086            HashMap<String, String> params = new HashMap<String, String>();
087            if ( map.get( "-sourceCRS" ) != null ) {
088                params.put( "SRCCRS", map.getProperty( "-sourceCRS" ) );
089            } else {
090                System.out.println( "use default source CRS (-sourceCRS EPSG:31467)" );
091            }
092    
093            XSLTDocument outXSLSheet = new XSLTDocument();
094            outXSLSheet.load( xslt );
095    
096            XMLFragment doc = new XMLFragment();
097            doc.load( new File( map.getProperty( "-sourceFile" ) ).toURL() );
098    
099            XMLFragment resultDocument = 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    }