gvsig-raster / org.gvsig.raster.gdal / tags / pre-remove-jgdal / org.gvsig.raster.gdal / org.gvsig.raster.gdal.io / src / main / java / org / gvsig / jogr / OGRSpatialReference.java @ 3497
History | View | Annotate | Download (13.3 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
package org.gvsig.jogr; |
24 |
|
25 |
import java.util.Vector; |
26 |
|
27 |
import org.gdal.osr.SpatialReference; |
28 |
import org.gvsig.jgdal.JNIBase; |
29 |
|
30 |
/**
|
31 |
* Representa un sistema de referencia espacial OpenGIS.
|
32 |
*
|
33 |
* @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
|
34 |
* @version 0.0
|
35 |
* @link http://www.gvsig.gva.es
|
36 |
*/
|
37 |
|
38 |
public class OGRSpatialReference extends SpatialReference { |
39 |
|
40 |
//private native int setUTMNat(long cPtr, int zona, int norte_sur);
|
41 |
//private native int setWellKnownGeogCSNat(long cPtr, String cs);
|
42 |
//private native long OGRSpatialReferenceNat();
|
43 |
//private native String exportToWktNat(long cPtr);
|
44 |
// private native void OSRDestroySpatialReferenceNat(long cPtr);
|
45 |
// private native int getUTMZoneNat(long cPtr);
|
46 |
// private native int getHemisphereNat(long cPtr);
|
47 |
// private native int setFromUserInputNat(long cPtr, String a_srs);
|
48 |
//
|
49 |
// private native long OGRSpatialReferenceNat() throws CrsGdalException;
|
50 |
// private native void OGRDestroySpatialReferenceNat(long crs);
|
51 |
//
|
52 |
// protected static native String exportToProj4Nat(long cPtr);
|
53 |
// protected static native String exportToWktNat(long cPtr);
|
54 |
// protected static native int importFromWktNat(long cPtr, String cadenas);
|
55 |
// protected static native int setUTMNat(long cPtr, int zona, int norte_sur);
|
56 |
// protected static native int setWellKnownGeogCSNat(long cPtr, String cs);
|
57 |
// protected static native int importFromEPSGNat(long cPtr, int cod);
|
58 |
// protected static native int importFromProj4Nat(long cPtr, String cs);
|
59 |
// protected static native int importFromPCINat(long cPtr,String cod, String cs,double[] coord);
|
60 |
// protected static native int importFromUSGSNat(long cPtr, long code, long zone, double[] params, long datum);
|
61 |
// protected static native int importFromESRINat(long cPtr, String cadenas);
|
62 |
// protected static native boolean isGeographicNat(long cPtr);
|
63 |
// protected static native String getAuthorityCodeNat(long cPtr, String targetKey);
|
64 |
// protected static native String getAuthorityNameNat(long cPtr, String targetKey);
|
65 |
|
66 |
/**
|
67 |
*Constructor a partir de la direcci?n de memoria
|
68 |
*/
|
69 |
|
70 |
public OGRSpatialReference(long spatialReference){ |
71 |
super(spatialReference, true); |
72 |
} |
73 |
|
74 |
/**
|
75 |
* Constructor generico
|
76 |
*/
|
77 |
|
78 |
public OGRSpatialReference(){
|
79 |
super();
|
80 |
} |
81 |
|
82 |
/**
|
83 |
* Escribe la zona UTM pasada por par?metro
|
84 |
* @param zona Zona UTM
|
85 |
* @param norte_sur TRUE hemisferio norte y FALSE hemisferio sur
|
86 |
* @throws OGRException
|
87 |
*/
|
88 |
|
89 |
public void setUTM(int zona, boolean norte_sur)throws OGRException { |
90 |
int ns=-1; |
91 |
if(norte_sur)ns=1; |
92 |
else ns=0; |
93 |
|
94 |
// if(cPtr == 0)
|
95 |
// throw new OGRException("Fallo al acceder al dato.");
|
96 |
|
97 |
if ((zona <= 0) || (zona > 60)) |
98 |
throw new OGRException("Zona incorrecta"); |
99 |
|
100 |
int res = this.SetUTM(zona, ns); |
101 |
|
102 |
if(res < 0) |
103 |
throw new OGRException("Error en setUTM(). No se ha podido asignar la zona especificada."); |
104 |
} |
105 |
|
106 |
/**
|
107 |
* Lee la zona UTM
|
108 |
* @return Zona UTM
|
109 |
* @throws OGRException
|
110 |
*/
|
111 |
|
112 |
public int getUTMZone()throws OGRException { |
113 |
// if(cPtr == 0)
|
114 |
// throw new OGRException("Fallo al acceder al dato.");
|
115 |
|
116 |
int res = this.GetUTMZone(); |
117 |
|
118 |
if(res < 0) |
119 |
throw new OGRException("Error en getUTMZone(). Valor de zona devuelto erroneo."); |
120 |
|
121 |
return res;
|
122 |
} |
123 |
|
124 |
/**
|
125 |
* Obtiene el hemisferio
|
126 |
* @return TRUE hemisferio norte y FALSE hemisferio sur
|
127 |
* @throws OGRException
|
128 |
*/
|
129 |
|
130 |
public boolean getHemisphere()throws OGRException { |
131 |
// if(cPtr == 0)
|
132 |
// throw new OGRException("Fallo al acceder al dato.");
|
133 |
|
134 |
int hemis = this.GetUTMZone(); |
135 |
|
136 |
if(hemis == 0) |
137 |
throw new OGRException("Error en getHemisphere(). Valor de hemisferio devuelto erroneo."); |
138 |
|
139 |
if(hemis > 0)return true; |
140 |
else return false; |
141 |
} |
142 |
|
143 |
/**
|
144 |
*Asigna las coordenadas geogr?ficas
|
145 |
*@param cs Coordenadas geograficas soportadas:<BR>
|
146 |
*<UL>
|
147 |
*<LI>WGS84</LI>
|
148 |
*<LI>WGS72</LI>
|
149 |
*<LI>NAD27</LI>
|
150 |
*<LI>NAD83</LI>
|
151 |
*<LI>EPSG:n</LI>
|
152 |
*</UL>
|
153 |
*@throws OGRException
|
154 |
*/
|
155 |
|
156 |
public void setWellKnownGeogCS(String cs)throws OGRException { |
157 |
// if(cPtr == 0)
|
158 |
// throw new OGRException("Fallo al acceder al dato.");
|
159 |
|
160 |
if ((cs == null) || (cs.equals(""))) |
161 |
throw new OGRException("Parametro incorrecto en OGRSpatialReference.setWllKnownGeoCS"); |
162 |
|
163 |
int res = this.SetWellKnownGeogCS(cs); |
164 |
|
165 |
if(res < 0) |
166 |
throw new OGRException("Error en setWellKnownGeoCS(). No se ha podido asignar el sistema de coordenadas especificado."); |
167 |
} |
168 |
|
169 |
/**
|
170 |
* Devuelve la codificaci?n WKT
|
171 |
* @return Codificaci?n WKT
|
172 |
* @throws OGRException
|
173 |
*/
|
174 |
public String exportToWkt()throws OGRException { |
175 |
// if(cPtr == 0)
|
176 |
// throw new OGRException("Fallo al acceder al dato.");
|
177 |
|
178 |
String wkt = this.ExportToWkt(); |
179 |
|
180 |
if(wkt == null) |
181 |
throw new OGRException("Error en exportToWkt(). No se ha podido obtener la proyecci?n."); |
182 |
|
183 |
return wkt;
|
184 |
} |
185 |
|
186 |
/**
|
187 |
* @throws OGRException
|
188 |
* @param a_srs
|
189 |
*/
|
190 |
public void setFromUserInput(String a_srs)throws OGRException { |
191 |
// if(cPtr == 0)
|
192 |
// throw new OGRException("Fallo al acceder al dato.");
|
193 |
|
194 |
if ((a_srs == null) || (a_srs.equals(""))) |
195 |
throw new OGRException("Parametro incorrecto en OGRSpatialReference.setFromUserInput"); |
196 |
|
197 |
int ogrerr = this.SetFromUserInput(a_srs); |
198 |
//throwException(ogrerr,"Error en setFromUserInput().");
|
199 |
} |
200 |
|
201 |
/**
|
202 |
* Destructor
|
203 |
*/
|
204 |
protected void finalize(){ |
205 |
// if(cPtr == 0)
|
206 |
// throw new OGRFailureException("Fallo al acceder al dato.");
|
207 |
|
208 |
//OSRDestroySpatialReferenceNat(cPtr);
|
209 |
this.delete();
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* Consulta si la fuente de datos est? en coordenas geograficas o no
|
214 |
* @return true si est? en coordenadas geogr?ficas
|
215 |
*/
|
216 |
public boolean isGeographic() throws CrsGdalException { |
217 |
// if(cPtr == 0)
|
218 |
// throw new CrsGdalException();
|
219 |
return this.IsGeographic()>0; |
220 |
} |
221 |
|
222 |
/**
|
223 |
* Obtiene el c?digo EPSG
|
224 |
* @param targetKey
|
225 |
* @return "PROJCS", "GEOGCS", "GEOGCS|UNIT" or NULL
|
226 |
* @throws CrsGdalException
|
227 |
*/
|
228 |
public String getAuthorityCode(String targetKey) throws CrsGdalException { |
229 |
// if(cPtr == 0)
|
230 |
// throw new CrsGdalException();
|
231 |
|
232 |
if ((targetKey == null) || (targetKey.equals(""))) |
233 |
throw new CrsGdalException(); |
234 |
|
235 |
return this.GetAuthorityCode(targetKey); |
236 |
} |
237 |
|
238 |
/**
|
239 |
* Obtiene el autority name. Tipicamente EPSG
|
240 |
* @param targetKey
|
241 |
* @return "PROJCS", "GEOGCS", "GEOGCS|UNIT" or NULL
|
242 |
* @throws CrsGdalException
|
243 |
*/
|
244 |
public String getAuthorityName(String targetKey) throws CrsGdalException { |
245 |
// if(cPtr == 0)
|
246 |
// throw new CrsGdalException();
|
247 |
|
248 |
if ((targetKey == null) || (targetKey.equals(""))) |
249 |
throw new CrsGdalException(); |
250 |
|
251 |
return this.GetAuthorityName(targetKey); |
252 |
} |
253 |
|
254 |
|
255 |
|
256 |
/**
|
257 |
*
|
258 |
* @param ORGSpace
|
259 |
* @return
|
260 |
* @throws CrsGdalException
|
261 |
* @throws OGRException
|
262 |
*/
|
263 |
public static String exportToWkt(OGRSpatialReference ORGSpace) throws CrsGdalException, OGRException{ |
264 |
// if (ORGSpace.cPtr == 0)
|
265 |
// throw new CrsGdalException();
|
266 |
|
267 |
return ORGSpace.ExportToWkt();
|
268 |
} |
269 |
|
270 |
|
271 |
/**
|
272 |
*
|
273 |
* @param ORGSpace
|
274 |
* @param cadenas
|
275 |
* @return
|
276 |
* @throws OGRException
|
277 |
*/
|
278 |
public static int importFromWkt(OGRSpatialReference ORGSpace, String cadenas) throws OGRException { |
279 |
if ((cadenas == null) || (cadenas.equals(""))) |
280 |
throw new OGRException("Parametro incorrecto"); |
281 |
|
282 |
// if (ORGSpace.cPtr == 0)
|
283 |
// throw new OGRException("Parametro incorrecto");
|
284 |
|
285 |
int result = ORGSpace.ImportFromWkt(cadenas);
|
286 |
if(result != 0) |
287 |
throw new OGRException(result, "Error en Wkt().La creacion del objeto no tuvo exito. ", ORGSpace); |
288 |
return result;
|
289 |
} |
290 |
|
291 |
|
292 |
/**
|
293 |
*
|
294 |
* @param ORGSpace
|
295 |
* @param zona
|
296 |
* @param norte_sur
|
297 |
* @return
|
298 |
* @throws OGRException
|
299 |
*/
|
300 |
public static int setUTM(OGRSpatialReference v ,int zona, boolean norte_sur)throws OGRException { |
301 |
if ((zona <= 0) || (zona > 60)) |
302 |
throw new OGRException("Zona incorrecta"); |
303 |
|
304 |
// if(ORGSpace.cPtr == 0)
|
305 |
// throw new OGRException("Error en setUTM(). La llamada de creaci?n de objeto no tuvo exito.");
|
306 |
|
307 |
int ns=-1; |
308 |
if(norte_sur)ns=1; |
309 |
else ns=0; |
310 |
|
311 |
int res = v.SetUTM(zona, ns);
|
312 |
|
313 |
if(res != 0) |
314 |
throw new OGRException(res,"Error en setUTM(). No se ha podido asignar la zona especificada. ", v); |
315 |
return res;
|
316 |
} |
317 |
|
318 |
|
319 |
/**
|
320 |
*
|
321 |
* @param ORGSpace
|
322 |
* @param cs
|
323 |
* @return
|
324 |
* @throws OGRException
|
325 |
*/
|
326 |
public static int setWellKnownGeogCS(OGRSpatialReference ORGSpace, String cs)throws OGRException { |
327 |
if ((cs == null) || (cs.equals(""))) |
328 |
throw new OGRException("Parametro incorrecto"); |
329 |
|
330 |
// if(ORGSpace.cPtr == 0)
|
331 |
// throw new OGRException("Error en setWellKnownGeogCS(). La llamada de creaci?n de objeto no tuvo exito.");
|
332 |
|
333 |
int res = ORGSpace.SetWellKnownGeogCS(cs);
|
334 |
|
335 |
if(res != 0) |
336 |
throw new OGRException(res,"Error en setWellKnownGeoCS(). No se ha podido asignar el sistema de coordenadas especificado. ",ORGSpace); |
337 |
return res;
|
338 |
} |
339 |
|
340 |
|
341 |
/**
|
342 |
*
|
343 |
* @param ORGSpace
|
344 |
* @param cod
|
345 |
* @return
|
346 |
* @throws OGRException
|
347 |
*/
|
348 |
public static int importFromEPSG(OGRSpatialReference ORGSpace, int cod) throws OGRException { |
349 |
// if(ORGSpace.cPtr == 0)
|
350 |
// throw new OGRException("Error importFromEPSG. La llamada de creaci?n de objeto no tuvo exito.");
|
351 |
|
352 |
int result = ORGSpace.ImportFromEPSG(cod);
|
353 |
|
354 |
if(result != 0) |
355 |
throw new OGRException(result,"Error en EPSG().La creacion del objeto no tuvo exito. ",ORGSpace); |
356 |
|
357 |
return result;
|
358 |
} |
359 |
|
360 |
|
361 |
/**
|
362 |
*
|
363 |
* @param ORGSpace
|
364 |
* @param cs
|
365 |
* @return
|
366 |
* @throws OGRException
|
367 |
*/
|
368 |
public static int importFromProj4(OGRSpatialReference ORGSpace, String cs)throws OGRException { |
369 |
|
370 |
if ((cs == null) || (cs.equals(""))) |
371 |
throw new OGRException("Parametro incorrecto"); |
372 |
|
373 |
// if(ORGSpace.cPtr == 0)
|
374 |
// throw new OGRException("Error en Proj4(). La llamada de creaci?n de objeto no tuvo exito.");
|
375 |
|
376 |
int res = ORGSpace.ImportFromProj4(cs);
|
377 |
|
378 |
if(res != 0) |
379 |
throw new OGRException(res, "Error en Proj4(). No se ha podido asignar el sistema de coordenadas especificado. ", ORGSpace); |
380 |
|
381 |
return res;
|
382 |
|
383 |
} |
384 |
|
385 |
|
386 |
/**
|
387 |
*
|
388 |
* @param ORGSpace
|
389 |
* @return
|
390 |
* @throws CrsOgrException
|
391 |
*/
|
392 |
public static String exportToProj4(OGRSpatialReference ORGSpace) throws OGRException { |
393 |
// if(ORGSpace.cPtr == 0)
|
394 |
// throw new OGRException("Error en exportToProj4(). La llamada de creaci?n de objeto no tuvo exito.");
|
395 |
|
396 |
String result = ORGSpace.ExportToProj4();
|
397 |
|
398 |
if(result.length() == 0) |
399 |
throw new OGRException("No se ha podido hacer exportToProj4"); |
400 |
return result;
|
401 |
} |
402 |
|
403 |
|
404 |
/**
|
405 |
*
|
406 |
* @param ORGSpace
|
407 |
* @param cod
|
408 |
* @param cs
|
409 |
* @param coord
|
410 |
* @return
|
411 |
* @throws OGRException
|
412 |
*/
|
413 |
public static int importFromPCI(OGRSpatialReference ORGSpace,String cod, String cs, double[] coord)throws OGRException { |
414 |
if ((cs == null) || (cs.equals(""))) |
415 |
throw new OGRException("Parametro incorrecto"); |
416 |
|
417 |
if ((cod == null) || (cod.equals(""))) |
418 |
throw new OGRException("Parametro incorrecto"); |
419 |
|
420 |
// if(ORGSpace.cPtr == 0)
|
421 |
// throw new OGRException("Error en importFromPCI. La llamada de creaci?n de objeto no tuvo exito.");
|
422 |
|
423 |
if (coord == null) |
424 |
throw new OGRException("Parametro incorrecto"); |
425 |
|
426 |
int result = ORGSpace.ImportFromPCI(cod, cs, coord);
|
427 |
|
428 |
if(result != 0) |
429 |
throw new OGRException(result, "Error en PCI().La creacion del objeto no tuvo exito. ", ORGSpace); |
430 |
|
431 |
return result;
|
432 |
} |
433 |
|
434 |
|
435 |
/**
|
436 |
*
|
437 |
* @param ORGSpace
|
438 |
* @param code
|
439 |
* @param zone
|
440 |
* @param params
|
441 |
* @param datum
|
442 |
* @return
|
443 |
* @throws OGRException
|
444 |
*/
|
445 |
|
446 |
|
447 |
|
448 |
|
449 |
|
450 |
public static int importFromUSGS(OGRSpatialReference ORGSpace, long code, long zone, double[] params, long datum) throws OGRException { |
451 |
// if(ORGSpace.cPtr == 0)
|
452 |
// throw new OGRException("Error en importFromUSGS. La llamada de creaci?n de objeto no tuvo exito.");
|
453 |
|
454 |
if ((zone <= 0) || (zone > 60)) |
455 |
throw new OGRException("Zona incorrecta"); |
456 |
|
457 |
if (params == null) |
458 |
throw new OGRException("Parametro incorrecto"); |
459 |
|
460 |
int result = ORGSpace.ImportFromUSGS(
|
461 |
OGRTools.safeLongToInt(code), OGRTools.safeLongToInt(zone), params, OGRTools.safeLongToInt(datum)); |
462 |
|
463 |
if(result != 0) |
464 |
throw new OGRException(result, "Error en USGS().La creacion del objeto no tuvo exito. ", ORGSpace); |
465 |
|
466 |
return result;
|
467 |
|
468 |
} |
469 |
|
470 |
|
471 |
/**
|
472 |
*
|
473 |
* @param ORGSpace
|
474 |
* @param cadenas
|
475 |
* @return
|
476 |
* @throws OGRException
|
477 |
*/
|
478 |
public static int importFromESRI(OGRSpatialReference ORGSpace, String cadenas) throws OGRException { |
479 |
if (cadenas == null) |
480 |
throw new OGRException("Parametro incorrecto"); |
481 |
|
482 |
// if(ORGSpace.cPtr == 0)
|
483 |
// throw new OGRException("Error en importFromEsri. La llamada de creaci?n de objeto no tuvo exito.");
|
484 |
|
485 |
Vector vec = null; |
486 |
|
487 |
int result = ORGSpace.ImportFromESRI(OGRTools.safeStringToVector(cadenas));
|
488 |
if(result != 0) |
489 |
throw new OGRException(result, "Error en ESRI().La creacion del objeto no tuvo exito. ", ORGSpace); |
490 |
return result;
|
491 |
} |
492 |
} |