001    //$HeadURL: svn+ssh://developername@svn.wald.intevation.org/deegree/base/trunk/resources/eclipse/files_template.xml $
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    
037    package org.deegree.ogcwebservices.wms.dataaccess;
038    
039    import java.awt.image.BufferedImage;
040    import java.io.IOException;
041    import java.io.InputStream;
042    import java.net.URL;
043    import java.util.Properties;
044    import java.util.UUID;
045    
046    import org.deegree.datatypes.QualifiedName;
047    import org.deegree.datatypes.Types;
048    import org.deegree.framework.util.IDGenerator;
049    import org.deegree.framework.util.StringTools;
050    import org.deegree.model.crs.CRSFactory;
051    import org.deegree.model.crs.CoordinateSystem;
052    import org.deegree.model.feature.FeatureCollection;
053    import org.deegree.model.feature.FeatureFactory;
054    import org.deegree.model.feature.FeatureProperty;
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.WKTAdapter;
059    import org.deegree.ogcwebservices.wfs.operation.FeatureResult;
060    import org.deegree.ogcwebservices.wms.dataaccess.ExternalVectorDataAccess;
061    import org.deegree.ogcwebservices.wms.operation.GetFeatureInfo;
062    import org.deegree.ogcwebservices.wms.operation.GetFeatureInfoResult;
063    import org.deegree.ogcwebservices.wms.operation.GetLegendGraphic;
064    import org.deegree.ogcwebservices.wms.operation.GetMap;
065    
066    /**
067     * expects configuration like:
068     * <pre>
069     * # name of the feature type that will be created (important for style definition)
070     * FeatureType={http://www.deegree.org/app}:WKTType
071     * # name of the vendor specific GetMap parameter that shall be evaluated
072     * WKT=WKT
073     * </pre>
074     *
075     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
076     *
077     * @author last edited by: $Author: Andreas Poth $
078     *
079     * @version $Revision: $, $Date: $
080     *
081     */
082    public class WKTMarker implements ExternalVectorDataAccess {
083    
084        private Properties props;
085    
086        private FeatureType ft;
087    
088        private BufferedImage legend = new BufferedImage( 10, 10, BufferedImage.TYPE_INT_RGB );
089    
090        /*
091         * (non-Javadoc)
092         *
093         * @see
094         * org.deegree.ogcwebservices.wms.dataaccess.ExternalVectorDataAccess#perform(org.deegree.ogcwebservices.wms.operation
095         * .GetMap)
096         */
097        public FeatureResult perform( GetMap getMap )
098                                throws Exception {
099            String wkt = getMap.getVendorSpecificParameter( props.getProperty( "WKT" ) );
100            FeatureCollection fc = FeatureFactory.createFeatureCollection( "UUID_" + UUID.randomUUID().toString(), 5 );
101            if ( wkt != null ) {
102                CoordinateSystem crs = CRSFactory.create( getMap.getSrs() );
103                String[] s = StringTools.toArray( wkt, ";", false );
104                for ( String string : s ) {
105                    Geometry geom = WKTAdapter.wrap( string, crs );
106                    FeatureProperty[] fp = new FeatureProperty[3];
107                    fp[0] = FeatureFactory.createFeatureProperty( ft.getPropertyName( 0 ),
108                                                                  (int) IDGenerator.getInstance().generateUniqueID() );
109                    fp[1] = FeatureFactory.createFeatureProperty( ft.getPropertyName( 1 ), wkt );
110                    fp[2] = FeatureFactory.createFeatureProperty( ft.getPropertyName( 2 ), geom );
111                    fc.add( FeatureFactory.createFeature( "UUID_" + UUID.randomUUID(), ft, fp ) );
112                }
113    
114            }
115            return new FeatureResult( getMap, fc );
116        }
117    
118        /*
119         * (non-Javadoc)
120         *
121         * @see
122         * org.deegree.ogcwebservices.wms.dataaccess.ExternalDataAccess#perform(org.deegree.ogcwebservices.wms.operation
123         * .GetFeatureInfo)
124         */
125        public GetFeatureInfoResult perform( GetFeatureInfo gfi ) {
126            return new GetFeatureInfoResult( gfi, "" );
127        }
128    
129        /*
130         * (non-Javadoc)
131         *
132         * @see
133         * org.deegree.ogcwebservices.wms.dataaccess.ExternalDataAccess#perform(org.deegree.ogcwebservices.wms.operation
134         * .GetLegendGraphic)
135         */
136        public BufferedImage perform( GetLegendGraphic glg ) {
137            return legend;
138        }
139    
140        /*
141         * (non-Javadoc)
142         *
143         * @see org.deegree.ogcwebservices.wms.dataaccess.ExternalDataAccess#setConfigurationFile(java.net.URL)
144         */
145        public void setConfigurationFile( URL url )
146                                throws IOException {
147            props = new Properties();
148            InputStream is = url.openStream();
149            props.load( is );
150            is.close();
151    
152            String ftName = props.getProperty( "FeatureType" );
153            QualifiedName qn = new QualifiedName( ftName );
154            PropertyType[] pt = new PropertyType[3];
155            pt[0] = FeatureFactory.createSimplePropertyType( new QualifiedName( "ID", qn.getNamespace() ), Types.INTEGER,
156                                                             false );
157            pt[1] = FeatureFactory.createSimplePropertyType( new QualifiedName( "WKT", qn.getNamespace() ), Types.VARCHAR,
158                                                             false );
159            pt[2] = FeatureFactory.createSimplePropertyType( new QualifiedName( "GEOM", qn.getNamespace() ),
160                                                             Types.GEOMETRY, false );
161            ft = FeatureFactory.createFeatureType( qn, false, pt );
162        }
163    }