Revision 359

View differences:

org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.app.jcrs/org.gvsig.projection.app.jcrs.common/src/main/assembly/gvsig-plugin-package.xml
61 61
            <include>javax.units:jsr108</include>
62 62
            <include>java3d:vecmath</include>
63 63
            <include>org.opengis:geoapi</include>
64
            
64
            <include>org.gdal:gdal</include>
65 65
            <include>org.gvsig:org.gvsig.projection.api</include>
66 66
            <include>org.gvsig:org.gvsig.projection.cresques.ui</include>
67 67
            <include>org.gvsig:org.gvsig.projection.cresques.impl</include>
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.app.jcrs/org.gvsig.projection.app.jcrs.common/pom.xml
13 13
        - Convertion of coordinates (no datum changing)
14 14
        - Transformation of coordinates (datum changing) from EPSG, manual, recent, compound and grid (.gsb extension)
15 15
    </description>
16
   
16

  
17 17
    <parent>
18 18
        <groupId>org.gvsig</groupId>
19 19
        <artifactId>org.gvsig.projection.app.jcrs</artifactId>
......
21 21
    </parent>
22 22

  
23 23
    <properties>
24
        <gvsig.package.info.name>CRS: CRS management (Proj4/Geotools based, Native)</gvsig.package.info.name>    
24
        <gvsig.package.info.name>CRS: CRS management (Proj4/Geotools based, Native)</gvsig.package.info.name>
25 25
        <gvsig.package.info.state>testing</gvsig.package.info.state>
26 26
        <gvsig.package.info.official>true</gvsig.package.info.official>
27 27
        <gvsig.package.info.operatingSystem>all</gvsig.package.info.operatingSystem>
......
30 30
        <gvsig.package.info.categories />
31 31
        <gvsig.package.info.poolURL>http://devel.gvsig.org/download/projects/gvsig-jcrs/pool</gvsig.package.info.poolURL>
32 32
        <gvsig.install.plugin>false</gvsig.install.plugin>
33
        <gvsig.install.plugin.package>false</gvsig.install.plugin.package>    
33
        <gvsig.install.plugin.package>false</gvsig.install.plugin.package>
34 34
    </properties>
35 35

  
36 36
    <dependencies>
......
75 75
            <artifactId>jsr108</artifactId>
76 76
            <scope>compile</scope>
77 77
        </dependency>
78
    
79
    
78

  
79

  
80 80
        <dependency>
81 81
            <groupId>org.geotools</groupId>
82 82
            <artifactId>gt2-main</artifactId>
......
96 96
            <artifactId>hsqldb</artifactId>
97 97
            <scope>compile</scope>
98 98
        </dependency>
99
    
99

  
100 100
        <!--  Runtime dependencies -->
101 101
        <!--  Need to include in the assembly -->
102 102
        <dependency>
......
104 104
            <artifactId>org.gvsig.projection.cresques.impl</artifactId>
105 105
            <scope>runtime</scope>
106 106
        </dependency>
107
        <!-- 
107
        <!--
108 108
        <dependency>
109 109
          <groupId>org.gvsig</groupId>
110 110
          <artifactId>gt2-epsg-esri</artifactId>
......
131 131
            <artifactId>vecmath</artifactId>
132 132
            <scope>runtime</scope>
133 133
        </dependency>
134

  
135
        <dependency>
136
           <groupId>org.gdal</groupId>
137
           <artifactId>gdal</artifactId>
138
        </dependency>
139

  
134 140
    </dependencies>
135 141

  
136 142
    <build>
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/CrsGT.java
55 55
import org.opengis.referencing.crs.CoordinateReferenceSystem;
56 56
import org.slf4j.Logger;
57 57
import org.slf4j.LoggerFactory;
58

  
58 59
import org.gvsig.crs.proj.CrsProj;
59 60
import org.gvsig.crs.proj.CrsProjException;
60
import org.gvsig.crs.proj.JNIBaseCrs;
61 61
import org.gvsig.crs.proj.OperationCrsException;
62 62
import org.gvsig.fmap.crs.CRSFactory;
63 63

  
64 64
/**
65 65
 * Clase que representa un CRS basado en GeoTools/GeoApi.
66
 * 
66
 *
67 67
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
68 68
 *
69 69
 */
70 70
public class CrsGT implements ICrs {
71
	private static final Logger logger = LoggerFactory.getLogger(CrsGT.class); 
71
	private static final Logger logger = LoggerFactory.getLogger(CrsGT.class);
72 72

  
73 73
	private static final Color basicGridColor = new Color(64, 64, 64, 128);
74
	
74

  
75 75
	/**
76 76
	 * CRS GeoApi. Nucleo de la clare CrsGT.
77 77
	 */
78 78
	private CoordinateReferenceSystem 	crsGT			= null;
79
	
79

  
80 80
	/**
81 81
	 *Cadena proj4
82 82
	 */
83 83
	private String 						proj4String 	= null;
84
	
84

  
85 85
	private Color 						gridColor 		= basicGridColor;
86
	
86

  
87 87
	/**
88 88
	 * Par?metros de transformaci?n para el CRS fuente en formato proj4.
89 89
	 */
90 90
	private String 						sourceTrParams			= null;
91
	
91

  
92 92
	/**
93 93
	 * Par?metros de transformaci?n para el CRS destino en formato proj4.
94 94
	 */
95 95
	private String 						targetTrParams			= null;
96
	
96

  
97 97
	/**
98 98
	 * CRS operable con proj4.
99 99
	 */
100 100
	private CrsProj 					crsProj			= null;
101
	
101

  
102 102
	/**
103 103
	 * CRS Base operable con proj4.
104 104
	 */
105 105
	private CrsProj 					crsProjBase		= null;
106
	
106

  
107 107
	/**
108 108
	 * Provisional, hasta que se elimine getCrsWkt de ICrs.
109 109
	 */
110 110
	private CrsWkt 						crsWkt			= null;
111
	
111

  
112 112
	/**
113 113
	 * Conversor de CRSs a cadenas proj4.
114 114
	 */
115 115
	private Proj4 						proj4			= null;
116
	
117
	
118
	
116

  
117

  
118

  
119 119
	/**
120 120
	 * Constructor a partir de un CoordinateReferenceSystem
121
	 * 
121
	 *
122 122
	 * @param crsGT
123
	 * @throws CrsProjException 
123
	 * @throws CrsProjException
124 124
	 */
125 125
	public CrsGT(CoordinateReferenceSystem crsGT){
126 126
		this.crsGT = crsGT;
......
144 144
		this.sourceTrParams = SourceParams;
145 145
		this.targetTrParams = TargetParams;
146 146
	}
147
	
147

  
148 148
	/**
149 149
	 * Devuelve los parametros de la transformacion del crs fuente
150 150
	 * @return
......
152 152
	public String getSourceTransformationParams() {
153 153
		return this.sourceTrParams;
154 154
	}
155
	
155

  
156 156
	/**
157 157
	 * Devuelve los parametros de la transformacion del crs destino
158 158
	 * @return
......
175 175
		return null;
176 176
	}
177 177

  
178
	public String getAbrev() {		
178
	public String getAbrev() {
179 179
		return ((AbstractSingleCRS)crsGT).getIdentifiers().iterator().next().toString();
180 180
	}
181 181

  
182 182
	public ICoordTrans getCT(IProjection dest) {
183
		
183

  
184 184
		try {
185 185
			if (dest == this)
186 186
				return null;
187 187
			COperation operation = null;
188
			if(((ICrs)dest).getSourceTransformationParams() != null || ((ICrs)dest).getTargetTransformationParams() != null) 
188
			if(((ICrs)dest).getSourceTransformationParams() != null || ((ICrs)dest).getTargetTransformationParams() != null)
189 189
				operation = new COperation(this, (ICrs)dest,((ICrs)dest).getTargetTransformationParams(),((ICrs)dest).getSourceTransformationParams());
190 190
			else
191 191
				operation = new COperation(this, (ICrs)dest,sourceTrParams,targetTrParams);
......
193 193
		}catch (CrsException e) {
194 194
            throw new RuntimeException(e);
195 195
		}
196
		
196

  
197 197
		/*
198 198
		try {
199 199
			operation = new COperation(this, (ICrs)dest);
......
201 201
			// TODO Auto-generated catch block
202 202
			logger...
203 203
		}
204
		
204

  
205 205
		if (!getTransformationParams().equals("")){
206 206
			if (isParamsInTarget())
207 207
				operation.setParamsCrsProj(new CrsProj(crsDest.getProj4String()+getTransformationParams()), true);
......
209 209
				operation.setParamsCrsProj(new CrsProj(getProj4String()+getTransformationParams()), false);
210 210
			return operation;
211 211
		}
212
		
212

  
213 213
		return operation;	*/
214 214
	}
