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