svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.remoteclient / src / main / java / org / gvsig / remoteclient / utils / BoundaryBox.java @ 40769
History | View | Annotate | Download (4.34 KB)
1 | 40559 | jjdelcerro | /**
|
---|---|---|---|
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 | 40435 | jjdelcerro | |
25 | package org.gvsig.remoteclient.utils; |
||
26 | |||
27 | public class BoundaryBox { |
||
28 | |||
29 | private double xmin; |
||
30 | |||
31 | private double xmax; |
||
32 | private double ymin; |
||
33 | private double ymax; |
||
34 | private String srs; |
||
35 | public double getXmin() { |
||
36 | return xmin;
|
||
37 | } |
||
38 | public void setXmin(double _xmin) { |
||
39 | xmin = _xmin; |
||
40 | } |
||
41 | public double getXmax() { |
||
42 | return xmax;
|
||
43 | } |
||
44 | public void setXmax(double _xmax) { |
||
45 | xmax = _xmax; |
||
46 | } |
||
47 | public double getYmin() { |
||
48 | return ymin;
|
||
49 | } |
||
50 | public void setYmin(double _ymin) { |
||
51 | ymin = _ymin; |
||
52 | } |
||
53 | public double getYmax() { |
||
54 | return ymax;
|
||
55 | } |
||
56 | public void setYmax(double _ymax) { |
||
57 | ymax = _ymax; |
||
58 | } |
||
59 | public String getSrs() { |
||
60 | return srs;
|
||
61 | } |
||
62 | public void setSrs(String _srs) { |
||
63 | srs = _srs; |
||
64 | } |
||
65 | |||
66 | public String toString(){ |
||
67 | String s = srs + " (" + xmin + ", " + ymin + ", " + xmax + ", " + ymax + ")"; |
||
68 | |||
69 | return s;
|
||
70 | } |
||
71 | |||
72 | public static boolean validLat(double v) { |
||
73 | return v >= -90 && v <= 90; |
||
74 | } |
||
75 | |||
76 | public static boolean validLon(double v) { |
||
77 | return v >= -180 && v <= 180; |
||
78 | } |
||
79 | |||
80 | public static BoundaryBox clipGeodeticBBox(BoundaryBox bbox) { |
||
81 | |||
82 | BoundaryBox resp = new BoundaryBox();
|
||
83 | resp.setSrs(bbox.getSrs()); |
||
84 | resp.setXmin(bbox.getXmin()); |
||
85 | resp.setXmax(bbox.getXmax()); |
||
86 | resp.setYmin(bbox.getYmin()); |
||
87 | resp.setYmax(bbox.getYmax()); |
||
88 | |||
89 | // ==================================================
|
||
90 | // Fix longitude
|
||
91 | // ==================================================
|
||
92 | if (resp.getXmax() > resp.getXmin()
|
||
93 | && validLon(resp.getXmin()) && !validLon(resp.getXmax())) { |
||
94 | // only xmax is wrong:
|
||
95 | resp.setXmax(180);
|
||
96 | } else {
|
||
97 | if (resp.getXmax() > resp.getXmin()
|
||
98 | && !validLon(resp.getXmin()) && validLon(resp.getXmax())) { |
||
99 | // only xmin is wrong:
|
||
100 | resp.setXmin(-180);
|
||
101 | } else {
|
||
102 | if (resp.getXmax() > resp.getXmin()
|
||
103 | && validLon(resp.getXmin()) && validLon(resp.getXmax())) { |
||
104 | // OK, do nothing
|
||
105 | } else {
|
||
106 | resp.setXmax(180);
|
||
107 | resp.setXmin(-180);
|
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | // ==================================================
|
||
112 | // Fix latitude
|
||
113 | // ==================================================
|
||
114 | if (resp.getYmax() > resp.getYmin()
|
||
115 | && validLat(resp.getYmin()) && !validLat(resp.getYmax())) { |
||
116 | // only ymax is wrong:
|
||
117 | resp.setYmax(90);
|
||
118 | } else {
|
||
119 | if (resp.getYmax() > resp.getYmin()
|
||
120 | && !validLat(resp.getYmin()) && validLat(resp.getYmax())) { |
||
121 | // only ymin is wrong:
|
||
122 | resp.setYmin(-90);
|
||
123 | } else {
|
||
124 | if (resp.getYmax() > resp.getYmin()
|
||
125 | && validLat(resp.getYmin()) && validLat(resp.getYmax())) { |
||
126 | // OK, do nothing
|
||
127 | } else {
|
||
128 | // box was a mess, let's fix it
|
||
129 | resp.setYmax(90);
|
||
130 | resp.setYmin(-90);
|
||
131 | } |
||
132 | } |
||
133 | } |
||
134 | // ===============================================
|
||
135 | return resp;
|
||
136 | |||
137 | } |
||
138 | } |