svn-gvsig-desktop / trunk / libraries / libJCRS / src / org / gvsig / crs / COperation.java @ 8405
History | View | Annotate | Download (2.53 KB)
1 |
package org.gvsig.crs; |
---|---|
2 |
|
3 |
import java.awt.geom.Point2D; |
4 |
import java.awt.geom.Rectangle2D; |
5 |
|
6 |
import org.cresques.cts.ICoordTrans; |
7 |
import org.cresques.cts.IProjection; |
8 |
import org.gvsig.crs.proj.CrsProjException; |
9 |
import org.gvsig.crs.proj.OperationCrs; |
10 |
import org.gvsig.crs.proj.OperationCrsException; |
11 |
|
12 |
public class COperation implements ICOperation { |
13 |
private Crs sourceCrs;
|
14 |
private Crs targetCrs;
|
15 |
public COperation(ICrs from, ICrs to) throws CrsException { |
16 |
sourceCrs = (Crs) from; |
17 |
targetCrs = (Crs) to; |
18 |
} |
19 |
|
20 |
public ICrs getSource() {
|
21 |
return sourceCrs;
|
22 |
} |
23 |
|
24 |
public ICrs getTarget() {
|
25 |
return targetCrs;
|
26 |
} |
27 |
|
28 |
public Point2D operate(Point2D pt) throws CrsException { |
29 |
double x[] = {pt.getX()}; |
30 |
double y[] = {pt.getY()}; |
31 |
double z[] = {0D}; |
32 |
try {
|
33 |
OperationCrs.operate( x , y, z, |
34 |
sourceCrs.getCrsEpsg(), targetCrs.getCrsEpsg()); |
35 |
} catch (OperationCrsException e) {
|
36 |
throw new CrsException(e); |
37 |
} catch (CrsProjException e) {
|
38 |
throw new CrsException(e); |
39 |
} |
40 |
// System.out.println("x="+x[0]+"y="+y[0]);
|
41 |
// if(!targetCrs.isProjected())
|
42 |
// return new Point2D.Double(x[0]*((180)/Math.PI),y[0]*((180)/Math.PI));
|
43 |
// else
|
44 |
return new Point2D.Double(x[0],y[0]); |
45 |
} |
46 |
|
47 |
public double [] operate(double []ptOrig) throws CrsException { |
48 |
double x[] = {ptOrig[0]}; |
49 |
double y[] = {ptOrig[1]}; |
50 |
double z[] = {ptOrig[2]}; |
51 |
try {
|
52 |
OperationCrs.operate(x, y, z, |
53 |
sourceCrs.getCrsEpsg(), targetCrs.getCrsEpsg()); |
54 |
} catch (OperationCrsException e) {
|
55 |
throw new CrsException(e); |
56 |
} catch (CrsProjException e) {
|
57 |
throw new CrsException(e); |
58 |
} |
59 |
|
60 |
double ptDest[] = {x[0], y[0], z[0]}; |
61 |
return ptDest;
|
62 |
} |
63 |
|
64 |
public IProjection getPOrig() {
|
65 |
return null; |
66 |
} |
67 |
|
68 |
public IProjection getPDest() {
|
69 |
return null; |
70 |
} |
71 |
|
72 |
public Point2D convert(Point2D ptOrig, Point2D ptDest) { |
73 |
try {
|
74 |
ptDest = operate(ptOrig); |
75 |
} catch (CrsException e) {
|
76 |
// TODO LWS implementar una gesti?n completa de los errores.
|
77 |
e.printStackTrace(); |
78 |
} |
79 |
return ptDest;
|
80 |
} |
81 |
|
82 |
public Rectangle2D convert(Rectangle2D rect) { |
83 |
Point2D pt1 = new Point2D.Double(rect.getMinX(), rect.getMinY()); |
84 |
Point2D pt2 = new Point2D.Double(rect.getMaxX(), rect.getMaxY()); |
85 |
try {
|
86 |
pt1 = operate(pt1); |
87 |
pt2 = operate(pt2); |
88 |
} catch (CrsException e) {
|
89 |
// TODO LWS implementar una gesti?n completa de los errores.
|
90 |
e.printStackTrace(); |
91 |
} |
92 |
rect = new Rectangle2D.Double(); |
93 |
rect.setFrameFromDiagonal(pt1, pt2); |
94 |
return rect;
|
95 |
} |
96 |
|
97 |
public ICoordTrans getInverted() {
|
98 |
try {
|
99 |
return new COperation(targetCrs, sourceCrs); |
100 |
} catch (CrsException e) {
|
101 |
e.printStackTrace(); |
102 |
} |
103 |
return null; |
104 |
} |
105 |
|
106 |
} |