001 //$HeadURL: svn+ssh://rbezema@svn.wald.intevation.org/deegree/base/branches/2.2_testing/src/org/deegree/io/shpapi/SHPEnvelope.java $
002
003 /*---------------- FILE HEADER ------------------------------------------
004
005 This file is part of deegree.
006 Copyright (C) 2001-2008 by:
007 EXSE, Department of Geography, University of Bonn
008 http://www.giub.uni-bonn.de/deegree/
009 lat/lon GmbH
010 http://www.lat-lon.de
011
012 This library is free software; you can redistribute it and/or
013 modify it under the terms of the GNU Lesser General Public
014 License as published by the Free Software Foundation; either
015 version 2.1 of the License, or (at your option) any later version.
016
017 This library is distributed in the hope that it will be useful,
018 but WITHOUT ANY WARRANTY; without even the implied warranty of
019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
020 Lesser General Public License for more details.
021
022 You should have received a copy of the GNU Lesser General Public
023 License along with this library; if not, write to the Free Software
024 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
025
026 Contact:
027
028 Andreas Poth
029 lat/lon GmbH
030 Aennchenstr. 19
031 53115 Bonn
032 Germany
033 E-Mail: poth@lat-lon.de
034
035 Prof. Dr. Klaus Greve
036 Department of Geography
037 University of Bonn
038 Meckenheimer Allee 166
039 53115 Bonn
040 Germany
041 E-Mail: greve@giub.uni-bonn.de
042
043
044 ---------------------------------------------------------------------------*/
045
046 package org.deegree.io.shpapi;
047
048
049 import java.io.Serializable;
050
051 import org.deegree.model.spatialschema.ByteUtils;
052
053 /**
054 * Class representing a rectangle - envelope.
055 *
056 * <P>
057 * <B>Last changes<B>:<BR>
058 * 07.01.2000 ap: all methods copied from Rectangle.java<BR>
059 * 07.01.2000 ap: constructor renamed<BR>
060 * 17.01.2000 ap: constructor SHPEnvelope(ESRIBoundingBox Ebb) removed<BR>
061 * 17.01.2000 ap: constructor SHPEnvelope(SHPEnvelope env)implemented<BR>
062 * 01.08.2000 ap: method writeSHPEnvelope() added<BR>
063 *
064 * <!---------------------------------------------------------------------------->
065 * @version 01.08.2000
066 * @author Andreas Poth
067 *
068 */
069
070
071
072 public class SHPEnvelope implements Serializable{
073
074 /**
075 * this order:
076 *
077 * west, east, north, south
078 */
079
080 // each double 8 byte distance, offset due to position in .shp-file-record
081 public static final int recWest= 4;
082 public static final int recSouth= 12;
083 public static final int recEast= 20;
084 public static final int recNorth= 28;
085
086
087 //west bounding coordinate
088 public double west;
089 //east bounding coordinate
090 public double east;
091 //north bounding coordinate
092 public double north;
093 //south bounding coordinate
094 public double south;
095
096
097 //------------- CONSTRUTOR IMPLEMENTATION BEGIN
098 public SHPEnvelope() {
099
100 west = 0.0;
101 east = 0.0;
102 north = 0.0;
103 south = 0.0;
104
105 }
106
107
108 public SHPEnvelope(double westbc, double eastbc, double northbc, double southbc) {
109
110 this.west= westbc; // west bounding coordinate
111 this.east= eastbc; // east bounding coordinate
112 this.north= northbc; // north bounding coordinate
113 this.south= southbc; // south bounding coordinate
114
115 }
116
117 /**
118 * Transform from WKBPoint to Rectangle
119 */
120 public SHPEnvelope(SHPPoint min, SHPPoint max) {
121
122 //west bounding coordinate = minEsri.x
123 this.west= min.x;
124 //east bounding coordinate = maxEsri.x
125 this.east= max.x;
126 //north bounding coordinate = maxEsri.y
127 this.north= max.y;
128 //south bounding coordinate = minEsri.y
129 this.south= min.y;
130
131 }
132
133 /**
134 * create from an existing SHPEnvelope
135 */
136 public SHPEnvelope(SHPEnvelope env) {
137
138 //west bounding coordinate = Ebb.min.x
139 this.west= env.west;
140 //east bounding coordinate = Ebb.max.x
141 this.east= env.east;
142 //north bounding coordinate = Ebb.max.y
143 this.north= env.north;
144 //south bounding coordinate = Ebb.min.y
145 this.south= env.south;
146
147 }
148
149
150 public SHPEnvelope(byte[] recBuf) {
151
152 //west bounding coordinate = xmin of rec-Box
153 this.west= ByteUtils.readLEDouble(recBuf, recWest);
154 //east bounding coordinate = xmax of rec-Box
155 this.east= ByteUtils.readLEDouble(recBuf, recEast);
156 //north bounding coordinate = ymax of rec-Box
157 this.north= ByteUtils.readLEDouble(recBuf, recNorth);
158 //south bounding coordinate = ymin of rec-Box
159 this.south= ByteUtils.readLEDouble(recBuf, recSouth);
160
161 }
162
163 public byte[] writeLESHPEnvelope() {
164 byte[] recBuf = new byte[8*4];
165 //west bounding coordinate = xmin of rec-Box
166 ByteUtils.writeLEDouble(recBuf, 0, west);
167 //south bounding coordinate = ymin of rec-Box
168 ByteUtils.writeLEDouble(recBuf, 8, south);
169 //east bounding coordinate = xmax of rec-Box
170 ByteUtils.writeLEDouble(recBuf, 16, east);
171 //north bounding coordinate = ymax of rec-Box
172 ByteUtils.writeLEDouble(recBuf, 24, north);
173
174 return recBuf;
175 }
176
177 public byte[] writeBESHPEnvelope() {
178 byte[] recBuf = new byte[8*4];
179 //west bounding coordinate = xmin of rec-Box
180 ByteUtils.writeBEDouble(recBuf, 0, west);
181 //south bounding coordinate = ymin of rec-Box
182 ByteUtils.writeBEDouble(recBuf, 8, south);
183 //east bounding coordinate = xmax of rec-Box
184 ByteUtils.writeBEDouble(recBuf, 16, east);
185 //north bounding coordinate = ymax of rec-Box
186 ByteUtils.writeLEDouble(recBuf, 24, north);
187
188 return recBuf;
189 }
190
191
192 //----------------- METHOD IMPLEMENTATION
193 public String toString() {
194
195 return "RECTANGLE" +
196 "\n[west: " + this.west + "]" +
197 "\n[east: " + this.east + "]" +
198 "\n[north: " + this.north + "]" +
199 "\n[south: " + this.south + "]" ;
200
201 }
202
203
204
205 }