svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / utils / BoundaryBox.java @ 40559
History | View | Annotate | Download (5.1 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.remoteclient.utils; |
26 |
|
27 |
/**
|
28 |
* <p></p>
|
29 |
*
|
30 |
*/
|
31 |
public class BoundaryBox { |
32 |
|
33 |
/**
|
34 |
* <p>Represents ...</p>
|
35 |
*
|
36 |
*/
|
37 |
private double xmin; |
38 |
|
39 |
/**
|
40 |
* <p>Represents ...</p>
|
41 |
*
|
42 |
*/
|
43 |
private double xmax; |
44 |
|
45 |
/**
|
46 |
* <p>Represents ...</p>
|
47 |
*
|
48 |
*/
|
49 |
private double ymin; |
50 |
|
51 |
/**
|
52 |
* <p>Represents ...</p>
|
53 |
*
|
54 |
*/
|
55 |
private double ymax; |
56 |
|
57 |
/**
|
58 |
* <p>Represents ...</p>
|
59 |
*
|
60 |
*/
|
61 |
private String srs; |
62 |
|
63 |
/**
|
64 |
* <p>Represents ...</p>
|
65 |
*
|
66 |
*
|
67 |
* @return
|
68 |
*/
|
69 |
public double getXmin() { |
70 |
return xmin;
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* <p>Represents ...</p>
|
75 |
*
|
76 |
*
|
77 |
* @param _xmin
|
78 |
*/
|
79 |
public void setXmin(double _xmin) { |
80 |
xmin = _xmin; |
81 |
} |
82 |
|
83 |
/**
|
84 |
* <p>Represents ...</p>
|
85 |
*
|
86 |
*
|
87 |
* @return
|
88 |
*/
|
89 |
public double getXmax() { |
90 |
return xmax;
|
91 |
} |
92 |
|
93 |
/**
|
94 |
* <p>Represents ...</p>
|
95 |
*
|
96 |
*
|
97 |
* @param _xmax
|
98 |
*/
|
99 |
public void setXmax(double _xmax) { |
100 |
xmax = _xmax; |
101 |
} |
102 |
|
103 |
/**
|
104 |
* <p>Represents ...</p>
|
105 |
*
|
106 |
*
|
107 |
* @return
|
108 |
*/
|
109 |
public double getYmin() { |
110 |
return ymin;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* <p>Represents ...</p>
|
115 |
*
|
116 |
*
|
117 |
* @param _ymin
|
118 |
*/
|
119 |
public void setYmin(double _ymin) { |
120 |
ymin = _ymin; |
121 |
} |
122 |
|
123 |
/**
|
124 |
* <p>Represents ...</p>
|
125 |
*
|
126 |
*
|
127 |
* @return
|
128 |
*/
|
129 |
public double getYmax() { |
130 |
return ymax;
|
131 |
} |
132 |
|
133 |
/**
|
134 |
* <p>Represents ...</p>
|
135 |
*
|
136 |
*
|
137 |
* @param _ymax
|
138 |
*/
|
139 |
public void setYmax(double _ymax) { |
140 |
ymax = _ymax; |
141 |
} |
142 |
|
143 |
/**
|
144 |
* <p>Represents ...</p>
|
145 |
*
|
146 |
*
|
147 |
* @return
|
148 |
*/
|
149 |
public String getSrs() { |
150 |
return srs;
|
151 |
} |
152 |
|
153 |
/**
|
154 |
* <p>Represents ...</p>
|
155 |
*
|
156 |
*
|
157 |
* @param _srs
|
158 |
*/
|
159 |
public void setSrs(String _srs) { |
160 |
srs = _srs; |
161 |
} |
162 |
|
163 |
public String toString(){ |
164 |
String s = srs + " (" + xmin + ", " + ymin + ", " + xmax + ", " + ymax + ")"; |
165 |
|
166 |
return s;
|
167 |
} |
168 |
|
169 |
public static boolean validLat(double v) { |
170 |
return v >= -90 && v <= 90; |
171 |
} |
172 |
|
173 |
public static boolean validLon(double v) { |
174 |
return v >= -180 && v <= 180; |
175 |
} |
176 |
|
177 |
public static BoundaryBox clipGeodeticBBox(BoundaryBox bbox) { |
178 |
|
179 |
BoundaryBox resp = new BoundaryBox();
|
180 |
resp.setSrs(bbox.getSrs()); |
181 |
resp.setXmin(bbox.getXmin()); |
182 |
resp.setXmax(bbox.getXmax()); |
183 |
resp.setYmin(bbox.getYmin()); |
184 |
resp.setYmax(bbox.getYmax()); |
185 |
|
186 |
// ==================================================
|
187 |
// Fix longitude
|
188 |
// ==================================================
|
189 |
if (resp.getXmax() > resp.getXmin()
|
190 |
&& validLon(resp.getXmin()) && !validLon(resp.getXmax())) { |
191 |
// only xmax is wrong:
|
192 |
resp.setXmax(180);
|
193 |
} else {
|
194 |
if (resp.getXmax() > resp.getXmin()
|
195 |
&& !validLon(resp.getXmin()) && validLon(resp.getXmax())) { |
196 |
// only xmin is wrong:
|
197 |
resp.setXmin(-180);
|
198 |
} else {
|
199 |
if (resp.getXmax() > resp.getXmin()
|
200 |
&& validLon(resp.getXmin()) && validLon(resp.getXmax())) { |
201 |
// OK, do nothing
|
202 |
} else {
|
203 |
resp.setXmax(180);
|
204 |
resp.setXmin(-180);
|
205 |
} |
206 |
} |
207 |
} |
208 |
// ==================================================
|
209 |
// Fix latitude
|
210 |
// ==================================================
|
211 |
if (resp.getYmax() > resp.getYmin()
|
212 |
&& validLat(resp.getYmin()) && !validLat(resp.getYmax())) { |
213 |
// only ymax is wrong:
|
214 |
resp.setYmax(90);
|
215 |
} else {
|
216 |
if (resp.getYmax() > resp.getYmin()
|
217 |
&& !validLat(resp.getYmin()) && validLat(resp.getYmax())) { |
218 |
// only ymin is wrong:
|
219 |
resp.setYmin(-90);
|
220 |
} else {
|
221 |
if (resp.getYmax() > resp.getYmin()
|
222 |
&& validLat(resp.getYmin()) && validLat(resp.getYmax())) { |
223 |
// OK, do nothing
|
224 |
} else {
|
225 |
// box was a mess, let's fix it
|
226 |
resp.setYmax(90);
|
227 |
resp.setYmin(-90);
|
228 |
} |
229 |
} |
230 |
} |
231 |
// ===============================================
|
232 |
return resp;
|
233 |
|
234 |
} |
235 |
} |