001package org.kepler.module.gis;
002/*
003 * Copyright (c) 2015 The Regents of the University of California.
004 * All rights reserved.
005 *
006 * '$Author: crawl $'
007 * '$Date: 2016-04-21 05:37:35 +0000 (Thu, 21 Apr 2016) $' 
008 * '$Revision: 34474 $'
009 * 
010 * Permission is hereby granted, without written agreement and without
011 * license or royalty fees, to use, copy, modify, and distribute this
012 * software and its documentation for any purpose, provided that the above
013 * copyright notice and the following two paragraphs appear in all copies
014 * of this software.
015 *
016 * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY
017 * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
018 * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
019 * THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF
020 * SUCH DAMAGE.
021 *
022 * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
023 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
024 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
025 * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
026 * CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
027 * ENHANCEMENTS, OR MODIFICATIONS.
028 *
029 */
030import java.io.File;
031
032import org.geotools.referencing.factory.epsg.HsqlEpsgDatabase;
033import org.geotools.referencing.factory.epsg.ThreadedHsqlEpsgFactory;
034import org.kepler.gis.data.BoundingBoxToken;
035import org.kepler.gis.data.GISToken;
036import org.kepler.gis.data.RasterToken;
037import org.kepler.gis.data.VectorToken;
038import org.kepler.module.ModuleInitializer;
039import org.kepler.moml.filter.GISClassChanges;
040import org.kepler.moml.filter.GISPropertyClassChanges;
041import org.kepler.util.DotKeplerManager;
042
043import ptolemy.data.expr.PtParser;
044import ptolemy.data.type.BaseType;
045import ptolemy.data.type.TypeLattice;
046import ptolemy.graph.DirectedAcyclicGraph;
047
048/**
049 * Perform initialization for the gis module.
050 * 
051 * @author Daniel Crawl
052 * @version $Id: Initialize.java 34474 2016-04-21 05:37:35Z crawl $
053 * 
054 */
055public class Initialize implements ModuleInitializer {
056        
057        /** Perform any module-specific initializations. */
058        @Override
059    public void initializeModule() {
060        
061        }
062        
063        /** The following is in a static block so that it is
064         *  performed only once instead of each time the modules
065         *  are initialized.
066         */
067        static {
068            
069        // set the directory to write the EPSG HSQL database.
070        // the default location is in /tmp, which means the directory may
071        // already be created by another user, but not writable. if the
072        // database version is different between users and the directory
073        // is not writable, then the database files cannot be written and
074        // decoding CRSs results in exceptions.
075        File dir = DotKeplerManager.getInstance().getTransientModuleDirectory("gis");
076        
077        // set both databases; which one is used? are there others?
078        System.setProperty(HsqlEpsgDatabase.DIRECTORY_KEY, dir.getAbsolutePath());
079        System.setProperty(ThreadedHsqlEpsgFactory.DIRECTORY_KEY, dir.getAbsolutePath()); 
080        
081        
082        //Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
083        //System.setProperty("org.geotools.referencing.forceXY", "true");
084
085        // add the GIS types to the Type Lattice
086        DirectedAcyclicGraph lattice = (DirectedAcyclicGraph) TypeLattice.basicLattice();
087        lattice.addNodeWeight(GISToken.GIS);
088        lattice.addNodeWeight(VectorToken.VECTOR);
089        lattice.addNodeWeight(RasterToken.RASTER);
090        lattice.addNodeWeight(BoundingBoxToken.BOUNDING_BOX);
091        
092        // Vector and Raster types are both GIS types
093        lattice.addEdge(BaseType.UNKNOWN, VectorToken.VECTOR);
094        lattice.addEdge(BaseType.UNKNOWN, RasterToken.RASTER);
095        lattice.addEdge(BaseType.UNKNOWN, BoundingBoxToken.BOUNDING_BOX);
096        lattice.addEdge(VectorToken.VECTOR, GISToken.GIS);
097        lattice.addEdge(RasterToken.RASTER, GISToken.GIS);
098        lattice.addEdge(BoundingBoxToken.BOUNDING_BOX, GISToken.GIS);
099        
100        // register the bounding box token so that the expression language
101        // can parse bbox().
102        PtParser.registerFunctionClass("org.kepler.gis.data.BoundingBoxToken");
103
104        // handle class name changes.
105        GISClassChanges.initialize();
106        GISPropertyClassChanges.initialize();
107
108        }
109}