215 215

  
......
240 240
//        }
241 241
        return scale;
242 242
	}
243
	
243

  
244 244
	public double getScale(double minX, double maxX, double minY, double maxY, double width, double dpi) {
245
		
245

  
246 246
		double scale = 0D;
247 247
		double incX = (maxX-minX);
248
		
248

  
249 249
		if (!isProjected()) {
250 250
			double a = getDatum().getESemiMajorAxis();
251 251
			double invF = getDatum().getEIFlattening();
252 252
			double meanY = (minY+maxY)/2.0;
253 253
			double radius = 0.0;
254
			
255
			
254

  
255

  
256 256
			if (invF == Double.POSITIVE_INFINITY){
257 257
				radius = a;
258 258
			}
......
262 262
			}
263 263
			incX *= Math.PI/180.0*radius;
264 264
		}
265
			
265

  
266 266
		scale = (incX * // metros
267 267
				(dpi / 2.54 * 100.0)) / // px / metro
268 268
					width; // pixels
269
		
269

  
270 270
        return scale;
271 271
	}
272 272

  
......
287 287
			double y[] = {pt.getY()};
288 288
			double z[] = {0D};
289 289
			try {
290
				JNIBaseCrs.operate( x , y, z,
290
			    CrsProj.operate( x , y, z,
291 291
						getCrsProj(),getCrsProjBase());
292 292
			} catch (OperationCrsException e) {
293 293
                throw new RuntimeException(e);
......
297 297
		else
298 298
			return pt;
299 299
	}
300
	
300

  
301 301
	/**
302 302
	 * @param targetParam
303 303
	 */
304 304
	/*public void setParamsInTarget(boolean targetParam) {
305 305
		this.paramsInTarget = targetParam;
306 306
	}*/
307
	
307

  
308 308
	/**
309
	 * 
309
	 *
310 310
	 * @return Cadena proj4 Correspondiente al CRS.
311
	 * @throws CrsException 
311
	 * @throws CrsException
312 312
	 */
313 313
	public String getProj4String() throws CrsException {
314 314
		if (proj4String == null)
315 315
		proj4String = getProj4().exportToProj4(crsGT);
316
			
316

  
317 317
		return proj4String;
318 318
	}
319 319

  
320 320
	public CoordinateReferenceSystem getCrsGT() {
321 321
		return crsGT;
322 322
	}
323
	
323

  
324 324
	public CrsProj getCrsProj() {
325 325
		if (crsProj == null)
326 326
			try {
327 327
				crsProj = new CrsProj(getProj4String());
328 328
			} catch (CrsException e) {
329 329
	            throw new RuntimeException(e);
330
			} 
330
			}
331 331
		return crsProj;
332 332
	}
333 333

  
......
352 352
			}
353 353
		return proj4;
354 354
	}
355
	
355

  
356 356
	/**
357 357
	 * @return Authority:code:proj@Sourceparam@TargerParam@
358 358
	 */
......
365 365
			sourceParams = sourceTrParams;
366 366
		if (targetTrParams != null)
367 367
			targetParams = targetTrParams;
368
		
368

  
369 369
		return getAbrev()+":proj@"+sourceParams+"@"+targetParams;
370 370
	}
371 371

  
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/COperation.java
45 45

  
46 46
import org.cresques.cts.ICoordTrans;
47 47
import org.cresques.cts.IProjection;
48
import org.gvsig.crs.proj.CrsProj;
49
import org.gvsig.crs.proj.JNIBaseCrs;
50
import org.gvsig.crs.proj.OperationCrsException;
48
import org.gdal.gdal.gdal;
49
import org.gdal.osr.CoordinateTransformation;
51 50
import org.slf4j.Logger;
52 51
import org.slf4j.LoggerFactory;
53 52

  
53
import org.gvsig.crs.proj.CrsProj;
54
import org.gvsig.crs.proj.OperationCrsException;
55

  
54 56
/**
55 57
 * Clase que implementa las operaciones de tranformacion de coordenadas entre
56 58
 * dos CRSs.
......
63 65
// public class COperation implements ICOperation {
64 66
public class COperation implements ICoordTrans {
65 67

  
66
	private static final Logger logger = LoggerFactory
67
			.getLogger(COperation.class);
68
	/**
69
	 * CRS Fuente
70
	 */
71
	private ICrs sourceCrs;
72
	/**
73
	 * CRS Destino
74
	 */
75
	private ICrs targetCrs;
76
	/**
77
	 * CRS con los par?metros de transformaci?n (puede representar el CRS fuente
78
	 * o destino, dependiendo de <code>paramsInTarget</code>).
79
	 */
80
	private CrsProj paramsCrsProj = null;
