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