Revision 8676 trunk/libraries/libJCRS/src/org/gvsig/crs/COperation.java

View differences:

COperation.java
5 5

  
6 6
import org.cresques.cts.ICoordTrans;
7 7
import org.cresques.cts.IProjection;
8
import org.gvsig.crs.proj.CrsProj;
8 9
import org.gvsig.crs.proj.CrsProjException;
9 10
import org.gvsig.crs.proj.JNIBaseCrs;
10 11
import org.gvsig.crs.proj.OperationCrsException;
......
14 15
public class COperation implements ICOperation {
15 16
	private Crs sourceCrs;
16 17
	private Crs targetCrs;
18
	private CrsProj nadCrsProj = null;
19
	private boolean nadInTarget;
17 20
	public COperation(ICrs from, ICrs to) throws CrsException {
18 21
		sourceCrs = (Crs) from;
19 22
		targetCrs = (Crs) to;
......
31 34
		double x[] = {pt.getX()};
32 35
		double y[] = {pt.getY()};
33 36
		double z[] = {0D};
37
		int errno = 0;
34 38
		try {
35
			JNIBaseCrs.operate( x , y, z,
36
				sourceCrs.getCrsEpsg(), targetCrs.getCrsEpsg());
39
			if (nadCrsProj != null){
40
				if (nadInTarget)
41
					errno = JNIBaseCrs.operate( x , y, z,sourceCrs.getCrsProj(), nadCrsProj);
42
				else
43
					errno = JNIBaseCrs.operate( x , y, z,nadCrsProj,targetCrs.getCrsProj());
44
				if (errno != -38)
45
					return new Point2D.Double(x[0],y[0]);
46
			}
47
			
48
			// Si el punto estaba fuera del ?mbito del nadgrid operamos sin nadgrid (convertimos)
49
			x[0] = pt.getX();
50
			y[0] = pt.getY();
51
			z[0] = 0D;
52
			JNIBaseCrs.operate( x , y, z,sourceCrs.getCrsProj(), targetCrs.getCrsProj());
53
			return new Point2D.Double(x[0],y[0]);
54
			
37 55
		} catch (OperationCrsException e) {
38 56
			throw new CrsException(e);
39 57
		} catch (CrsProjException e) {
......
43 61
	//	if(!targetCrs.isProjected())
44 62
	//		return new Point2D.Double(x[0]*((180)/Math.PI),y[0]*((180)/Math.PI));
45 63
	//	else
46
			return new Point2D.Double(x[0],y[0]);
47 64
	}
48 65

  
49 66
	public double [] operate(double []ptOrig) throws CrsException {
50 67
		double x[] = {ptOrig[0]};
51 68
		double y[] = {ptOrig[1]};
52 69
		double z[] = {ptOrig[2]};
70
		int errno = 0;
53 71
		try {
54
			JNIBaseCrs.operate(x, y, z,
55
				sourceCrs.getCrsEpsg(), targetCrs.getCrsEpsg());
72
			if (nadCrsProj != null){
73
				if (nadInTarget)
74
					errno = JNIBaseCrs.operate( x , y, z,sourceCrs.getCrsProj(), nadCrsProj);
75
				else
76
					errno = JNIBaseCrs.operate( x , y, z,nadCrsProj,targetCrs.getCrsProj());
77
				if (errno != -38){
78
					double ptDest[] = {x[0], y[0], z[0]};
79
					return ptDest;
80
				}
81
			}
82
			
83
			// Si el punto estaba fuera del ?mbito del nadgrid operamos sin nadgrid (convertimos)
84
			 x[0] = ptOrig[0];
85
			 y[0] = ptOrig[1];
86
			 z[0] = ptOrig[2];
87
			 JNIBaseCrs.operate(x, y, z,sourceCrs.getCrsProj(), targetCrs.getCrsProj());
88
			 double ptDest[] = {x[0], y[0], z[0]};
89
			 return ptDest;
56 90
		} catch (OperationCrsException e) {
57 91
			throw new CrsException(e);
58 92
		} catch (CrsProjException e) {
59 93
			throw new CrsException(e);
60 94
		}
61

  
62
		double ptDest[] = {x[0], y[0], z[0]};
63
		return ptDest;
64 95
	}
65 96

  
66 97
	public IProjection getPOrig() {
......
105 136
		return null;
106 137
	}
107 138
	
139
	public void setNadCrsProj(CrsProj nadCrs, boolean inTarget){
140
		this.nadInTarget = inTarget;
141
		this.nadCrsProj = nadCrs;
142
	}
108 143
}

Also available in: Unified diff