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