81
	/**
82
	 * Indica si los par?metros de transformaci?n van asociados al CRS fuente (
83
	 * <code>false</code>) o al destino (<code>true</code>)
84
	 */
85
	private boolean paramsInTarget;
68
    private static final Logger logger = LoggerFactory.getLogger(COperation.class);
69
    /**
70
     * CRS Fuente
71
     */
72
    private ICrs sourceCrs;
73
    /**
74
     * CRS Destino
75
     */
76
    private ICrs targetCrs;
77
    /**
78
     * CRS con los par?metros de transformaci?n (puede representar el CRS fuente
79
     * o destino, dependiendo de <code>paramsInTarget</code>).
80
     */
81
    private CrsProj paramsCrsProj = null;
82
    /**
83
     * Indica si los par?metros de transformaci?n van asociados al CRS fuente (
84
     * <code>false</code>) o al destino (<code>true</code>)
85
     */
86
    private boolean paramsInTarget;
86 87

  
87
	/**
88
	 * par?metros de transformaci?n para el CRS fuente en el formato proj4
89
	 */
90
	private String sourceParams = null;
88
    /**
89
     * par?metros de transformaci?n para el CRS fuente en el formato proj4
90
     */
91
    private String sourceParams = null;
91 92

  
92
	/**
93
	 * par?metros de transformaci?n para el CRS destino en el formato proj4
94
	 */
95
	private String targetParams = null;
93
    /**
94
     * par?metros de transformaci?n para el CRS destino en el formato proj4
95
     */
96
    private String targetParams = null;
96 97

  
97
	private CrsProj source = null;
98
    private CrsProj source = null;
98 99

  
99
	private CrsProj target = null;
100
    private CrsProj target = null;
100 101

  
101
	/**
102
	 * Constructor.
103
	 *
104
	 * @param from
105
	 *            CRS fuente.
106
	 * @param to
107
	 *            CRS destino.
108
	 * @throws CrsException
109
	 */
110
	public COperation(ICrs from, ICrs to) throws CrsException {
111
		sourceCrs = from;
112
		targetCrs = to;
113
		source = sourceCrs.getCrsProj();
114
		target = targetCrs.getCrsProj();
115
	}
102
    private CoordinateTransformation coordinateTransformation = null;
116 103

  
117
	/**
118
	 * Construcctor.
119
	 *
120
	 * @param sourceCrs
121
	 *            CRS fuente.
122
	 * @param targetCrs
123
	 *            CRS destino.
124
	 * @param sourceParams
125
	 *            Par?metros de transformaci?n para la fuente (en formato
126
	 *            proj4).
127
	 * @param targetParams
128
	 *            Par?metros de transformaci?n para el destino (en formato
129
	 *            proj4).
130
	 * @throws CrsException
131
	 */
132
	public COperation(ICrs sourceCrs, ICrs targetCrs, String sourceParams,
133
			String targetParams) throws CrsException {
134
		this.sourceCrs = sourceCrs;
135
		this.targetCrs = targetCrs;
136
		this.sourceParams = sourceParams;
137
		this.targetParams = targetParams;
104
    /**
105
     * Constructor.
106
     *
107
     * @param from
108
     *            CRS fuente.
109
     * @param to
110
     *            CRS destino.
111
     * @throws CrsException
112
     */
113
    public COperation(ICrs from, ICrs to) throws CrsException {
114
        sourceCrs = from;
115
        targetCrs = to;
116
        source = sourceCrs.getCrsProj();
117
        target = targetCrs.getCrsProj();
118
    }
138 119

  
139
		if (sourceParams != null)
140
			source = new CrsProj(sourceCrs.getProj4String() + sourceParams);
141
		else
142
			source = sourceCrs.getCrsProj();
143
		if (targetParams != null)
144
			target = new CrsProj(targetCrs.getProj4String() + targetParams);
145
		else
146
			target = targetCrs.getCrsProj();
147
	}
120
    /**
121
     * Construcctor.
122
     *
123
     * @param sourceCrs
124
     *            CRS fuente.
125
     * @param targetCrs
126
     *            CRS destino.
127
     * @param sourceParams
128
     *            Par?metros de transformaci?n para la fuente (en formato
129
     *            proj4).
130
     * @param targetParams
131
     *            Par?metros de transformaci?n para el destino (en formato
132
     *            proj4).
133
     * @throws CrsException
134
     */
