svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.projection / org.gvsig.projection.cresques / org.gvsig.projection.cresques.impl / src / main / java / org / cresques / impl / cts / gt2 / CoordSys.java @ 40559
History | View | Annotate | Download (6.66 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 |
package org.cresques.impl.cts.gt2; |
25 |
|
26 |
import java.awt.Color; |
27 |
import java.awt.Graphics2D; |
28 |
import java.awt.geom.Point2D; |
29 |
import java.awt.geom.Rectangle2D; |
30 |
|
31 |
import org.cresques.cts.ICoordTrans; |
32 |
import org.cresques.cts.IDatum; |
33 |
import org.cresques.cts.IProjection; |
34 |
import org.cresques.geo.ViewPortData; |
35 |
import org.geotools.cs.CoordinateSystem; |
36 |
import org.geotools.cs.CoordinateSystemFactory; |
37 |
import org.geotools.cs.GeographicCoordinateSystem; |
38 |
import org.geotools.cs.ProjectedCoordinateSystem; |
39 |
import org.gvsig.fmap.crs.CRSFactory; |
40 |
import org.opengis.referencing.FactoryException; |
41 |
|
42 |
|
43 |
/**
|
44 |
* Sistema de Coordenadas (Proyecci?n).
|
45 |
* @author "Luis W. Sevilla" <sevilla_lui@gva.es>
|
46 |
*/
|
47 |
public class CoordSys implements IProjection { |
48 |
private static final Color basicGridColor = new Color(64, 64, 64, 128); |
49 |
protected CoordinateSystemFactory csFactory = CoordinateSystemFactory.getDefault();
|
50 |
protected CSDatum datum = null; |
51 |
protected GeographicCoordinateSystem geogCS = null; |
52 |
protected ProjectedCoordinateSystem projCS = null; |
53 |
protected String abrev = ""; |
54 |
Color gridColor = basicGridColor;
|
55 |
|
56 |
public CoordSys(CSDatum datum) {
|
57 |
this.datum = datum;
|
58 |
this.geogCS = new GeographicCoordinateSystem(datum.getName(null), datum.getDatum()); |
59 |
} |
60 |
|
61 |
public CoordSys(String wkt) { |
62 |
try {
|
63 |
//((GeographicCoordinateSystem)
|
64 |
CoordinateSystem cs = CoordinateSystemFactory.getDefault().createFromWKT(wkt); |
65 |
// ).getHorizontalDatum();
|
66 |
if (cs instanceof GeographicCoordinateSystem) |
67 |
geogCS = (GeographicCoordinateSystem) cs; |
68 |
if (cs instanceof ProjectedCoordinateSystem) { |
69 |
projCS = (ProjectedCoordinateSystem) cs; |
70 |
geogCS = projCS.getGeographicCoordinateSystem(); |
71 |
} |
72 |
datum = new CSDatum(geogCS.getHorizontalDatum());
|
73 |
} catch (FactoryException e) {
|
74 |
// TODO Auto-generated catch block
|
75 |
e.printStackTrace(); |
76 |
} |
77 |
} |
78 |
|
79 |
/**
|
80 |
* Crea un nuevo CoordSys geogr?fico a partir de uno proyectado.
|
81 |
* Si el actual es geogr?fico retorna el mismo.
|
82 |
* @return
|
83 |
*/
|
84 |
public CoordSys toGeo() {
|
85 |
CoordSys coordSys = new CoordSys((CSDatum) getDatum());
|
86 |
|
87 |
if (geogCS != null) { |
88 |
coordSys.geogCS = this.geogCS;
|
89 |
} else {
|
90 |
coordSys.geogCS = projCS.getGeographicCoordinateSystem(); |
91 |
} |
92 |
|
93 |
return coordSys;
|
94 |
} |
95 |
|
96 |
public IDatum getDatum() {
|
97 |
return datum;
|
98 |
} |
99 |
|
100 |
public CoordinateSystem getCS() {
|
101 |
if (projCS != null) { |
102 |
return projCS;
|
103 |
} |
104 |
|
105 |
return geogCS;
|
106 |
} |
107 |
|
108 |
public CoordinateSystem getGeogCS() {
|
109 |
if (geogCS != null) { |
110 |
return geogCS;
|
111 |
} |
112 |
|
113 |
return projCS.getGeographicCoordinateSystem();
|
114 |
} |
115 |
|
116 |
/* (no Javadoc)
|
117 |
* @see org.cresques.cts.IProjection#createPoint(double, double)
|
118 |
*/
|
119 |
public Point2D createPoint(double x, double y) { |
120 |
return new Point2D.Double(x, y); |
121 |
} |
122 |
|
123 |
public String toString() { |
124 |
if (projCS != null) { |
125 |
return projCS.toString();
|
126 |
} |
127 |
|
128 |
return geogCS.toString();
|
129 |
} |
130 |
|
131 |
public void setAbrev(String abrev) { |
132 |
this.abrev = abrev;
|
133 |
} |
134 |
|
135 |
public String getAbrev() { |
136 |
return abrev;
|
137 |
} |
138 |
|
139 |
/* (no Javadoc)
|
140 |
* @see org.cresques.cts.IProjection#drawGrid(java.awt.Graphics2D, org.cresques.geo.ViewPortData)
|
141 |
*/
|
142 |
public void drawGrid(Graphics2D g, ViewPortData vp) { |
143 |
// TODO Ap?ndice de m?todo generado autom?ticamente
|
144 |
} |
145 |
|
146 |
public void setGridColor(Color c) { |
147 |
gridColor = c; |
148 |
} |
149 |
|
150 |
public Color getGridColor() { |
151 |
return gridColor;
|
152 |
} |
153 |
|
154 |
/* (no Javadoc)
|
155 |
* @see org.cresques.cts.IProjection#toGeo(java.awt.geom.Point2D)
|
156 |
*/
|
157 |
public Point2D toGeo(Point2D pt) { |
158 |
//TODO VCN Esto si no lo comento no me trasforma el punto en coordenadas geogr?ficas.
|
159 |
// if (getGeogCS() == geogCS) {
|
160 |
// return pt;
|
161 |
// } else {
|
162 |
CoordTrans ct = new CoordTrans(this, toGeo()); |
163 |
|
164 |
return ct.convert(pt, null); |
165 |
// }
|
166 |
} |
167 |
|
168 |
/* (no Javadoc)
|
169 |
* @see org.cresques.cts.IProjection#fromGeo(java.awt.geom.Point2D, java.awt.geom.Point2D)
|
170 |
*/
|
171 |
public Point2D fromGeo(Point2D gPt, Point2D mPt) { |
172 |
// TODO Ap?ndice de m?todo generado autom?ticamente
|
173 |
return null; |
174 |
} |
175 |
|
176 |
public double getScale(double minX, double maxX, double w, double dpi) { |
177 |
double scale = 0D; |
178 |
|
179 |
if (projCS == null) { // Es geogr?fico; calcula la escala. |
180 |
scale = ((maxX - minX) * // grados
|
181 |
|
182 |
// 1852.0 metros x minuto de meridiano
|
183 |
(dpi / 2.54 * 100.0 * 1852.0 * 60.0)) / // px / metro |
184 |
w; // pixels
|
185 |
} |
186 |
|
187 |
return scale;
|
188 |
} |
189 |
public Rectangle2D getExtent(Rectangle2D extent,double scale,double wImage,double hImage,double mapUnits,double distanceUnits,double dpi) { |
190 |
double w =0; |
191 |
double h =0; |
192 |
double wExtent =0; |
193 |
double hExtent =0; |
194 |
if (projCS!=null) { |
195 |
w = ((wImage / dpi) * 2.54);
|
196 |
h = ((hImage / dpi) * 2.54);
|
197 |
wExtent =w * scale*distanceUnits/ mapUnits; |
198 |
hExtent =h * scale*distanceUnits/ mapUnits; |
199 |
|
200 |
}else {
|
201 |
w = ((wImage / dpi) * 2.54);
|
202 |
h = ((hImage / dpi) * 2.54);
|
203 |
wExtent =(w*scale*distanceUnits)/ (mapUnits*1852.0*60.0); |
204 |
hExtent =(h*scale*distanceUnits)/ (mapUnits*1852.0*60.0); |
205 |
} |
206 |
double xExtent = extent.getCenterX() - wExtent/2; |
207 |
double yExtent = extent.getCenterY() - hExtent/2; |
208 |
Rectangle2D rec=new Rectangle2D.Double(xExtent,yExtent,wExtent,hExtent); |
209 |
return rec;
|
210 |
} |
211 |
public boolean isProjected() { |
212 |
return projCS != null; |
213 |
} |
214 |
|
215 |
public ICoordTrans getCT(IProjection dest) {
|
216 |
return new CoordTrans(this, (CoordSys) dest); |
217 |
} |
218 |
|
219 |
public String getFullCode() { |
220 |
return getAbrev();
|
221 |
} |
222 |
|
223 |
public Object clone() throws CloneNotSupportedException { |
224 |
return CRSFactory.getCRS( this.getFullCode() ); |
225 |
} |
226 |
|
227 |
} |