001    //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/tags/2.1/src/org/deegree/model/crs/CoordinateSystem.java $
002    /*----------------    FILE HEADER  ------------------------------------------
003    
004     This file is part of deegree
005     Copyright (C) 2001-2006 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     Klaus Greve
035     Department of Geography
036     University of Bonn
037     Meckenheimer Allee 166
038     53115 Bonn
039     Germany
040     E-Mail: klaus.greve@giub.uni-bonn.de
041    
042     ---------------------------------------------------------------------------*/
043    package org.deegree.model.crs;
044    
045    // OpenGIS dependencies
046    import java.net.URI;
047    
048    import org.deegree.datatypes.QualifiedName;
049    import org.deegree.framework.util.StringTools;
050    import org.deegree.model.csct.cs.ConvenienceCSFactory;
051    import org.deegree.model.csct.cs.GeocentricCoordinateSystem;
052    import org.deegree.model.csct.cs.GeographicCoordinateSystem;
053    
054    /**
055     * A coordinate system is a mathematical space, where the elements of the space are called
056     * positions. Each position is described by a list of numbers. The length of the list corresponds to
057     * the dimension of the coordinate system. So in a 2D coordinate system each position is described
058     * by a list containing 2 numbers. <br>
059     * <br>
060     * However, in a coordinate system, not all lists of numbers correspond to a position - some lists
061     * may be outside the domain of the coordinate system. For example, in a 2D Lat/Lon coordinate
062     * system, the list (91,91) does not correspond to a position. <br>
063     * <br>
064     * Some coordinate systems also have a mapping from the mathematical space into locations in the
065     * real world. So in a Lat/Lon coordinate system, the mathematical position (lat, long) corresponds
066     * to a location on the surface of the Earth. This mapping from the mathematical space into
067     * real-world locations is called a Datum.
068     * 
069     * @version $Revision: 6259 $
070     * @author <a href="mailto:poth@lat-lon.de">Andreas Poth</a>
071     * @author last edited by: $Author: bezema $
072     * 
073     * @version 1.0. $Revision: 6259 $, $Date: 2007-03-20 10:15:15 +0100 (Di, 20 Mär 2007) $
074     * 
075     * @since 2.0
076     */
077    public class CoordinateSystem extends QualifiedName {
078    
079        /**
080         * 
081         */
082        private static final long serialVersionUID = -170831086069691683L;
083    
084        private String name = null;
085    
086        private String identifier = null;
087    
088        /**
089         * 
090         * @param prefix
091         *            must be not null
092         * @param localName
093         * @param namespace
094         */
095        CoordinateSystem( String prefix, String localName, URI namespace ) {
096            super( prefix.toLowerCase(), localName, namespace );
097        }
098    
099        /**
100         * 
101         * @param name
102         * @param namespace
103         */
104        CoordinateSystem( String name, URI namespace ) {
105            super( name, namespace );
106        }
107    
108        /**
109         * e.g. epgs:4326
110         * 
111         * @param name
112         */
113        protected CoordinateSystem( String name ) {
114            super( name );
115        }
116    
117        /**
118         * returns the name of the CRS with - if available - prefix seperated with ':' from the CRS code
119         * 
120         * @return the name of the CRS
121         */
122        public String getName() {
123            if ( name == null ) {
124                String prefix = getPrefix();
125                if ( prefix == null ) {
126                    prefix = "";
127                }
128                name = StringTools.concat( 50, prefix, ":", getLocalName() );
129            }
130            return name;
131        }
132    
133        /**
134         * in opposit to {@link #getName()} this method always returns the prefix of a CRS name in lower
135         * case characters. This method will be used to set CRS for transformation using proj4
136         * 
137         * @see #getName()
138         * @return the prefix of a CRS name in lower case characters
139         */
140        public String getIdentifier() {
141            if ( identifier == null ) {
142                String prefix = getPrefix();
143                if ( prefix == null ) {
144                    prefix = "";
145                }
146                identifier = StringTools.concat( 50, prefix.toLowerCase(), ":", getLocalName() );
147            }
148            return identifier;
149        }
150    
151        /**
152         * returns the CRSs code. In case of EPSG:4326 it will be 4326; in case of
153         * adv:DE_DHDN_3GK2_NW177 it will be DE_DHDN_3GK2_NW177
154         * 
155         * @return the CRSs code
156         */
157        public String getCode() {
158            return getLocalName();
159        }
160    
161        /**
162         * returns the CRS name as URN. e.g. urn:epsg:crs:4326 or urn:adv:crs:DE_DHDN_3GK2_NW177
163         * 
164         * @return the CRS name as URN
165         */
166        public String getAsURN() {
167            String prefix = getPrefix();
168            if ( prefix == null ) {
169                prefix = "";
170            }
171            return StringTools.concat( 100, "urn", prefix.toLowerCase(), "crs", getLocalName() );
172        }
173    
174        /**
175         * returns the units use by the CRS
176         * 
177         * @return the units use by the CRS
178         */
179        public String getUnits() {
180            // quuick and dirty hack
181            // TODO
182            org.deegree.model.csct.cs.CoordinateSystem cs = ConvenienceCSFactory.getInstance().getCSByName(
183                                                                                                            getName() );
184            if ( cs instanceof GeographicCoordinateSystem || cs instanceof GeocentricCoordinateSystem ) {
185                return "°";
186            }
187            //if not de(e)grees it must be meters
188            return "m";
189        }
190    
191        /**
192         * @return 2
193         */
194        public int getDimension() {
195            // TODO
196            // determine crs dimension
197            return 2;
198        }
199    }
200    
201    /***************************************************************************************************
202     * <code>
203     Changes to this class. What the people have been up to:
204     
205     $Log$
206     Revision 1.11  2007/03/05 10:18:39  bezema
207     added docu and removed some boxed conversions of char, also an unnecessary variable instantiation
208    
209     Revision 1.10  2007/02/02 08:18:37  wanhoff
210     fixed Javadoc @return tag, @see tag and footer
211     Revision
212     1.9 2006/11/29 09:39:04 poth
213     ** empty log message ***
214     
215     Revision 1.8 2006/11/27 09:07:51 poth 
216     JNI integration of proj4 has been removed. The CRS
217     functionality now will be done by native deegree code.
218     
219     Revision 1.7 2006/11/02 10:30:45 mschneider 
220     Removed #equals().
221     
222     Revision 1.6 2006/11/02 10:17:48 mschneider 
223     Fixed indentation. Implemented #equals(Object).
224     
225     Revision 1.5 2006/09/26 14:22:50 poth 
226     set constructor(String) to protected
227     
228     Revision 1.4 2006/05/16 06:47:15 poth 
229     getAsProjection method adapted to changed Projection
230     implementation
231     
232     </code>
233     **************************************************************************************************/