135
    public COperation(ICrs sourceCrs, ICrs targetCrs, String sourceParams, String targetParams) throws CrsException {
136
        this.sourceCrs = sourceCrs;
137
        this.targetCrs = targetCrs;
138
        this.sourceParams = sourceParams;
139
        this.targetParams = targetParams;
148 140

  
149
	/**
150
	 * Realiza la operaci?n de transformaci?n sobre un punto. Si exiten
151
	 * par?metros de transformaci?n (<code>paramsCrsProj</code>) se utilizan en
152
	 * lugar del CRS fuente o destino, seg?n indique <code>paramsInTarget</code>
153
	 * .
154
	 *
155
	 * @throws OperationCrsException
156
	 *
157
	 */
158
	private Point2D operate(Point2D pt) throws CrsException,
159
			OperationCrsException {
160
		double x[] = { pt.getX() };
161
		double y[] = { pt.getY() };
162
		double z[] = { 0D };
163
		int errno = 0;
141
        if (sourceParams != null)
142
            source = new CrsProj(sourceCrs.getProj4String() + sourceParams);
143
        else
144
            source = sourceCrs.getCrsProj();
145
        if (targetParams != null)
146
            target = new CrsProj(targetCrs.getProj4String() + targetParams);
147
        else
148
            target = targetCrs.getCrsProj();
149
    }
164 150

  
165
		try {
166
			errno = JNIBaseCrs.operate(x, y, z, source, target);
167
		} catch (OperationCrsException e) {
168
			// Parche para arreglar posible error al transformar de latlong a proyectadas cuando la y es +/- 90
169
			if (e.getErrno() == -20) {
170
				source.reloadCrs();
171
				target.reloadCrs();
172
				if (!sourceCrs.isProjected() && targetCrs.isProjected()) {
173
					if (Math.abs((pt.getY() - 90.0)) < 0.000000001) {
174
						x[0] = pt.getX();
175
						y[0] = 89.99999999;
176
						z[0] = 0D;
177
						errno = JNIBaseCrs.operate(x, y, z, source, target);
178
					} else if (Math.abs(pt.getY() + 90.0) < 0.000000001) {
179
						x[0] = pt.getX();
180
						y[0] = -89.99999999;
181
						z[0] = 0D;
182
						errno = JNIBaseCrs.operate(x, y, z, source, target);
183
					}
184
				}
185
			}
186
		}
187
		if (errno != -38) // "failed to load NAD27-83 correction file"
188
							// (pj_strerrno.c)
189
			return new Point2D.Double(x[0], y[0]);
190
		else {
191
			x[0] = pt.getX();
192
			y[0] = pt.getY();
193
			z[0] = 0D;
194
			try {
195
				errno = JNIBaseCrs.operate(x, y, z, sourceCrs.getCrsProj(),
196
						targetCrs.getCrsProj());
197
			} catch (OperationCrsException e) {
198
				if (e.getErrno() == -20) {
199
					if (!sourceCrs.isProjected() && targetCrs.isProjected()) {
200
						if (Math.abs((pt.getY() - 90.0)) < 0.000000001) {
201
							x[0] = pt.getX();
202
							y[0] = 89.99999999;
203
							z[0] = 0D;
204
							errno = JNIBaseCrs.operate(x, y, z,
205
									sourceCrs.getCrsProj(),
206
									targetCrs.getCrsProj());
207
						} else if (Math.abs(pt.getY() + 90.0) < 0.000000001) {
208
							x[0] = pt.getX();
209
							y[0] = -89.99999999;
210
							z[0] = 0D;
211
							errno = JNIBaseCrs.operate(x, y, z,
212
									sourceCrs.getCrsProj(),
213
									targetCrs.getCrsProj());
214
						}
215
					}
216
				}
217
			}
218
			return new Point2D.Double(x[0], y[0]);
219
		}
151
    /**
152
     * Realiza la operaci?n de transformaci?n sobre un punto. Si exiten
153
     * par?metros de transformaci?n (<code>paramsCrsProj</code>) se utilizan en
154
     * lugar del CRS fuente o destino, seg?n indique <code>paramsInTarget</code>
155
     * .
156
     *
157
     * @throws OperationCrsException
158
     *
159
     */
160
    private Point2D operate(Point2D pt) throws CrsException, OperationCrsException {
161
        double x = pt.getX();
162
        double y = pt.getY();
220 163

  
221
		/*
222
		 * if (paramsCrsProj != null){ if (paramsInTarget) errno =
223
		 * JNIBaseCrs.operate( x , y, z,sourceCrs.getCrsProj(), paramsCrsProj);
224
		 * else errno = JNIBaseCrs.operate( x , y,
225
		 * z,paramsCrsProj,targetCrs.getCrsProj()); if (errno != -38) //
226
		 * "failed to load NAD27-83 correction file" (pj_strerrno.c) return new
227
		 * Point2D.Double(x[0],y[0]); }
228
		 *
229
		 * // Si el punto estaba fuera del ?mbito del nadgrid operamos sin
230
		 * nadgrid (convertimos) x[0] = pt.getX(); y[0] = pt.getY(); z[0] = 0D;
231
		 * JNIBaseCrs.operate( x , y, z,sourceCrs.getCrsProj(),
232
		 * targetCrs.getCrsProj()); return new Point2D.Double(x[0],y[0]);
233
		 */
234
		// System.out.println("x="+x[0]+"y="+y[0]);
235
		// if(!targetCrs.isProjected())
236
		// return new Point2D.Double(x[0]*((180)/Math.PI),y[0]*((180)/Math.PI));
237
		// else
238
	}
164
        int errno = 0;
165
        String msg = "";
166
        int errtype = 0;
239 167

  
240
	/**
241
	 * Realiza la operaci?n de transformaci?n sobre un punto. Si exiten
242
	 * par?metros de transformaci?n (<code>paramsCrsProj</code>) se utilizan en
243
	 * lugar del CRS fuente o destino, seg?n indique <code>paramsInTarget</code>
244
	 * .
245
	 *
246
	 * @throws CrsException
247
	 *
248
	 */
249
	// TODO Eliminar este m?todo. Me vale con el operate(Point2D).
250
	private double[] operate(double[] ptOrig) throws OperationCrsException,
251
			CrsException {
252
		double x[] = { ptOrig[0] };
253
		double y[] = { ptOrig[1] };
254
		double z[] = { ptOrig[2] };
255
		int errno = 0;
168
        double[] transformed = { 0, 0, 0 };
169
        initializeCoordinateTransformation();
170
        if (coordinateTransformation != null) {
171
            transformed = coordinateTransformation.TransformPoint(x, y);
172
        }
256 173

  
257
		CrsProj source;
258
		CrsProj target;
259
		if (sourceParams != null)
260
			source = new CrsProj(sourceCrs.getProj4String() + sourceParams);
261
		else
262
			source = sourceCrs.getCrsProj();
263
		if (targetParams != null)
264
			target = new CrsProj(targetCrs.getProj4String() + targetParams);
265
		else
266
			target = targetCrs.getCrsProj();
174
        errno = gdal.GetLastErrorNo();
175
        msg = gdal.GetLastErrorMsg();
176
        errtype = gdal.GetLastErrorType();
267 177

  
268
		errno = JNIBaseCrs.operate(x, y, z, source, target);
269
		if (errno != -38) { // "failed to load NAD27-83 correction file"
270
							// (pj_strerrno.c)
271
			double ptDest[] = { x[0], y[0], z[0] };
272
			return ptDest;
273
		}
178
        Point2D.Double result = null;
179
        if (errno != 0 && errtype != 0) {
180
            //FIXME:
181
            // gdal no devuelve m?s de 20 errores por transformaci?n,
182
            // si queremos de los devuelva todos tenemos que anular la
183
            // transformaci?n cada vez que se produce un error
184
//            coordinateTransformation = null;
185
            // Adem?s, no podemos hacer nada por los puntos que devuelve
186
            // la transformaci?n cuando ha tenido un error.
187
            // Lo suyo ser?a elevar una excepci?n y quien la recoja que decida qu? dabe hacer con el punto,
188
            // por ejemplo, si se est? dibujando una geometr?a, tal vez, no habr?a que dibujarla o saltarse los
189
            // puntos que no se pueden transformar.
274 190

  
275
		/*
276
		 * if (paramsCrsProj != null){ if (paramsInTarget) errno =
277
		 * JNIBaseCrs.operate( x , y, z,sourceCrs.getCrsProj(), paramsCrsProj);
278
		 * else errno = JNIBaseCrs.operate( x , y,
279
		 * z,paramsCrsProj,targetCrs.getCrsProj()); if (errno != -38){ //
280
		 * "failed to load NAD27-83 correction file" (pj_strerrno.c) double
281
		 * ptDest[] = {x[0], y[0], z[0]}; return ptDest; } }
282
		 */
191
            gdal.ErrorReset();
283 192

  
284
		// Si el punto estaba fuera del ?mbito del nadgrid operamos sin nadgrid
285
		// (convertimos)
286
		x[0] = ptOrig[0];
287
		y[0] = ptOrig[1];
288
		z[0] = ptOrig[2];
289
		JNIBaseCrs.operate(x, y, z, sourceCrs.getCrsProj(),
290
				targetCrs.getCrsProj());
291
		double ptDest[] = { x[0], y[0], z[0] };
292
		return ptDest;
293
	}
193
        }
194
        result = new Point2D.Double(transformed[0], transformed[1]);
195
        return result;
196
    }
