Revision 11304

View differences:

branches/F2/libraries/libJCRS/src-test/es/idr/crs/crsGT/CrsGTTest.java
1 1
package es.idr.crs.crsGT;
2 2

  
3 3
import org.cresques.cts.IProjection;
4
import org.gvsig.crs.ICrs;
5
import org.gvsig.crs.repository.EpsgRepository;
4 6
import org.gvsig.crs.repository.EpsgRepositoryGT;
5 7

  
6 8
public class CrsGTTest {
......
12 14
		EpsgRepositoryGT repo = new EpsgRepositoryGT();
13 15
		IProjection crs = repo.getCrs("EPSG:23032");
14 16
		System.out.println(crs.getAbrev());
17
		System.out.println(((ICrs)crs).getCode()+"\n\n");
18
		
19
		EpsgRepository repo2 = new EpsgRepository();
20
		IProjection crs2 = repo2.getCrs("23032");
21
		System.out.println(crs2.getAbrev());
22
		System.out.println(((ICrs)crs2).getCode());
15 23
	}
16 24

  
17 25
}
branches/F2/libraries/libJCRS/src/org/gvsig/crs/CrsGT.java
53 53
import org.geotools.referencing.crs.AbstractDerivedCRS;
54 54
import org.geotools.referencing.crs.AbstractSingleCRS;
55 55
import org.geotools.referencing.datum.DefaultGeodeticDatum;
56
import org.gvsig.crs.proj.CrsProj;
57
import org.gvsig.crs.proj.CrsProjException;
58
import org.gvsig.crs.proj.JNIBaseCrs;
59
import org.gvsig.crs.proj.OperationCrsException;
56 60
import org.opengis.referencing.crs.CoordinateReferenceSystem;
57 61

  
58 62
/**
......
62 66
 *
63 67
 */
64 68
public class CrsGT implements ICrs {
69
	private static final Color basicGridColor = new Color(64, 64, 64, 128);
65 70
	
66
	CoordinateReferenceSystem crsGT;
71
	private CoordinateReferenceSystem 	crsGT			= null;
72
	private boolean 					targetNad 		= false;
73
	private String 						proj4 			= null;
74
	private Color 						gridColor 		= basicGridColor;
75
	private String 						nad				= null;
67 76
	
68 77
	/**
69 78
	 * Constructor a partir de un CoordinateReferenceSystem
......
75 84
	}
76 85

  
77 86
	public int getCode() {
78
		// TODO Auto-generated method stub
79
		return 0;
87
		return Integer.valueOf(getAbrev().split(":")[1]).intValue();
80 88
	}
81 89

  
82 90
	public CrsWkt getCrsWkt() {
......
90 98
	}
91 99

  
92 100
	public void setNadGrid(String nad) {
93
		// TODO Auto-generated method stub
101
		this.nad = nad;
94 102

  
95 103
	}
96 104

  
......
121 129
	}
122 130

  
123 131
	public ICoordTrans getCT(IProjection dest) {
124
		// TODO Auto-generated method stub
125
		return null;
132
		COperation operation = null;
133
		CrsGT crsDest = (CrsGT)dest;
134
		try {
135
			operation = new COperation(this, (ICrs)dest);
136
		} catch (CrsException e) {
137
			// TODO Auto-generated catch block
138
			e.printStackTrace();
139
		}
140
		
141
		if (!getNadGrid().equals("")){
142
			if (isTargetNad())
143
				operation.setNadCrsProj(new CrsProj(crsDest.getProj4()+getNadGrid()), true);
144
			else
145
				operation.setNadCrsProj(new CrsProj(getProj4()+getNadGrid()), false);
146
			
147
			return operation;
148
		}
149
		
150
		return operation;		
126 151
	}
127 152

  
128 153
	public IDatum getDatum() {
......
138 163
	}
139 164

  
140 165
	public Color getGridColor() {
141
		// TODO Auto-generated method stub
142
		return null;
166
		return gridColor;
143 167
	}
144 168

  
145 169
	public double getScale(double minX, double maxX, double width, double dpi) {
146
		// TODO Auto-generated method stub
147
		return 0;
170
		double scale = 0D;
171
        if (!isProjected()) { // Es geogr?fico; calcula la escala.
172
            scale = ((maxX - minX) * // grados
173

  
174
            // 1852.0 metros x minuto de meridiano
175
            (dpi / 2.54 * 100.0 * 1852.0 * 60.0)) / // px / metro
176
                    width; // pixels
177
        }
178
        else{
179
        	 scale = ((maxX - minX) * // metros
180
                    (dpi / 2.54 * 100.0)) / // px / metro
181
                    width; // pixels
182
        }
183
        return scale;
148 184
	}
149 185

  
150 186
	public boolean isProjected() {
......
155 191
	}
156 192

  
157 193
	public void setGridColor(Color c) {
158
		// TODO Auto-generated method stub
159

  
194
		gridColor = c;
160 195
	}
161 196

  
162 197
	public Point2D toGeo(Point2D pt) {
163
		// TODO Auto-generated method stub
164
		return null;
198
		if (isProjected()){
199
			double x[] = {pt.getX()};
200
			double y[] = {pt.getY()};
201
			double z[] = {0D};
202
			try {
203
				JNIBaseCrs.operate( x , y, z,
204
						crsProj4,crsBase);
205
			} catch (OperationCrsException e) {
206
				// TODO Auto-generated catch block
207
				e.printStackTrace();
208
			} catch (CrsProjException e) {
209
				// TODO Auto-generated catch block
210
				e.printStackTrace();
211
			}
212
			return new Point2D.Double(x[0],y[0]);
213
		}
214
		else
215
			return pt;
165 216
	}
166 217

  
218
	public String getNadGrid() {
219
		return nad;
220
	}
221
	
222
	/**
223
	 * @return
224
	 */
225
	public boolean isTargetNad() {
226
		return targetNad;
227
	}
228
	
229
	/**
230
	 * 
231
	 * @return
232
	 */
233
	public String getProj4() {
234
		return proj4;
235
	}
236

  
237
	public CoordinateReferenceSystem getCrsGT() {
238
		return crsGT;
239
	}
240

  
167 241
}
branches/F2/libraries/libJCRS/src/org/gvsig/crs/Crs.java
49 49
import org.cresques.cts.IDatum;
50 50
import org.cresques.cts.IProjection;
51 51
import org.cresques.geo.ViewPortData;
52
import org.geotools.referencing.CRS;
53 52
import org.gvsig.crs.proj.CrsProj;
54 53
import org.gvsig.crs.proj.CrsProjException;
55 54
import org.gvsig.crs.proj.JNIBaseCrs;
56 55
import org.gvsig.crs.proj.OperationCrsException;
57
import org.opengis.referencing.FactoryException;
58
import org.opengis.referencing.NoSuchAuthorityCodeException;
59 56
import org.opengis.referencing.crs.CoordinateReferenceSystem;
60 57

  
61 58
import es.gva.cit.jogr.CrsGdalException;
branches/F2/libraries/libJCRS/src/org/gvsig/crs/ICrs.java
64 64
	String getWKT();
65 65
	
66 66
	/**
67
	 * Devuelve la cadena con el par?metro nadgrid para proj4
68
	 * 
69
	 * @return
70
	 */
71
	String getNadGrid();
72
	
73
	/**
67 74
	 * M?todo para la aplicaci?n de la propiedad de nadgrids
68 75
	 * sobre el CRS destino o fuente 
69 76
	 * @param nad

Also available in: Unified diff