root / trunk / libraries / libJCRS / src / org / gvsig / crs / Crs.java @ 11374
History | View | Annotate | Download (19.2 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.ogr.CrsOgr; |
53 |
import org.gvsig.crs.ogr.CrsOgrException; |
54 |
import org.gvsig.crs.ogr.OGRException; |
55 |
import org.gvsig.crs.ogr.OGRSpatialReference; |
56 |
import org.gvsig.crs.ogr.crsgdalException; |
57 |
import org.gvsig.crs.proj.CrsProj; |
58 |
import org.gvsig.crs.proj.CrsProjException; |
59 |
import org.gvsig.crs.proj.JNIBaseCrs; |
60 |
import org.gvsig.crs.proj.OperationCrsException; |
61 |
|
62 |
/**
|
63 |
* Clase que construye el CRS a partir de la cadena WKT
|
64 |
* @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
|
65 |
* @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
|
66 |
* @author Miguel Garc?a Jim?nez (garciajimenez.miguel@gmail.com)
|
67 |
*
|
68 |
*/
|
69 |
public class Crs implements ICrs { |
70 |
private static final Color basicGridColor = new Color(64, 64, 64, 128); |
71 |
private String proj4; |
72 |
private String trans; |
73 |
//private String transOrigin = "";
|
74 |
private String abrev; |
75 |
private String name = ""; |
76 |
private CrsProj crsProj4;
|
77 |
private CrsProj crsBase = null; |
78 |
private CrsWkt crsWkt;
|
79 |
private int epsg_code = 23030; |
80 |
boolean targetNad = false; |
81 |
String TransParam = ""; |
82 |
String wkt = null; |
83 |
Color gridColor = basicGridColor;
|
84 |
CRSDatum datum = null;
|
85 |
|
86 |
/**
|
87 |
* Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
|
88 |
*
|
89 |
* @param code
|
90 |
* @throws CrsException
|
91 |
*/
|
92 |
public Crs(String code) throws CrsException { |
93 |
String fullCode;
|
94 |
setWKT(code); |
95 |
if(code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P') |
96 |
fullCode = code; |
97 |
else fullCode = "EPSG:"+code; |
98 |
String cod = ""; |
99 |
if(code.length() < 15 ) { |
100 |
code = code.substring(code.indexOf(":")+1); |
101 |
try {
|
102 |
//Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
|
103 |
crsWkt = new CrsWkt(fullCode);
|
104 |
OGRSpatialReference oSRSSource = new OGRSpatialReference();
|
105 |
CrsOgr.importFromEPSG(oSRSSource, |
106 |
Integer.parseInt(code));
|
107 |
//Guardamos la cadena Proj4 devuelva por la OGRSpatialReference
|
108 |
proj4 = CrsOgr.exportToProj4(oSRSSource); |
109 |
crsProj4 = new CrsProj(proj4);
|
110 |
setName(fullCode); |
111 |
setAbrev(fullCode); |
112 |
|
113 |
} catch (OGRException e) {
|
114 |
throw new CrsException(e); |
115 |
} catch (crsgdalException e) {
|
116 |
throw new CrsException(e); |
117 |
} catch (CrsOgrException e) {
|
118 |
throw new CrsException(e); |
119 |
} |
120 |
}else {
|
121 |
String aux;
|
122 |
String code2 = ""; |
123 |
for(int i = 0; i < code.length(); i++) { |
124 |
aux = ""+code.charAt(i);
|
125 |
if(!aux.equals(" ")) { |
126 |
code2+=aux; |
127 |
}else {
|
128 |
code2 += "";
|
129 |
} |
130 |
} |
131 |
crsWkt = new CrsWkt(code2);
|
132 |
try {
|
133 |
OGRSpatialReference oSRSSource = new OGRSpatialReference();
|
134 |
CrsOgr.importFromWkt(oSRSSource,code2); |
135 |
proj4 =CrsOgr.exportToProj4(oSRSSource); |
136 |
crsProj4 = new CrsProj(proj4);
|
137 |
setName(fullCode); |
138 |
//setAbrev(crsWkt.getName());
|
139 |
setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
140 |
} catch (OGRException e) {
|
141 |
throw new CrsException(e); |
142 |
} catch (crsgdalException e) {
|
143 |
throw new CrsException(e); |
144 |
} catch (CrsOgrException e) {
|
145 |
throw new CrsException(e); |
146 |
} |
147 |
} |
148 |
// Asignar el datum y el crs base (en el caso de ser projectado):
|
149 |
if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){ |
150 |
double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue(); |
151 |
double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue(); |
152 |
datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
|
153 |
|
154 |
//crs base (en el caso de ser projectado):
|
155 |
if(this.isProjected()){ |
156 |
String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ; |
157 |
crsBase = new CrsProj(proj4Base);
|
158 |
} |
159 |
} |
160 |
} |
161 |
|
162 |
/**
|
163 |
*Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
|
164 |
*
|
165 |
* @param epsg_cod
|
166 |
* @param code
|
167 |
* @throws CrsException
|
168 |
*/
|
169 |
public Crs(int epsg_cod, String code) throws CrsException { |
170 |
String fullCode;
|
171 |
setWKT(code); |
172 |
setCode(epsg_cod); |
173 |
if(code != null || code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P') |
174 |
fullCode = code; |
175 |
else fullCode = "EPSG:"+code; |
176 |
String cod = ""; |
177 |
if(code.length() < 15 ) { |
178 |
code = code.substring(code.indexOf(":")+1); |
179 |
try {
|
180 |
//Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
|
181 |
crsWkt = new CrsWkt(fullCode);
|
182 |
OGRSpatialReference oSRSSource = new OGRSpatialReference();
|
183 |
CrsOgr.importFromEPSG(oSRSSource, |
184 |
Integer.parseInt(code));
|
185 |
//Guardamos la cadena Proj4 devuelva por la OGRSpatialReference
|
186 |
proj4 = CrsOgr.exportToProj4(oSRSSource); |
187 |
crsProj4 = new CrsProj(proj4);
|
188 |
setName(fullCode); |
189 |
setAbrev(fullCode); |
190 |
|
191 |
} catch (OGRException e) {
|
192 |
throw new CrsException(e); |
193 |
} catch (crsgdalException e) {
|
194 |
throw new CrsException(e); |
195 |
} catch (CrsOgrException e) {
|
196 |
throw new CrsException(e); |
197 |
} |
198 |
}else {
|
199 |
String aux;
|
200 |
String code2 = ""; |
201 |
for(int i = 0; i < code.length(); i++) { |
202 |
aux = ""+code.charAt(i);
|
203 |
if(!aux.equals(" ")) { |
204 |
code2+=aux; |
205 |
}else {
|
206 |
code2 += "";
|
207 |
} |
208 |
} |
209 |
crsWkt = new CrsWkt(code2);
|
210 |
/*
|
211 |
* Arreglo temporal para ver si funcionan de la iau2000 las proyecciones
|
212 |
* cilindrica equidistante y oblicua cilindrica equidistante
|
213 |
* que no estan en gdal, por lo que asignaremos directamente su cadena
|
214 |
* en proj4 para trabajar con ellas
|
215 |
*/
|
216 |
if (!crsWkt.getProjection().equals("Equidistant_Cylindrical") && !crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){ |
217 |
try {
|
218 |
OGRSpatialReference oSRSSource = new OGRSpatialReference();
|
219 |
CrsOgr.importFromWkt(oSRSSource,code2); |
220 |
proj4 = CrsOgr.exportToProj4(oSRSSource); |
221 |
crsProj4 = new CrsProj(proj4);
|
222 |
setName(fullCode); |
223 |
//setAbrev(crsWkt.getName());
|
224 |
setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
225 |
} catch (OGRException e) {
|
226 |
throw new CrsException(e); |
227 |
} catch (crsgdalException e) {
|
228 |
throw new CrsException(e); |
229 |
} catch (CrsOgrException e) {
|
230 |
throw new CrsException(e); |
231 |
} |
232 |
} |
233 |
else if (crsWkt.getProjection().equals("Equidistant_Cylindrical")){ |
234 |
String spheroid1 = crsWkt.getSpheroid()[1]; |
235 |
String spheroid2 = crsWkt.getSpheroid()[2]; |
236 |
String centralMeridian = ""; |
237 |
String falseNorthing = ""; |
238 |
String falseEasting = ""; |
239 |
String standardParallel1 = "0.0"; |
240 |
for (int i=0; i<crsWkt.getParam_name().length;i++){ |
241 |
if (crsWkt.getParam_name()[i].equals("Central_Meridian")) |
242 |
centralMeridian = crsWkt.getParam_value()[i]; |
243 |
if (crsWkt.getParam_name()[i].equals("False_Easting")) |
244 |
falseEasting = crsWkt.getParam_value()[i]; |
245 |
if(crsWkt.getParam_name()[i].equals("False_Northing")) |
246 |
falseNorthing = crsWkt.getParam_value()[i]; |
247 |
if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1")) |
248 |
standardParallel1 = crsWkt.getParam_value()[i]; |
249 |
} |
250 |
if (spheroid2.equals("0.0")){ |
251 |
proj4 = "+proj=eqc +a=" + spheroid1 +
|
252 |
" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing + |
253 |
" +lat_ts="+standardParallel1;
|
254 |
} else {
|
255 |
proj4 = "+proj=eqc +a="+ spheroid1 +" +rf=" + spheroid2 + |
256 |
" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing + |
257 |
" +lat_ts="+standardParallel1;
|
258 |
} |
259 |
|
260 |
crsProj4 = new CrsProj(proj4);
|
261 |
setName(fullCode); |
262 |
//setAbrev(crsWkt.getName());
|
263 |
setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
264 |
|
265 |
} |
266 |
else if (crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){ |
267 |
String spheroid1 = crsWkt.getSpheroid()[1]; |
268 |
String spheroid2 = crsWkt.getSpheroid()[2]; |
269 |
String centralMeridian = ""; |
270 |
String falseNorthing = ""; |
271 |
String falseEasting = ""; |
272 |
String standardParallel1 = ""; |
273 |
String standardParallel2 = "0.0"; |
274 |
for (int i=0; i<crsWkt.getParam_name().length;i++){ |
275 |
if (crsWkt.getParam_name()[i].equals("Central_Meridian")) |
276 |
centralMeridian = crsWkt.getParam_value()[i]; |
277 |
if (crsWkt.getParam_name()[i].equals("False_Easting")) |
278 |
falseEasting = crsWkt.getParam_value()[i]; |
279 |
if(crsWkt.getParam_name()[i].equals("False_Northing")) |
280 |
falseNorthing = crsWkt.getParam_value()[i]; |
281 |
if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1")) |
282 |
standardParallel1 = crsWkt.getParam_value()[i]; |
283 |
if (crsWkt.getParam_name()[i].equals("Standard_Parallel_2")) |
284 |
standardParallel2 = crsWkt.getParam_value()[i]; |
285 |
} |
286 |
if (spheroid2.equals("0.0")){ |
287 |
proj4 = "+proj=ocea +a="+ spheroid1 +
|
288 |
" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing + |
289 |
" +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" + |
290 |
" +lon_2=long_2 +no_defs";
|
291 |
} else {
|
292 |
proj4 = "+proj=ocea +a="+ spheroid1 + " +rf=" + spheroid2 + |
293 |
" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing + |
294 |
" +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" + |
295 |
" +lon_2=long_2 +no_defs";
|
296 |
} |
297 |
|
298 |
crsProj4 = new CrsProj(proj4);
|
299 |
setName(fullCode); |
300 |
//setAbrev(crsWkt.getName());
|
301 |
setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
302 |
} |
303 |
} |
304 |
// Asignar el datum:
|
305 |
if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){ |
306 |
double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue(); |
307 |
double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue(); |
308 |
datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
|
309 |
|
310 |
// Crs base (en el caso de ser projectado):
|
311 |
if(this.isProjected()){ |
312 |
String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ; |
313 |
crsBase = new CrsProj(proj4Base);
|
314 |
} |
315 |
} |
316 |
} |
317 |
|
318 |
/**
|
319 |
* Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
|
320 |
* En el caso de WKT le a?ade a la cadena proj4 el string params.
|
321 |
*
|
322 |
* @param epsg_cod
|
323 |
* @param code
|
324 |
* @param params
|
325 |
* @throws CrsException
|
326 |
*/
|
327 |
public Crs(int epsg_cod, String code,String params) throws CrsException { |
328 |
String fullCode;
|
329 |
setCode(epsg_cod); |
330 |
setWKT(code); |
331 |
if(code.charAt(0) == 'E' || code.charAt(0) == 'G' || code.charAt(0) == 'P') |
332 |
fullCode = code; |
333 |
else fullCode = "EPSG:"+code; |
334 |
String cod = ""; |
335 |
if(code.length() < 15 ) { |
336 |
code = code.substring(code.indexOf(":")+1); |
337 |
try {
|
338 |
//Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
|
339 |
crsWkt = new CrsWkt(fullCode);
|
340 |
OGRSpatialReference oSRSSource = new OGRSpatialReference();
|
341 |
CrsOgr.importFromEPSG(oSRSSource, |
342 |
Integer.parseInt(code));
|
343 |
//Guardamos la cadena Proj4 devuelva por la OGRSpatialReference
|
344 |
proj4 = CrsOgr.exportToProj4(oSRSSource); |
345 |
crsProj4 = new CrsProj(proj4);
|
346 |
setName(fullCode); |
347 |
setAbrev(fullCode); |
348 |
|
349 |
} catch (OGRException e) {
|
350 |
throw new CrsException(e); |
351 |
} catch (crsgdalException e) {
|
352 |
throw new CrsException(e); |
353 |
} catch (CrsOgrException e) {
|
354 |
throw new CrsException(e); |
355 |
} |
356 |
}else {
|
357 |
String aux;
|
358 |
String code2 = ""; |
359 |
for(int i = 0; i < code.length(); i++) { |
360 |
aux = ""+code.charAt(i);
|
361 |
if(!aux.equals(" ")) { |
362 |
code2+=aux; |
363 |
}else {
|
364 |
code2 += "";
|
365 |
} |
366 |
} |
367 |
crsWkt = new CrsWkt(code2);
|
368 |
try {
|
369 |
OGRSpatialReference oSRSSource = new OGRSpatialReference();
|
370 |
CrsOgr.importFromWkt(oSRSSource,code2); |
371 |
proj4 =CrsOgr.exportToProj4(oSRSSource)+params+" ";
|
372 |
crsProj4 = new CrsProj(proj4);
|
373 |
setName(fullCode); |
374 |
//setAbrev(crsWkt.getName());
|
375 |
setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]); |
376 |
} catch (OGRException e) {
|
377 |
throw new CrsException(e); |
378 |
} catch (crsgdalException e) {
|
379 |
throw new CrsException(e); |
380 |
} catch (CrsOgrException e) {
|
381 |
throw new CrsException(e); |
382 |
} |
383 |
} |
384 |
// Asignar el datum:
|
385 |
if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){ |
386 |
double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue(); |
387 |
double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue(); |
388 |
datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
|
389 |
|
390 |
// Crs base (en el caso de ser projectado):
|
391 |
if(this.isProjected()){ |
392 |
String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ; |
393 |
crsBase = new CrsProj(proj4Base);
|
394 |
} |
395 |
} |
396 |
} |
397 |
|
398 |
/* public Crs(CrsEpsg source) throws CrsException {
|
399 |
crsProj4 = source;
|
400 |
}*/
|
401 |
|
402 |
/**
|
403 |
* @param code
|
404 |
*/
|
405 |
public void setTrans(String code) { |
406 |
trans = code; |
407 |
changeTrans(trans); |
408 |
} |
409 |
|
410 |
/**
|
411 |
*
|
412 |
* @param code
|
413 |
*/
|
414 |
public void changeTrans(String code) { |
415 |
crsProj4.changeStrCrs(code); |
416 |
} |
417 |
|
418 |
/**
|
419 |
*
|
420 |
*/
|
421 |
public String getAbrev() { |
422 |
return abrev;
|
423 |
} |
424 |
|
425 |
/**
|
426 |
*
|
427 |
* @param code
|
428 |
*/
|
429 |
protected void setAbrev(String code) { |
430 |
abrev = code; |
431 |
} |
432 |
|
433 |
/**
|
434 |
*
|
435 |
* @param nom
|
436 |
*/
|
437 |
public void setName(String nom) { |
438 |
name = nom; |
439 |
} |
440 |
|
441 |
/**
|
442 |
* @return
|
443 |
*/
|
444 |
public IDatum getDatum() {
|
445 |
/*CSDatum datum = new CSDatum();
|
446 |
try {
|
447 |
datum.fromWKT(getWKT());
|
448 |
} catch (FactoryException e) {
|
449 |
// TODO Auto-generated catch block
|
450 |
e.printStackTrace();
|
451 |
}*/
|
452 |
return datum;
|
453 |
} |
454 |
|
455 |
/**
|
456 |
* @return
|
457 |
*/
|
458 |
public CrsWkt getCrsWkt() {
|
459 |
return crsWkt;
|
460 |
} |
461 |
|
462 |
/**
|
463 |
*
|
464 |
* @param wkt
|
465 |
*/
|
466 |
public void setWKT(String wkt){ |
467 |
this.wkt = wkt;
|
468 |
} |
469 |
|
470 |
/**
|
471 |
* @return
|
472 |
*/
|
473 |
public String getWKT(){ |
474 |
return this.wkt; |
475 |
} |
476 |
|
477 |
/**
|
478 |
*
|
479 |
* @param param
|
480 |
*/
|
481 |
public void setTransParam(String param){ |
482 |
this.TransParam = param;
|
483 |
} |
484 |
|
485 |
/**
|
486 |
* @return
|
487 |
*/
|
488 |
public String getTransParam(){ |
489 |
return this.TransParam; |
490 |
} |
491 |
|
492 |
/**
|
493 |
* @param target
|
494 |
* @return
|
495 |
*/
|
496 |
public ICOperation getCOp(ICrs target) throws CrsException { |
497 |
if (!this.getTransParam().equals("")) { |
498 |
ICrs crs = new Crs(target.getCode(), target.getWKT(), this.getTransParam()); |
499 |
return new COperation(this, crs); |
500 |
} |
501 |
else return new COperation(this, target); |
502 |
} |
503 |
|
504 |
/**
|
505 |
*
|
506 |
* @return
|
507 |
*/
|
508 |
protected CrsProj getCrsProj() {
|
509 |
return crsProj4;
|
510 |
} |
511 |
|
512 |
/**
|
513 |
* @param x
|
514 |
* @param y
|
515 |
* @return
|
516 |
*/
|
517 |
public Point2D createPoint(double x, double y) { |
518 |
return new Point2D.Double(x,y); |
519 |
} |
520 |
|
521 |
/**
|
522 |
* @param g
|
523 |
* @param vp
|
524 |
*/
|
525 |
public void drawGrid(Graphics2D g, ViewPortData vp) { |
526 |
// TODO Auto-generated method stub
|
527 |
|
528 |
} |
529 |
|
530 |
/**
|
531 |
* @param c
|
532 |
*/
|
533 |
public void setGridColor(Color c) { |
534 |
gridColor = c; |
535 |
} |
536 |
|
537 |
/**
|
538 |
* @return
|
539 |
*/
|
540 |
public Color getGridColor() { |
541 |
return gridColor;
|
542 |
} |
543 |
|
544 |
/**
|
545 |
* @param dest
|
546 |
* @return
|
547 |
*/
|
548 |
public ICoordTrans getCT(IProjection dest) {
|
549 |
COperation operation = null;
|
550 |
Crs crsDest = (Crs)dest; |
551 |
try {
|
552 |
operation = new COperation(this, (ICrs)dest); |
553 |
} catch (CrsException e) {
|
554 |
// TODO Auto-generated catch block
|
555 |
e.printStackTrace(); |
556 |
} |
557 |
|
558 |
if (!getTransParam().equals("")){ |
559 |
if (isTransInTarget())
|
560 |
operation.setNadCrsProj(new CrsProj(crsDest.getProj4()+getTransParam()), true); |
561 |
else
|
562 |
operation.setNadCrsProj(new CrsProj(getProj4()+getTransParam()), false); |
563 |
|
564 |
return operation;
|
565 |
} |
566 |
|
567 |
return operation;
|
568 |
|
569 |
/*ICrs crs = (ICrs) dest;
|
570 |
try {
|
571 |
if (!this.getNadGrid().equals("")) {
|
572 |
crs = new Crs(crs.getCode(), crs.getWKT(), this.getNadGrid());
|
573 |
return new COperation(this, crs);
|
574 |
}
|
575 |
else return new COperation(this, crs);
|
576 |
} catch (CrsException e) {
|
577 |
// TODO Auto-generated catch block
|
578 |
e.printStackTrace();
|
579 |
}
|
580 |
return null;*/
|
581 |
} |
582 |
|
583 |
/**
|
584 |
* @param pt
|
585 |
* @return
|
586 |
*/
|
587 |
public Point2D toGeo(Point2D pt) { |
588 |
if (isProjected()){
|
589 |
double x[] = {pt.getX()}; |
590 |
double y[] = {pt.getY()}; |
591 |
double z[] = {0D}; |
592 |
try {
|
593 |
JNIBaseCrs.operate( x , y, z, |
594 |
crsProj4,crsBase); |
595 |
} catch (OperationCrsException e) {
|
596 |
// TODO Auto-generated catch block
|
597 |
e.printStackTrace(); |
598 |
} catch (CrsProjException e) {
|
599 |
// TODO Auto-generated catch block
|
600 |
e.printStackTrace(); |
601 |
} |
602 |
return new Point2D.Double(x[0],y[0]); |
603 |
} |
604 |
else
|
605 |
return pt;
|
606 |
} |
607 |
|
608 |
/**
|
609 |
* @param gPt
|
610 |
* @param mPt
|
611 |
* @return
|
612 |
*/
|
613 |
public Point2D fromGeo(Point2D gPt, Point2D mPt) { |
614 |
// TODO Auto-generated method stub
|
615 |
return null; |
616 |
} |
617 |
|
618 |
/**
|
619 |
* @return
|
620 |
*/
|
621 |
public boolean isProjected() { |
622 |
return !crsProj4.isLatlong();
|
623 |
} |
624 |
|
625 |
/**
|
626 |
* @param minX
|
627 |
* @param maxX
|
628 |
* @param width
|
629 |
* @param dpi
|
630 |
* @return
|
631 |
*/
|
632 |
public double getScale(double minX, double maxX, double width, double dpi) { |
633 |
double scale = 0D; |
634 |
if (!isProjected()) { // Es geogr?fico; calcula la escala. |
635 |
scale = ((maxX - minX) * // grados
|
636 |
|
637 |
// 1852.0 metros x minuto de meridiano
|
638 |
(dpi / 2.54 * 100.0 * 1852.0 * 60.0)) / // px / metro |
639 |
width; // pixels
|
640 |
} |
641 |
else{
|
642 |
scale = ((maxX - minX) * // metros
|
643 |
(dpi / 2.54 * 100.0)) / // px / metro |
644 |
width; // pixels
|
645 |
} |
646 |
return scale;
|
647 |
} |
648 |
|
649 |
/**
|
650 |
*
|
651 |
* @param epsg_cod
|
652 |
*/
|
653 |
public void setCode(int epsg_cod){ |
654 |
epsg_code = epsg_cod; |
655 |
} |
656 |
|
657 |
/**
|
658 |
* @return
|
659 |
*/
|
660 |
public int getCode() { |
661 |
// TODO Auto-generated method stub
|
662 |
return epsg_code;
|
663 |
} |
664 |
|
665 |
/**
|
666 |
*
|
667 |
*/
|
668 |
public Rectangle2D getExtent(Rectangle2D extent, double scale, double wImage, double hImage, double changeUnits, double dpi) { |
669 |
double w =0; |
670 |
double h =0; |
671 |
double wExtent =0; |
672 |
double hExtent =0; |
673 |
if (isProjected()) {
|
674 |
w = ((wImage / dpi) * 2.54);
|
675 |
h = ((hImage / dpi) * 2.54);
|
676 |
wExtent =w * scale/ changeUnits; |
677 |
hExtent =h * scale/ changeUnits; |
678 |
|
679 |
}else {
|
680 |
w = ((wImage / dpi) * 2.54);
|
681 |
h = ((hImage / dpi) * 2.54);
|
682 |
wExtent =(w*scale)/ (changeUnits*1852.0*60.0); |
683 |
hExtent =(h*scale)/ (changeUnits*1852.0*60.0); |
684 |
} |
685 |
double xExtent = extent.getCenterX() - wExtent/2; |
686 |
double yExtent = extent.getCenterY() - hExtent/2; |
687 |
Rectangle2D rec=new Rectangle2D.Double(xExtent,yExtent,wExtent,hExtent); |
688 |
return rec;
|
689 |
} |
690 |
|
691 |
/**
|
692 |
* @return
|
693 |
*/
|
694 |
public boolean isTransInTarget() { |
695 |
return targetNad;
|
696 |
} |
697 |
|
698 |
/**
|
699 |
* @param targetNad
|
700 |
*/
|
701 |
public void setTransInTarget(boolean targetNad) { |
702 |
this.targetNad = targetNad;
|
703 |
} |
704 |
|
705 |
/**
|
706 |
*
|
707 |
* @return
|
708 |
*/
|
709 |
public String getProj4() { |
710 |
return proj4;
|
711 |
} |
712 |
|
713 |
public String getFullCode() { |
714 |
if (!TransParam.equals("")) |
715 |
if(isTransInTarget())
|
716 |
return getAbrev()+":"+"proj@"+TransParam+"@1"; |
717 |
else
|
718 |
return getAbrev()+":"+"proj@"+TransParam+"@0"; |
719 |
else
|
720 |
return getAbrev();
|
721 |
} |
722 |
} |