Statistics
| Revision:

root / trunk / libraries / libjni-gdal / src / es / gva / cit / jogr / OGRSpatialReference.java @ 7765

History | View | Annotate | Download (5.04 KB)

1
/**********************************************************************
2
 * $Id: OGRSpatialReference.java 7765 2006-10-03 07:05:18Z nacho $
3
 *
4
 * Name:     OGRSpatialReference.java
5
 * Project:  JGDAL. Interface java to gdal (Frank Warmerdam).
6
 * Purpose:   
7
 * Author:   Nacho Brodin, brodin_ign@gva.es
8
 *
9
 **********************************************************************/
10
/*Copyright (C) 2004  Nacho Brodin <brodin_ign@gva.es>
11

12
 This program is free software; you can redistribute it and/or
13
 modify it under the terms of the GNU General Public License
14
 as published by the Free Software Foundation; either version 2
15
 of the License, or (at your option) any later version.
16

17
 This program is distributed in the hope that it will be useful,
18
 but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 GNU General Public License for more details.
21

22
 You should have received a copy of the GNU General Public License
23
 along with this program; if not, write to the Free Software
24
 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25
 */
26

    
27
package es.gva.cit.jogr;
28

    
29

    
30
import java.io.*;
31
import java.util.Date;
32

    
33
//import es.gva.cit.wrappergdal.OGRException;
34

    
35
/** 
36
 * Representa un sistema de referencia espacial OpenGIS.
37
 * 
38
 * @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
39
 * @version 0.0
40
 * @link http://www.gvsig.gva.es
41
 */
42

    
43
public class OGRSpatialReference extends JNIBase{
44
        
45
        private native int setUTMNat(long cPtr, int zona, int norte_sur);
46
        private native int setWellKnownGeogCSNat(long cPtr, String cs);
47
        private native long OGRSpatialReferenceNat();
48
        private native String exportToWktNat(long cPtr);
49
        private native void OSRDestroySpatialReferenceNat(long cPtr);
50
        private native int getUTMZoneNat(long cPtr);
51
        private native int getHemisphereNat(long cPtr);
52
        private native int setFromUserInputNat(long cPtr, String a_srs);
53
        
54
        /**
55
         *Constructor a partir de la direcci?n de memoria 
56
         */
57
        
58
        public OGRSpatialReference(long cPtr){
59
                this.cPtr=cPtr;
60
        }
61
        
62
        /**
63
         * Constructor generico 
64
         */
65
        
66
        public OGRSpatialReference(){
67
                cPtr = OGRSpatialReferenceNat();
68
        }
69
        
70
        /**
71
         * Escribe la zona UTM pasada por par?metro
72
         * @param zona        Zona UTM
73
         * @param norte_sur        TRUE hemisferio norte y FALSE hemisferio sur
74
         * @throws OGRException
75
         */
76
        
77
        public void setUTM(int zona, boolean norte_sur)throws OGRException{
78
                
79
                if(cPtr <= 0)
80
                        throw new OGRException("Error en setUTM(). La llamada de creaci?n de objeto no tuvo exito");
81
                
82
                int ns=-1;
83
                if(norte_sur)ns=1;
84
                else ns=0;
85
                
86
                int res = setUTMNat(cPtr, zona, ns);
87
                
88
                if(res<0)
89
                        throw new OGRException("Error en setUTM(). No se ha podido asignar la zona especificada.");
90
        }
91
        
92
        /**
93
         * Lee la zona UTM 
94
         * @return Zona UTM
95
         * @throws OGRException
96
         */
97
        
98
        public int getUTMZone()throws OGRException{
99
                
100
                if(cPtr <= 0)
101
                        throw new OGRException("Error en getUTMZone(). La llamada de creaci?n de objeto no tuvo exito");
102
                
103
                int res = getUTMZoneNat(cPtr);
104
                
105
                if(res<0)
106
                        throw new OGRException("Error en getUTMZone(). Valor de zona devuelto erroneo.");
107
                
108
                return res;        
109
        }
110
        
111
        /**
112
         * Obtiene el hemisferio
113
         * @return TRUE hemisferio norte y FALSE hemisferio sur
114
         * @throws OGRException
115
         */
116
        
117
        public boolean getHemisphere()throws OGRException{
118
                
119
                if(cPtr <= 0)
120
                        throw new OGRException("Error en getHemisphere(). La llamada de creaci?n de objeto no tuvo exito");
121
                
122
                int hemis = getHemisphereNat(cPtr);
123
                                         
124
                if(hemis<0)
125
                        throw new OGRException("Error en getHemisphere(). Valor de hemisferio devuelto erroneo.");
126
                
127
                if(hemis==1)return true;
128
                else return false;
129
        }
130
        
131
        /**
132
         *Asigna las coordenadas geogr?ficas
133
         *@param cs        Coordenadas geograficas soportadas:<BR>
134
         *<UL>
135
         *<LI>WGS84</LI>
136
         *<LI>WGS72</LI>
137
         *<LI>NAD27</LI>
138
         *<LI>NAD83</LI>
139
         *<LI>EPSG:n</LI>
140
         *</UL>
141
         *@throws OGRException
142
         */
143
        
144
        public void setWellKnownGeogCS( String cs)throws OGRException{
145
                
146
                if(cPtr <= 0)
147
                        throw new OGRException("Error en setWellKnownGeogCS(). La llamada de creaci?n de objeto no tuvo exito");
148
                
149
                int res = setWellKnownGeogCSNat(cPtr, cs);
150
                
151
                if(res<0)
152
                        throw new OGRException("Error en setWellKnownGeoCS(). No se ha podido asignar el sistema de coordenadas especificado.");
153
        }
154
        
155
        /**
156
         * Devuelve la codificaci?n WKT
157
         * @return Codificaci?n WKT
158
         * @throws OGRException
159
         */
160
        public String exportToWkt()throws OGRException{
161
                
162
                if(cPtr <= 0)
163
                        throw new OGRException("Error en exportToWkt(). La llamada de creaci?n de objeto no tuvo exito");
164
                
165
                String wkt = exportToWktNat(cPtr);
166
                
167
                if(wkt==null)
168
                        throw new OGRException("Error en exportToWkt(). No se ha podido obtener la proyecci?n.");
169
                
170
                return wkt;
171
        }
172
        
173
        
174
        /**
175
         * @throws OGRException
176
         * @param a_srs        
177
         */
178
        
179
        public void setFromUserInput(String a_srs)throws OGRException{
180
                
181
                if(cPtr <= 0)
182
                        throw new OGRException("Error en setFromUserInput(). La llamada de creaci?n de objeto no tuvo exito");
183
                
184
                int ogrerr = setFromUserInputNat(cPtr,a_srs);
185
                lanzarExcepcion(ogrerr,"Error en setFromUserInput().");
186

    
187
        }
188
        
189
        
190
        /**
191
         * Destructor 
192
         */
193
        
194
        protected void finalize(){
195
                if(cPtr > 0)
196
                        OSRDestroySpatialReferenceNat(cPtr);
197
        }
198
        
199
}