294 197

  
295
	public IProjection getPOrig() {
296
		return (IProjection) sourceCrs;
297
	}
198
    private void initializeCoordinateTransformation() {
199
        if (coordinateTransformation == null) {
200
            coordinateTransformation =
201
                CoordinateTransformation.CreateCoordinateTransformation(source.getSpatialReference(),
202
                    target.getSpatialReference());
203
        }
204
    }
298 205

  
299
	public IProjection getPDest() {
300
		return (IProjection) targetCrs;
301
	}
206
    public IProjection getPOrig() {
207
        return (IProjection) sourceCrs;
208
    }
302 209

  
303
	public Point2D convert(Point2D ptOrig, Point2D ptDest) {
304
		try {
305
			ptDest = operate(ptOrig);
306
		} catch (CrsException e) {
307
			logger.error("Can't operate over point orig (" + ptOrig.toString()
308
					+ ").", e);
309
			throw new IllegalStateException(e.getMessage());
310
		} catch (OperationCrsException e) {
311
			logger.error("Can't operate over point orig (" + ptOrig.toString()
312
					+ ").", e);
313
			throw new IllegalStateException(e.getMessage());
314
		}
315
		return ptDest;
316
	}
210
    public IProjection getPDest() {
211
        return (IProjection) targetCrs;
212
    }
317 213

  
318
	public Rectangle2D convert(Rectangle2D rect) {
319
		Point2D pt1 = new Point2D.Double(rect.getMinX(), rect.getMinY());
320
		Point2D pt2 = new Point2D.Double(rect.getMaxX(), rect.getMaxY());
321
		Point2D pt3 = new Point2D.Double(rect.getMinX(), rect.getMaxY());
322
		Point2D pt4 = new Point2D.Double(rect.getMaxX(), rect.getMinY());
323
		try {
324
			pt1 = operate(pt1);
325
			pt2 = operate(pt2);
326
			pt3 = operate(pt3);
327
			pt4 = operate(pt4);
328
		} catch (CrsException e) {
329
			logger.error("Can't operate over rect (" + rect.toString() + ").",
330
					e);
331
			throw new IllegalStateException(e.getMessage());
332
		} catch (OperationCrsException e) {
333
			logger.error("Can't operate over rect (" + rect.toString() + ").",
334
					e);
335
			throw new IllegalStateException(e.getMessage());
336
		}
214
    public Point2D convert(Point2D ptOrig, Point2D ptDest) {
215
        try {
216
            ptDest = operate(ptOrig);
217
        } catch (CrsException e) {
218
            logger.error("Can't operate over point orig (" + ptOrig.toString() + ").", e);
219
            throw new IllegalStateException(e.getMessage());
220
        } catch (OperationCrsException e) {
221
            logger.error("Can't operate over point orig (" + ptOrig.toString() + ").", e);
222
            throw new IllegalStateException(e.getMessage());
223
        }
224
        return ptDest;
225
    }
337 226

  
338
		double min_x = Math.min(Math.min(pt1.getX(), pt2.getX()),
339
				Math.min(pt3.getX(), pt4.getX()));
340
		double min_y = Math.min(Math.min(pt1.getY(), pt2.getY()),
341
				Math.min(pt3.getY(), pt4.getY()));
342
		double max_x = Math.max(Math.max(pt1.getX(), pt2.getX()),
343
				Math.max(pt3.getX(), pt4.getX()));
344
		double max_y = Math.max(Math.max(pt1.getY(), pt2.getY()),
345
				Math.max(pt3.getY(), pt4.getY()));
227
    public Rectangle2D convert(Rectangle2D rect) {
228
        Point2D pt1 = new Point2D.Double(rect.getMinX(), rect.getMinY());
229
        Point2D pt2 = new Point2D.Double(rect.getMaxX(), rect.getMaxY());
230
        Point2D pt3 = new Point2D.Double(rect.getMinX(), rect.getMaxY());
231
        Point2D pt4 = new Point2D.Double(rect.getMaxX(), rect.getMinY());
232
        try {
233
            pt1 = operate(pt1);
234
            pt2 = operate(pt2);
235
            pt3 = operate(pt3);
236
            pt4 = operate(pt4);
237
        } catch (CrsException e) {
238
            logger.error("Can't operate over rect (" + rect.toString() + ").", e);
239
            throw new IllegalStateException(e.getMessage());
240
        } catch (OperationCrsException e) {
241
            logger.error("Can't operate over rect (" + rect.toString() + ").", e);
242
            throw new IllegalStateException(e.getMessage());
243
        }
346 244

  
347
		return new Rectangle2D.Double(min_x, min_y, max_x - min_x, max_y
348
				- min_y);
349
	}
245
        double min_x = Math.min(Math.min(pt1.getX(), pt2.getX()), Math.min(pt3.getX(), pt4.getX()));
246
        double min_y = Math.min(Math.min(pt1.getY(), pt2.getY()), Math.min(pt3.getY(), pt4.getY()));
247
        double max_x = Math.max(Math.max(pt1.getX(), pt2.getX()), Math.max(pt3.getX(), pt4.getX()));
248
        double max_y = Math.max(Math.max(pt1.getY(), pt2.getY()), Math.max(pt3.getY(), pt4.getY()));
350 249

  
351
	public ICoordTrans getInverted() {
352
		COperation operation;
353
		try {
354
			operation = new COperation(targetCrs, sourceCrs, targetParams,
355
					sourceParams);
356
			return operation;
357
		} catch (CrsException e) {
358
			logger.error("Can't get operation.", e);
359
			return null;
360
		}
361
	}
362
	/*
363
	 * public void setParamsCrsProj(CrsProj paramsCrs, boolean inTarget){
364
	 * this.paramsInTarget = inTarget; this.paramsCrsProj = paramsCrs; }
365
	 */
250
        return new Rectangle2D.Double(min_x, min_y, max_x - min_x, max_y - min_y);
251
    }
252

  
253
    public ICoordTrans getInverted() {
254
        COperation operation;
255
        try {
256
            operation = new COperation(targetCrs, sourceCrs, targetParams, sourceParams);
257
            return operation;
258
        } catch (CrsException e) {
259
            logger.error("Can't get operation.", e);
260
            return null;
261
        }
262
    }
