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