    001    //$HeadURL: https://svn.wald.intevation.org/svn/deegree/base/branches/2.4_testing/src/org/deegree/io/shpapi/SHPEnvelope.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 java.io.Serializable;
    041
    042    import org.deegree.model.spatialschema.ByteUtils;
    043
    044    /**
    045     * Class representing a rectangle - envelope.
    046     *
    047     * <P>
    048     * <B>Last changes<B>:<BR>
    049     * 07.01.2000 ap: all methods copied from Rectangle.java<BR>
    050     * 07.01.2000 ap: constructor renamed<BR>
    051     * 17.01.2000 ap: constructor SHPEnvelope(ESRIBoundingBox Ebb) removed<BR>
    052     * 17.01.2000 ap: constructor SHPEnvelope(SHPEnvelope env)implemented<BR>
    053     * 01.08.2000 ap: method writeSHPEnvelope() added<BR>
    054     *
    055     * <!---------------------------------------------------------------------------->
    056     *
    057     * @version 01.08.2000
    058     * @author Andreas Poth
    059     *
    060     */
    061
    062    public class SHPEnvelope implements Serializable {
    063
    064        private static final long serialVersionUID = 3984929126225855256L;
    065
    066        /**
    067         * this order:
    068         *
    069         * west, east, north, south
    070         */
    071
    072        // each double 8 byte distance, offset due to position in .shp-file-record
    073        public static final int recWest = 4;
    074
    075        /**
    076         *
    077         */
    078        public static final int recSouth = 12;
    079
    080        /**
    081         *
    082         */
    083        public static final int recEast = 20;
    084
    085        /**
    086         *
    087         */
    088        public static final int recNorth = 28;
    089
    090        // west bounding coordinate
    091        /**
    092         *
    093         */
    094        public double west;
    095
    096        // east bounding coordinate
    097        /**
    098         *
    099         */
    100        public double east;
    101
    102        // north bounding coordinate
    103        /**
    104         *
    105         */
    106        public double north;
    107
    108        // south bounding coordinate
    109        /**
    110         *
    111         */
    112        public double south;
    113
    114        // ------------- CONSTRUTOR IMPLEMENTATION BEGIN
    115        /**
    116         *
    117         */
    118        public SHPEnvelope() {
    119
    120            west = 0.0;
    121            east = 0.0;
    122            north = 0.0;
    123            south = 0.0;
    124
    125        }
    126
    127        /**
    128         * @param westbc
    129         * @param eastbc
    130         * @param northbc
    131         * @param southbc
    132         */
    133        public SHPEnvelope( double westbc, double eastbc, double northbc, double southbc ) {
    134
    135            this.west = westbc; // west bounding coordinate
    136            this.east = eastbc; // east bounding coordinate
    137            this.north = northbc; // north bounding coordinate
    138            this.south = southbc; // south bounding coordinate
    139
    140        }
    141
    142        /**
    143         * Transform from WKBPoint to Rectangle
    144         *
    145         * @param min
    146         * @param max
    147         */
    148        public SHPEnvelope( SHPPoint min, SHPPoint max ) {
    149
    150            // west bounding coordinate = minEsri.x
    151            this.west = min.x;
    152            // east bounding coordinate = maxEsri.x
    153            this.east = max.x;
    154            // north bounding coordinate = maxEsri.y
    155            this.north = max.y;
    156            // south bounding coordinate = minEsri.y
    157            this.south = min.y;
    158
    159        }
    160
    161        /**
    162         * create from an existing SHPEnvelope
    163         *
    164         * @param env
    165         */
    166        public SHPEnvelope( SHPEnvelope env ) {
    167
    168            // west bounding coordinate = Ebb.min.x
    169            this.west = env.west;
    170            // east bounding coordinate = Ebb.max.x
    171            this.east = env.east;
    172            // north bounding coordinate = Ebb.max.y
    173            this.north = env.north;
    174            // south bounding coordinate = Ebb.min.y
    175            this.south = env.south;
    176
    177        }
    178
    179        /**
    180         * @param recBuf
    181         */
    182        public SHPEnvelope( byte[] recBuf ) {
    183
    184            // west bounding coordinate = xmin of rec-Box
    185            this.west = ByteUtils.readLEDouble( recBuf, recWest );
    186            // east bounding coordinate = xmax of rec-Box
    187            this.east = ByteUtils.readLEDouble( recBuf, recEast );
    188            // north bounding coordinate = ymax of rec-Box
    189            this.north = ByteUtils.readLEDouble( recBuf, recNorth );
    190            // south bounding coordinate = ymin of rec-Box
    191            this.south = ByteUtils.readLEDouble( recBuf, recSouth );
    192
    193        }
    194
    195        /**
    196         * @return the new byte array
    197         */
    198        public byte[] writeLESHPEnvelope() {
    199            byte[] recBuf = new byte[8 * 4];
    200            // west bounding coordinate = xmin of rec-Box
    201            ByteUtils.writeLEDouble( recBuf, 0, west );
    202            // south bounding coordinate = ymin of rec-Box
    203            ByteUtils.writeLEDouble( recBuf, 8, south );
    204            // east bounding coordinate = xmax of rec-Box
    205            ByteUtils.writeLEDouble( recBuf, 16, east );
    206            // north bounding coordinate = ymax of rec-Box
    207            ByteUtils.writeLEDouble( recBuf, 24, north );
    208
    209            return recBuf;
    210        }
    211
    212        /**
    213         * @return the new byte array
    214         */
    215        public byte[] writeBESHPEnvelope() {
    216            byte[] recBuf = new byte[8 * 4];
    217            // west bounding coordinate = xmin of rec-Box
    218            ByteUtils.writeBEDouble( recBuf, 0, west );
    219            // south bounding coordinate = ymin of rec-Box
    220            ByteUtils.writeBEDouble( recBuf, 8, south );
    221            // east bounding coordinate = xmax of rec-Box
    222            ByteUtils.writeBEDouble( recBuf, 16, east );
    223            // north bounding coordinate = ymax of rec-Box
    224            ByteUtils.writeLEDouble( recBuf, 24, north );
    225
    226            return recBuf;
    227        }
    228
    229        // ----------------- METHOD IMPLEMENTATION
    230        @Override
    231        public String toString() {
    232
    233            return "RECTANGLE" + "\n[west: " + this.west + "]" + "\n[east: " + this.east + "]" + "\n[north: " + this.north
    234                   + "]" + "\n[south: " + this.south + "]";
    235
    236        }
    237
    238    }