263
    /*
264
     * public void setParamsCrsProj(CrsProj paramsCrs, boolean inTarget){
265
     * this.paramsInTarget = inTarget; this.paramsCrsProj = paramsCrs; }
266
     */
366 267
}
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/Crs.java
50 50
import org.cresques.cts.IDatum;
51 51
import org.cresques.cts.IProjection;
52 52
import org.cresques.geo.ViewPortData;
53
import org.slf4j.Logger;
54
import org.slf4j.LoggerFactory;
55

  
53 56
import org.gvsig.crs.proj.CrsProj;
54
import org.gvsig.crs.proj.JNIBaseCrs;
55 57
import org.gvsig.crs.proj.OperationCrsException;
56 58
import org.gvsig.fmap.crs.CRSFactory;
57
import org.slf4j.Logger;
58
import org.slf4j.LoggerFactory;
59 59

  
60 60
/**
61 61
 * Clase que construye el CRS a partir de la cadena WKT
......
65 65
 *
66 66
 */
67 67
public class Crs implements ICrs {
68
	private static final Logger logger = LoggerFactory.getLogger(Crs.class); 
68
	private static final Logger logger = LoggerFactory.getLogger(Crs.class);
69 69

  
70 70
	private static final Color basicGridColor = new Color(64, 64, 64, 128);
71 71
	private Proj4 proj4;
......
82 82
	String targetTrParams = null;
83 83
	String wkt = null;
84 84
	Color gridColor = basicGridColor;
85
	CRSDatum datum = null;	
85
	CRSDatum datum = null;
86 86

  
87 87
	public Crs(int epsgCode, int aut) throws CrsException
88 88
	{
89 89
		String strEpsgCode = "";
90 90
		if (aut == 1) {
91
			strEpsgCode="EPSG:"+epsgCode;			
91
			strEpsgCode="EPSG:"+epsgCode;
92 92
		} else if (aut == 2){
93 93
			strEpsgCode="ESRI:"+epsgCode;
94 94
		} else if (aut == 3){
......
99 99
		crsWkt=new CrsWkt(strEpsgCode);
100 100
		setWKT(crsWkt.getWkt());
101 101
	}
102
	
103
	
102

  
103

  
104 104
	/**
105 105
	 * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
106
	 * 
106
	 *
107 107
	 * @param code
108 108
	 * @throws CrsException
109 109
	 */
......
118 118
			code = code.substring(code.indexOf(":")+1);
119 119
			try {
120 120
				//Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
121
				crsWkt = new CrsWkt(fullCode);				
121
				crsWkt = new CrsWkt(fullCode);
122 122
				setName(fullCode);
123 123
				setAbrev(fullCode);
124
				
124

  
125 125
			} catch (NumberFormatException e) {
126 126
				logger.error("Can't Wkt.",e);
127 127
			}
......
137 137
				}
138 138
			}
139 139
			crsWkt = new CrsWkt(code2);
140
	    	    		
140

  
141 141
    		setName(fullCode);
142 142
    		//setAbrev(crsWkt.getName());
143
    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);	    	
144
	    	
143
    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
144

  
145 145
    	}
146 146
		//	Asignar el datum y el crs base (en el caso de ser projectado):
147 147
		if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){
148 148
			double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
149 149
			double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
150 150
			datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
151
			
151

  
152 152
			//crs base (en el caso de ser projectado):
153 153
			/*if(this.isProjected()){
154 154
				String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
155 155
				crsBase = new CrsProj(proj4Base);
156 156
			}*/
157 157
		}
158
	}	
159
	
158
	}
159

  
160 160
	/**
161 161
	 *Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
162
	 * 
162
	 *
163 163
	 * @param epsg_cod
164 164
	 * @param code
165 165
	 * @throws CrsException
......
176 176
			code = code.substring(code.indexOf(":")+1);
177 177
			try {
178 178
				//Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
179
				crsWkt = new CrsWkt(fullCode);				
179
				crsWkt = new CrsWkt(fullCode);
180 180
				setName(fullCode);
181 181
				setAbrev(fullCode);
182
				
182

  
183 183
			} catch (NumberFormatException e) {
184 184
				logger.error("Can't get Wkt.",e);
185 185
			}
......
201 201
			 * que no estan en gdal, por lo que asignaremos directamente su cadena
202 202
			 * en proj4 para trabajar con ellas
203 203
			 */
204
			if (!crsWkt.getProjection().equals("Equidistant_Cylindrical") && !crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){		    		    		
204
			if (!crsWkt.getProjection().equals("Equidistant_Cylindrical") && !crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){
205 205
	    		setName(fullCode);
206 206
	    		//setAbrev(crsWkt.getName());
207
	    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);		    	 
207
	    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
208 208
			}
209 209
			else if (crsWkt.getProjection().equals("Equidistant_Cylindrical")){
210 210
				String spheroid1 = crsWkt.getSpheroid()[1];
......
215 215
				String standardParallel1 = "0.0";
216 216
				for (int i=0; i<crsWkt.getParam_name().length;i++){
217 217
					if (crsWkt.getParam_name()[i].equals("Central_Meridian"))
218
						centralMeridian = crsWkt.getParam_value()[i];	
218
						centralMeridian = crsWkt.getParam_value()[i];
219 219
					if (crsWkt.getParam_name()[i].equals("False_Easting"))
220
						falseEasting = crsWkt.getParam_value()[i];					
220
						falseEasting = crsWkt.getParam_value()[i];
221 221
					if(crsWkt.getParam_name()[i].equals("False_Northing"))
222
						falseNorthing = crsWkt.getParam_value()[i];					
222
						falseNorthing = crsWkt.getParam_value()[i];
223 223
					if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1"))
224
						standardParallel1 = crsWkt.getParam_value()[i];					
224
						standardParallel1 = crsWkt.getParam_value()[i];
225 225
				}
226 226
				if (spheroid2.equals("0.0")){
227 227
					proj4String = "+proj=eqc +a=" + spheroid1 +
......
231 231
					proj4String = "+proj=eqc +a="+ spheroid1 +" +rf=" + spheroid2 +
232 232
					" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
233 233
					" +lat_ts="+standardParallel1;
234
				}				
234
				}
235 235
				setName(fullCode);
236 236
	    		//setAbrev(crsWkt.getName());
237 237
	    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
238
				
238

  
239 239
			}
