svn-gvsig-desktop / branches / F2 / libraries / libJCRS / src / org / gvsig / crs / CrsGT.java @ 11389
History | View | Annotate | Download (6.82 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.crs; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Graphics2D; |
45 |
import java.awt.geom.Point2D; |
46 |
import java.awt.geom.Rectangle2D; |
47 |
|
48 |
import org.cresques.cts.ICoordTrans; |
49 |
import org.cresques.cts.IDatum; |
50 |
import org.cresques.cts.IProjection; |
51 |
import org.cresques.geo.ViewPortData; |
52 |
import org.gvsig.crs.proj.CrsProj; |
53 |
import org.gvsig.crs.proj.CrsProjException; |
54 |
import org.gvsig.crs.proj.JNIBaseCrs; |
55 |
import org.gvsig.crs.proj.OperationCrsException; |
56 |
import org.idr.geotools.metadata.iso.citation.Citations; |
57 |
import org.idr.geotools.referencing.crs.AbstractDerivedCRS; |
58 |
import org.idr.geotools.referencing.crs.AbstractSingleCRS; |
59 |
import org.idr.geotools.referencing.datum.DefaultGeodeticDatum; |
60 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
61 |
|
62 |
/**
|
63 |
* Clase que representa un CRS basado en GeoTools/GeoApi.
|
64 |
*
|
65 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
66 |
*
|
67 |
*/
|
68 |
public class CrsGT implements ICrs { |
69 |
private static final Color basicGridColor = new Color(64, 64, 64, 128); |
70 |
|
71 |
/**
|
72 |
* CRS GeoApi. Nucleo de la clare CrsGT.
|
73 |
*/
|
74 |
private CoordinateReferenceSystem crsGT = null; |
75 |
|
76 |
private boolean targetNad = false; |
77 |
/**
|
78 |
*Cadena proj4
|
79 |
*/
|
80 |
private String proj4 = null; |
81 |
|
82 |
private Color gridColor = basicGridColor; |
83 |
|
84 |
/**
|
85 |
* Par?metro nadgrid para proj4.
|
86 |
*/
|
87 |
private String nad = null; |
88 |
|
89 |
/**
|
90 |
* CRS operable con proj4.
|
91 |
*/
|
92 |
private CrsProj crsProj = null; |
93 |
|
94 |
/**
|
95 |
* CRS Base operable con proj4.
|
96 |
*/
|
97 |
private CrsProj crsProjBase = null; |
98 |
|
99 |
/**
|
100 |
* Provisional, hasta que se elimine getCrsWkt de ICrs.
|
101 |
*/
|
102 |
private CrsWkt crsWkt = null; |
103 |
|
104 |
|
105 |
|
106 |
/**
|
107 |
* Constructor a partir de un CoordinateReferenceSystem
|
108 |
*
|
109 |
* @param crsGT
|
110 |
* @throws CrsProjException
|
111 |
*/
|
112 |
public CrsGT(CoordinateReferenceSystem crsGT){
|
113 |
this.crsGT = crsGT;
|
114 |
Proj4 proj4; |
115 |
try {
|
116 |
proj4 = new Proj4();
|
117 |
crsProj = new CrsProj(proj4.exportToProj4(crsGT));
|
118 |
if (crsGT instanceof AbstractDerivedCRS){ |
119 |
AbstractDerivedCRS derivedCRS = (AbstractDerivedCRS)crsGT; |
120 |
crsProjBase = new CrsProj(proj4.exportToProj4(derivedCRS.getBaseCRS()));
|
121 |
} |
122 |
} catch (CrsException e) {
|
123 |
// TODO Auto-generated catch block
|
124 |
e.printStackTrace(); |
125 |
} |
126 |
|
127 |
crsWkt = new CrsWkt(crsGT);
|
128 |
} |
129 |
|
130 |
public int getCode() { |
131 |
return Integer.valueOf(getAbrev().split(":")[1]).intValue(); |
132 |
} |
133 |
|
134 |
public CrsWkt getCrsWkt() {
|
135 |
return crsWkt;
|
136 |
} |
137 |
|
138 |
public String getWKT() { |
139 |
return crsGT.toWKT();
|
140 |
} |
141 |
|
142 |
public void setNadGrid(String nad) { |
143 |
this.nad = nad;
|
144 |
|
145 |
} |
146 |
|
147 |
public void setNadInTarget(boolean targetNad) { |
148 |
// TODO Auto-generated method stub
|
149 |
|
150 |
} |
151 |
|
152 |
public Point2D createPoint(double x, double y) { |
153 |
// TODO Auto-generated method stub
|
154 |
return null; |
155 |
} |
156 |
|
157 |
public void drawGrid(Graphics2D g, ViewPortData vp) { |
158 |
// TODO Auto-generated method stub
|
159 |
|
160 |
} |
161 |
|
162 |
public Point2D fromGeo(Point2D gPt, Point2D mPt) { |
163 |
// TODO Auto-generated method stub
|
164 |
return null; |
165 |
} |
166 |
|
167 |
public String getAbrev() { |
168 |
AbstractSingleCRS crs = (AbstractSingleCRS)crsGT; |
169 |
String authority = crs.getName().toString().split(":")[0]; |
170 |
return ((AbstractSingleCRS)crsGT).getIdentifier(Citations.fromName(authority)).toString();
|
171 |
} |
172 |
|
173 |
public ICoordTrans getCT(IProjection dest) {
|
174 |
COperation operation = null;
|
175 |
CrsGT crsDest = (CrsGT)dest; |
176 |
try {
|
177 |
operation = new COperation(this, (ICrs)dest); |
178 |
} catch (CrsException e) {
|
179 |
// TODO Auto-generated catch block
|
180 |
e.printStackTrace(); |
181 |
} |
182 |
|
183 |
if (!getNadGrid().equals("")){ |
184 |
if (isTargetNad())
|
185 |
operation.setNadCrsProj(new CrsProj(crsDest.getProj4()+getNadGrid()), true); |
186 |
else
|
187 |
operation.setNadCrsProj(new CrsProj(getProj4()+getNadGrid()), false); |
188 |
return operation;
|
189 |
} |
190 |
|
191 |
return operation;
|
192 |
} |
193 |
|
194 |
public IDatum getDatum() {
|
195 |
DefaultGeodeticDatum datumGT = (DefaultGeodeticDatum)((AbstractSingleCRS)crsGT).getDatum(); |
196 |
CRSDatum datum = new CRSDatum(datumGT.getEllipsoid().getSemiMajorAxis(),datumGT.getEllipsoid().getInverseFlattening());
|
197 |
return datum;
|
198 |
} |
199 |
|
200 |
public Rectangle2D getExtent(Rectangle2D extent, double scale, |
201 |
double wImage, double hImage, double changeUnits, double dpi) { |
202 |
// TODO Auto-generated method stub
|
203 |
return null; |
204 |
} |
205 |
|
206 |
public Color getGridColor() { |
207 |
return gridColor;
|
208 |
} |
209 |
|
210 |
public double getScale(double minX, double maxX, double width, double dpi) { |
211 |
double scale = 0D; |
212 |
if (!isProjected()) { // Es geogr?fico; calcula la escala. |
213 |
scale = ((maxX - minX) * // grados
|
214 |
|
215 |
// 1852.0 metros x minuto de meridiano
|
216 |
(dpi / 2.54 * 100.0 * 1852.0 * 60.0)) / // px / metro |
217 |
width; // pixels
|
218 |
} |
219 |
else{
|
220 |
scale = ((maxX - minX) * // metros
|
221 |
(dpi / 2.54 * 100.0)) / // px / metro |
222 |
width; // pixels
|
223 |
} |
224 |
return scale;
|
225 |
} |
226 |
|
227 |
public boolean isProjected() { |
228 |
if (crsGT instanceof AbstractDerivedCRS){ |
229 |
return true; |
230 |
}else
|
231 |
return false; |
232 |
} |
233 |
|
234 |
public void setGridColor(Color c) { |
235 |
gridColor = c; |
236 |
} |
237 |
|
238 |
public Point2D toGeo(Point2D pt) { |
239 |
if (isProjected()){
|
240 |
double x[] = {pt.getX()}; |
241 |
double y[] = {pt.getY()}; |
242 |
double z[] = {0D}; |
243 |
try {
|
244 |
JNIBaseCrs.operate( x , y, z, |
245 |
crsProj,crsProjBase); |
246 |
} catch (OperationCrsException e) {
|
247 |
// TODO Auto-generated catch block
|
248 |
e.printStackTrace(); |
249 |
} catch (CrsProjException e) {
|
250 |
// TODO Auto-generated catch block
|
251 |
e.printStackTrace(); |
252 |
} |
253 |
return new Point2D.Double(x[0],y[0]); |
254 |
} |
255 |
else
|
256 |
return pt;
|
257 |
} |
258 |
|
259 |
public String getNadGrid() { |
260 |
return nad;
|
261 |
} |
262 |
|
263 |
/**
|
264 |
* @return
|
265 |
*/
|
266 |
public boolean isTargetNad() { |
267 |
return targetNad;
|
268 |
} |
269 |
|
270 |
/**
|
271 |
*
|
272 |
* @return
|
273 |
*/
|
274 |
public String getProj4() { |
275 |
return proj4;
|
276 |
} |
277 |
|
278 |
public CoordinateReferenceSystem getCrsGT() {
|
279 |
return crsGT;
|
280 |
} |
281 |
|
282 |
} |