001    //$HeadURL: svn+ssh://jwilden@svn.wald.intevation.org/deegree/base/branches/2.5_testing/src/org/deegree/io/shpapi/SHPPoint.java $
002    
003    /*----------------------------------------------------------------------------
004     This file is part of deegree, http://deegree.org/
005     Copyright (C) 2001-2009 by:
006       Department of Geography, University of Bonn
007     and
008       lat/lon GmbH
009    
010     This library is free software; you can redistribute it and/or modify it under
011     the terms of the GNU Lesser General Public License as published by the Free
012     Software Foundation; either version 2.1 of the License, or (at your option)
013     any later version.
014     This library is distributed in the hope that it will be useful, but WITHOUT
015     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
016     FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
017     details.
018     You should have received a copy of the GNU Lesser General Public License
019     along with this library; if not, write to the Free Software Foundation, Inc.,
020     59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021    
022     Contact information:
023    
024     lat/lon GmbH
025     Aennchenstr. 19, 53177 Bonn
026     Germany
027     http://lat-lon.de/
028    
029     Department of Geography, University of Bonn
030     Prof. Dr. Klaus Greve
031     Postfach 1147, 53001 Bonn
032     Germany
033     http://www.geographie.uni-bonn.de/deegree/
034    
035     e-mail: info@deegree.org
036    ----------------------------------------------------------------------------*/
037    
038    package org.deegree.io.shpapi;
039    
040    import org.deegree.model.spatialschema.ByteUtils;
041    import org.deegree.model.spatialschema.Position;
042    
043    /**
044     * Class representig a two dimensional point<BR>
045     *
046     * @version 14.08.2000
047     * @author Andreas Poth
048     *
049     */
050    public class SHPPoint extends SHPGeometry {
051    
052        /**
053         *
054         */
055        public double x;
056    
057        /**
058         *
059         */
060        public double y;
061    
062        /**
063         *
064         */
065        public SHPPoint() {
066            // with zero values
067        }
068    
069        /**
070         * constructor: gets a stream and the start index <BR>
071         * of point on it <BR>
072         * @param recBuf
073         * @param xStart
074         */
075        public SHPPoint( byte[] recBuf, int xStart ) {
076    
077            super( recBuf );
078    
079            // get x out of recordbuffer
080            this.x = ByteUtils.readLEDouble( recBuffer, xStart );
081            // get y out of recordbuffer
082            this.y = ByteUtils.readLEDouble( recBuffer, xStart + 8 );
083    
084        }
085    
086        /**
087         * constructor: creates a SHPPoint from a WKS Geometrie<BR>
088         * @param point
089         */
090        public SHPPoint( Position point ) {
091            x = point.getX();
092            y = point.getY();
093        }
094    
095        /**
096         * method: writeSHPPoint: writes a SHPPoint Objekt to a recBuffer <BR>
097         * @param byteArray
098         * @param start
099         */
100        public void writeSHPPoint( byte[] byteArray, int start ) {
101    
102            int offset = start;
103    
104            // write shape type identifier ( 1 = point )
105            ByteUtils.writeLEInt( byteArray, offset, 1 );
106    
107            offset += 4;
108    
109            // write x into the recbuffer
110            ByteUtils.writeLEDouble( byteArray, offset, x );
111    
112            offset += 8;
113    
114            // write y into the recbuffer
115            ByteUtils.writeLEDouble( byteArray, offset, y );
116    
117        }
118    
119        /**
120         * returns the size of the point shape in bytes<BR>
121         * @return the size of the point shape in bytes<BR>
122         */
123        public int size() {
124            return 20;
125        }
126    
127        @Override
128        public String toString() {
129    
130            return "SHPPOINT" + "[" + this.x + "; " + this.y + "]";
131    
132        }
133    
134    }