240 240
			else if (crsWkt.getProjection().equals("Oblique_Cylindrical_Equal_Area")){
241 241
				String spheroid1 = crsWkt.getSpheroid()[1];
......
245 245
				String falseEasting = "";
246 246
				String standardParallel1 = "";
247 247
				String standardParallel2 = "0.0";
248
				for (int i=0; i<crsWkt.getParam_name().length;i++){					
248
				for (int i=0; i<crsWkt.getParam_name().length;i++){
249 249
					if (crsWkt.getParam_name()[i].equals("Central_Meridian"))
250
						centralMeridian = crsWkt.getParam_value()[i];	
250
						centralMeridian = crsWkt.getParam_value()[i];
251 251
					if (crsWkt.getParam_name()[i].equals("False_Easting"))
252
						falseEasting = crsWkt.getParam_value()[i];					
252
						falseEasting = crsWkt.getParam_value()[i];
253 253
					if(crsWkt.getParam_name()[i].equals("False_Northing"))
254
						falseNorthing = crsWkt.getParam_value()[i];					
254
						falseNorthing = crsWkt.getParam_value()[i];
255 255
					if (crsWkt.getParam_name()[i].equals("Standard_Parallel_1"))
256 256
						standardParallel1 = crsWkt.getParam_value()[i];
257 257
					if (crsWkt.getParam_name()[i].equals("Standard_Parallel_2"))
258
						standardParallel2 = crsWkt.getParam_value()[i];		
258
						standardParallel2 = crsWkt.getParam_value()[i];
259 259
				}
260 260
				if (spheroid2.equals("0.0")){
261 261
					proj4String = "+proj=ocea +a="+ spheroid1  +
......
267 267
					" +lon_0="+ centralMeridian + " +x_0="+falseEasting+" +y_0="+falseNorthing +
268 268
					" +lat_1="+standardParallel1+" +lat_2="+standardParallel2+" +lon_1=long_1" +
269 269
					" +lon_2=long_2 +no_defs";
270
				}				
270
				}
271 271
				setName(fullCode);
272 272
	    		//setAbrev(crsWkt.getName());
273 273
	    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
......
278 278
			double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
279 279
			double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
280 280
			datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
281
			
281

  
282 282
			// Crs base (en el caso de ser projectado):
283 283
			/*if(this.isProjected()){
284 284
				String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
......
286 286
			}*/
287 287
		}
288 288
	}
289
	
289

  
290 290
	/**
291 291
	 * Construye un CRS a partir del c?digo EPSG o de la cadena WKT.
292 292
	 * En el caso de WKT le a?ade a la cadena proj4 el string params.
293
	 * 
293
	 *
294 294
	 * @param epsg_cod
295 295
	 * @param code
296 296
	 * @param params
......
309 309
			try {
310 310
				//Creamos el objeto que tendra los diferentes parametros de la cadena Wkt
311 311
				crsWkt = new CrsWkt(fullCode);
312
				
312

  
313 313
				setName(fullCode);
314 314
				setAbrev(fullCode);
315
				
315

  
316 316
			} catch (NumberFormatException e) {
317 317
				logger.error("Can't get Wkt.",e);
318 318
			}
......
328 328
				}
329 329
			}
330 330
			crsWkt = new CrsWkt(code2);
331
	    	
331

  
332 332
    		setName(fullCode);
333 333
    		//setAbrev(crsWkt.getName());
334 334
    		setAbrev(crsWkt.getAuthority()[0]+":"+crsWkt.getAuthority()[1]);
335
	    	
335

  
336 336
		}
337 337
		//	Asignar el datum:
338 338
		if (!(crsWkt.getSpheroid()[1].equals("")||crsWkt.getSpheroid()[2].equals(""))){
339 339
			double eSemiMajorAxis = Double.valueOf(crsWkt.getSpheroid()[1]).doubleValue();
340 340
			double eIFlattening = Double.valueOf(crsWkt.getSpheroid()[2]).doubleValue();
341 341
			datum = new CRSDatum(eSemiMajorAxis,eIFlattening);
342
			
342

  
343 343
			// Crs base (en el caso de ser projectado):
344 344
			/*if(this.isProjected()){
345 345
				String proj4Base = "+proj=latlong +a=" + crsWkt.getSpheroid()[1] + " +rf=" + crsWkt.getSpheroid()[2] ;
......
347 347
			}*/
348 348
		}
349 349
	}
350
		
350

  
351 351
/*	public Crs(CrsEpsg source) throws CrsException {
352 352
		crsProj4 = source;
353 353
	}*/
354
	
354

  
355 355
	/**
356
	 * @param code 
356
	 * @param code
357 357
	 */
358 358
	public void setTrans(String code) {
359 359
		trans = code;
360 360
		changeTrans(trans);
361 361
	}
362
	
362

  
363 363
	/**
364
	 * 
364
	 *
365 365
	 * @param code
366 366
	 */
367 367
	public void changeTrans(String code) {
368 368
		getCrsProj().changeStrCrs(code);
369 369
	}
370
	
370

  
371 371
	/**
372
	 * 
372
	 *
373 373
	 */
374 374
	public String getAbrev() {
375 375
		return abrev;
376 376
	}
377
	
377

  
378 378
	/**
379
	 * 
379
	 *
380 380
	 * @param code
381 381
	 */
382 382
	protected void setAbrev(String code) {
383 383
		abrev = code;
384 384
	}
385
	
385

  
386 386
	/**
387
	 * 
387
	 *
388 388
	 * @param nom
389 389
	 */
390 390
	public void setName(String nom) {
391 391
		name = nom;
392 392
	}
393
	
393

  
394 394
	/**
395 395
	 * @return
396 396
	 */
397 397
	public IDatum getDatum() {
398
		
398

  
399 399
		return datum;
400 400
	}
401
	
401

  
402 402
	/**
403 403
	 * @return
404 404
	 */
405 405
	public CrsWkt getCrsWkt() {
406 406
		return crsWkt;
407 407
	}
408
	
408

  
409 409
	/**
410
	 * 
410
	 *
411 411
	 * @param wkt
412 412
	 */
413 413
	public void setWKT(String wkt){
414 414
		this.wkt = wkt;
415 415
	}
416
	
416

  
417 417
	/**
418 418
	 * @return
419 419
	 */
420 420
	public String getWKT(){
421 421
		return this.wkt;
422 422
	}
423
	
423

  
424 424
	/**
425
	 * 
425
	 *
426 426
	 * @param params
427 427
	 */
428 428
	public void setTransformationParams(String sourceParams, String targetParams){
429 429
		this.sourceTrParams = sourceParams;
430 430
		this.targetTrParams = targetParams;
431 431
	}
432
	
432

  
433 433
	/**
434 434
	 * Devuelve los parametros de la transformacion del crs fuente
435 435
	 * @return
......
437 437
	public String getSourceTransformationParams() {
438 438
		return this.sourceTrParams;
439 439
	}
440
	
440

  
441 441
	/**
442 442
	 * Devuelve los parametros de la transformacion del crs destino
443 443
	 * @return
......
445 445
	public String getTargetTransformationParams() {
446 446
		return this.targetTrParams;
447 447
	}
448
	
448

  
449 449
	/**
450 450
	 * @return
451 451
	 */
452 452
	public String getTransformationParams(){
453 453
		return this.sourceTrParams;
454 454
	}
455
		
455

  
456 456
	/**
457
	 * 
457
	 *
458 458
	 * @return
459 459
	 */
460 460
	public CrsProj getCrsProj() {
......
463 463
				crsProj = new CrsProj(getProj4String());
464 464
			} catch (CrsException e) {
465 465
				logger.error("Can't get proj4 string.",e);
466
			} 
466
			}
467 467
		return crsProj;
468 468
	}
469 469

  
......
482 482
	 */
483 483
	public void drawGrid(Graphics2D g, ViewPortData vp) {
484 484
		// TODO Auto-generated method stub
485
		
485

  
486 486
	}
487 487

  
488 488
	/**
......
504 504
	 * @return
505 505
	 */
506 506
	public ICoordTrans getCT(IProjection dest) {
507
		
508
		
507

  
508

  
509 509
		try {
510 510
			if (dest == this)
511 511
				return null;
512 512
			COperation operation = null;
513
			if(((ICrs)dest).getSourceTransformationParams() != null || ((ICrs)dest).getTargetTransformationParams() != null) 
513
			if(((ICrs)dest).getSourceTransformationParams() != null || ((ICrs)dest).getTargetTransformationParams() != null)
514 514
				operation = new COperation(this, (ICrs)dest,((ICrs)dest).getTargetTransformationParams(),((ICrs)dest).getSourceTransformationParams());
515 515
			else
516 516
				operation = new COperation(this, (ICrs)dest,sourceTrParams,targetTrParams);
......
519 519
			logger.error("Can't get CoordTrans.",e);
520 520
			return null;
521 521
		}
522
		
522

  
523 523
		/*
524 524
		try {
525 525
			operation = new COperation(this, (ICrs)dest);
......
527 527
			// TODO Auto-generated catch block
528 528
			logger....
529 529
		}
530
		
530

  
531 531
		if (getTransformationParams()!=null){
532 532
			if (isTargetParams())
533 533
				operation.setParamsCrsProj(new CrsProj(crsDest.getProj4String()+getTransformationParams()), true);
534 534
			else
535 535
				operation.setParamsCrsProj(new CrsProj(getProj4String()+getTransformationParams()), false);
536
			
536

  
537 537
			return operation;
538 538
		}
539
		
540
		return operation;	*/	
539

  
540
		return operation;	*/
541 541
	}
542
	
542

  
543 543
	/**
544 544
	 * @param pt
545 545
	 * @return
......
550 550
			double y[] = {pt.getY()};
551 551
			double z[] = {0D};
552 552
			try {
553
				JNIBaseCrs.operate( x , y, z,
553
			    CrsProj.operate( x , y, z,
554 554
						getCrsProj(),crsBase);
555 555
			} catch (OperationCrsException e) {
556 556
				logger.error("Can't convert point to geo.",e);
......
575 575
	 * @return
576 576
	 */
577 577
	public boolean isProjected() {
578
		return !getCrsProj().isLatlong();		
578
		return !getCrsProj().isLatlong();
579 579
	}
580 580

  
581 581
	/**
......
602 602
//        }
603 603
        return scale;
604 604
	}
605
	
605

  
606 606
	public double getScale(double minX, double maxX, double minY, double maxY, double width, double dpi) {
607
		
607

  
608 608
		double scale = 0D;
609 609
		double incX = (maxX-minX);
610
		
610

  
611 611
		if (!isProjected()) {
612 612
			double a = getDatum().getESemiMajorAxis();
613 613
			double invF = getDatum().getEIFlattening();
614 614
			double meanY = (minY+maxY)/2.0;
615 615
			double radius = 0.0;
616
			
617
			
616

  
617

  
618 618
			if (invF == Double.POSITIVE_INFINITY){
619 619
				radius = a;
620 620
			}
......
624 624
			}
625 625
			incX *= Math.PI/180.0*radius;
626 626
		}
627
			
627

  
628 628
		scale = (incX * // metros
629 629
				(dpi / 2.54 * 100.0)) / // px / metro
630 630
					width; // pixels
631
		
631

  
632 632
        return scale;
633 633
	}
634
	
634

  
635 635
	/**
636
	 * 
636
	 *
637 637
	 * @param epsg_cod
638 638
	 */
639 639
	public void setCode(int epsg_cod){
......
657 657
			sourceParams = sourceTrParams;
658 658
		if (targetTrParams != null)
659 659
			targetParams = targetTrParams;
660
		
660

  
661 661
		return getAbrev()+":proj@"+sourceParams+"@"+targetParams;
662 662
	}
663 663

  
......
686 686
		Rectangle2D rec=new Rectangle2D.Double(xExtent,yExtent,wExtent,hExtent);
687 687
    	return  rec;
688 688
    }
689
   
689

  
690 690
	private Proj4 getProj4() {
691 691
		if (proj4 == null)
692 692
			try {
......
696 696
			}
697 697
		return proj4;
698 698
	}
699
	
700
	/** 
701
	 * 
699

  
700
	/**
701
	 *
702 702
	 * @return Cadena proj4 Correspondiente al CRS.
703
	 * @throws CrsException 
703
	 * @throws CrsException
704 704
	 */
705 705
	public String getProj4String() throws CrsException {
706 706
		if (proj4String == null)
707
			proj4String = getProj4().exportToProj4(this);			
707
			proj4String = getProj4().exportToProj4(this);
708 708
		return proj4String;
709 709
	}
710
	
710

  
711 711
	public Object clone() throws CloneNotSupportedException {
712 712
	       return CRSFactory.getCRS( this.getFullCode() );
713 713
	    }
714 714

  
715 715
        public String toString() {
716
            return MessageFormat.format("{0}({1},{2})", new Object[] { 
716
            return MessageFormat.format("{0}({1},{2})", new Object[] {
717 717
                this.getClass().getName(),
718 718
                this.hashCode(),
719 719
                this.getFullCode()
org.gvsig.projection.jcrs/trunk/org.gvsig.projection.jcrs/org.gvsig.projection.jcrs.lib/src/main/java/org/gvsig/crs/proj/JNIBaseCrs.java
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.proj;
42

  
43
/**
44
 *
45
 * @author Miguel Garc�a Jim�nez (garciajimenez.miguel@gmail.com)
46
 *
47
 */
48
public class JNIBaseCrs
49
{
50
	protected long cPtr;
51
	protected int latLong;
52
	protected String _strCrs;
53
	protected native long loadCrs(String crs);
54
	protected native void freeCrs(long crs);
55
	protected native int isLatlong(long crs);
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff