Statistics
| Revision:

root / trunk / libraries / libjni-gdal / src / es / gva / cit / jogr / OGRDataSource.java @ 1101

History | View | Annotate | Download (9.52 KB)

1
/**********************************************************************
2
 * $Id: OGRDataSource.java 1101 2005-01-19 13:12:13Z igbrotru $
3
 *
4
 * Name:     OGRDataSource.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
/** 
31
 * Esta clase representa a una fuente de datos
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 OGRDataSource extends JNIBase{
39
        
40
        private native String getNameNat(long cPtr);
41
        private native long getLayerNat(long cPtr, int i);
42
        private native void FreeOGRDataSource(long cPtr);
43
        
44
        private native long getLayerByNameNat(long cPtr, String name);
45
        private native int deleteLayerNat(long cPtr, int iLayer); //Excepciones
46
        private native int testCapabilityNat(long cPtr,  String odr );
47
        private native long createLayerNat(long cPtr, String pszName,
48
                                         long poSpatialRef,
49
                                         String eGType, //OGRwkbGeometryType OGRFeatureDefn
50
                                         String[] papszOptions);
51
        private native long copyLayerNat(long cPtr,  long poSrcLayer,
52
                                        String pszNewName,
53
                                        String[] papszOptions);
54
        private native long getStyleTableNat(long cPtr);
55
        private native long executeSQLNat(long cPtr,  String pszStatement,
56
                                        long poSpatialFilter,
57
                                        String pszDialect );
58
        private native void releaseResultSetNat(long cPtr,  long poResultsSet );
59
        private native int syncToDiskNat(long cPtr); //Excepciones
60

    
61
        
62
        /**
63
         * Constructor
64
         * @param cPtr        direcci?n de memoria al objeto OGRDataSource de C. 
65
         */
66
        
67
        public OGRDataSource(long cPtr){
68
                this.cPtr=cPtr;
69
        }
70
                
71
        /**
72
         * Obtiene el nombre del datasource
73
         * @throws OGRException
74
         * @return Nombre del datasource
75
         */
76
        
77
        public String getName()throws OGRException{
78
                
79
                if(cPtr <= 0)
80
                        throw new OGRException("Error en getName(). El constructor ha fallado.");
81
                    
82
                String name = getNameNat(cPtr);
83
                
84
                if(name==null)
85
                        throw new OGRException("Error en getName(). No se ha podido obtener el nombre del datasource.");
86
                return name;
87
        }
88
        
89
        /**
90
         * Obtiene el n?mero de capas
91
         * @throws OGRException
92
         * @return N?mero de capas
93
         */
94
        
95
         public int getLayerCount()throws OGRException{
96
                        
97
                String msg1="Error en getLayerCount. El constructor no tuvo exito.";
98
                String msg2="Error en el conteo de capas.";
99
                return baseSimpleFunctions(1,msg1,msg2);
100
         }
101
         
102
         /**
103
         * Obtiene la capa indicada por el ?ndice
104
         * @throws OGRException
105
         * @return una capa
106
         */
107
                        
108
         public OGRLayer getLayer(int i)throws OGRException{
109
                                
110
                 if(cPtr <= 0)
111
                        throw new OGRException("Error en getLayer(). El constructor no tuvo exito");
112
                            
113
                long layer = getLayerNat(cPtr, i);
114
                
115
                if(layer<=0)
116
                        throw new OGRException("Error en getLayer(). No se ha podido obtener la capa indicada.");
117
                                                
118
                return new OGRLayer(layer);
119
                        
120
         }
121

    
122
         
123
        /**
124
         * Destructor 
125
         */
126
        
127
        protected void finalize(){
128
                if(cPtr > 0)
129
                        FreeOGRDataSource(cPtr);
130
        }
131
         
132
        /**
133
         * 
134
         */
135
        
136
        public OGRLayer getLayerByName(String name)throws OGRException{
137
                
138
                if(cPtr <= 0)
139
                        throw new OGRException("Error en getLayerByName(). El constructor no tuvo exito");
140
                
141
                long ptr_name = getLayerByNameNat(cPtr, name);
142
                
143
                if(ptr_name<=0)
144
                        throw new OGRException("Error en getLayerByName(). No se ha podido obtener un puntero a un OGRLayer valido.");
145
                return new OGRLayer(ptr_name);
146
                    
147
    }
148
    
149
        /**
150
         * 
151
         */
152
        
153
    public void deleteLayer(int iLayer)throws OGRException{ //Excepciones
154
            
155
            if(cPtr <= 0)
156
                        throw new OGRException("Error en deleteLayer(). El constructor no tuvo exito");
157
                
158
            int ogrerr = deleteLayerNat(cPtr, iLayer);
159
            lanzarExcepcion(ogrerr, "Error en deleteLayer()");
160
    }
161

    
162
    /**
163
         * 
164
         */
165
    
166
    public int testCapability( String odr )throws OGRException{
167
            
168
            if(cPtr <= 0)
169
                        throw new OGRException("Error en testCapability(). El constructor no tuvo exito");
170
                
171
            int res=-1;
172
                res = testCapabilityNat(cPtr, odr);
173
                
174
                if(res<0)
175
                        throw new OGRException("Error en testCapability(). No se ha podido obtener un valor de retorno valido.");
176

    
177
                return res;
178
    }
179

    
180
    /**
181
         * 
182
         */
183
    
184
    public OGRLayer createLayer(String pszName,
185
                                     OGRSpatialReference poSpatialRef,
186
                                     String eGType, //OGRwkbGeometryType OGRFeatureDefn
187
                                     String[] papszOptions)throws OGRException{
188
            if(cPtr <= 0)
189
                        throw new OGRException("Error en createLayer(). El constructor no tuvo exito");
190
            
191
            if(poSpatialRef.getPtro()<=0)
192
                    throw new OGRException("Error en createLayer(). Referencia del par?metro OGRSpatialReference invalida.");
193
            
194
            long ptr_layer = createLayerNat(cPtr, pszName, poSpatialRef.getPtro(), eGType, papszOptions);
195
            if(ptr_layer<0)
196
                        throw new OGRException("Error en createLayer(). No se ha podido obtener una referencia valida a un OGRLayer.");
197
            return new OGRLayer(ptr_layer);
198
            
199
            
200
                    
201
    }
202
    
203
    /**
204
         * 
205
         */
206
    
207
    public OGRLayer copyLayer( OGRLayer poSrcLayer,
208
                                    String pszNewName,
209
                                    String[] papszOptions)throws OGRException{
210
            if(cPtr <= 0)
211
                        throw new OGRException("Error en copyLayer(). El constructor no tuvo exito");
212
                
213
            if(poSrcLayer.getPtro()<=0)
214
                    throw new OGRException("Error en copyLayer(). Referencia del par?metro OGRSpatialReference invalida.");
215
            
216
            long ptr_layer = copyLayerNat(cPtr, poSrcLayer.getPtro(), pszNewName, papszOptions);
217
            if(ptr_layer<=0)
218
                        throw new OGRException("Error en copyLayer(). No se ha podido obtener una referencia valida a un OGRLayer.");
219
            
220
            return new OGRLayer(ptr_layer);
221
                         
222
    }
223
    
224
    /**
225
         * 
226
         */
227
    
228
    public OGRStyleTable getStyleTable()throws OGRException{
229
            
230
            if(cPtr <= 0)
231
                        throw new OGRException("Error en getStyleTable(). El constructor no tuvo exito");
232
                
233
            long ptr_styletable = getStyleTableNat(cPtr);
234
            if(ptr_styletable<=0)
235
                        throw new OGRException("Error en getStyleTable(). No se ha podido obtener una referencia valida a un OGRStyleTable.");
236
            
237
            return new OGRStyleTable(ptr_styletable);
238
            
239
            
240
    }
241

    
242
    /**
243
         * 
244
         */
245
    
246
    public OGRLayer executeSQL( String pszStatement,
247
                                    OGRGeometry poSpatialFilter,
248
                                    String pszDialect )throws OGRException{
249
            
250
            if(cPtr <= 0)
251
                        throw new OGRException("Error en executeSQL(). El constructor no tuvo exito");
252
                
253
            if(poSpatialFilter.getPtro()<=0)
254
                    throw new OGRException("Error en executeSQL(). Referencia del par?metro OGRGeometry invalida.");
255
            
256
            long ptr_layer = executeSQLNat(cPtr, pszStatement, poSpatialFilter.getPtro(), pszDialect);
257
            if(ptr_layer<=0)
258
                        throw new OGRException("Error en executeSQL(). No se ha podido obtener una referencia valida a un OGRLayer.");
259
            
260
            return new OGRLayer(ptr_layer);
261
            
262
    }
263
    
264
    /**
265
         * 
266
         */
267
    
268
    public void releaseResultSet( OGRLayer poResultsSet )throws OGRException{
269
            
270
            if(cPtr <= 0)
271
                        throw new OGRException("Error en poResultsSet(). El constructor no tuvo exito");
272
                
273
            if(poResultsSet.getPtro()<=0)
274
                    throw new OGRException("Error en poResultsSet(). Referencia del par?metro OGRLayer invalida.");
275
            
276
            releaseResultSetNat(cPtr, poResultsSet.getPtro());
277
    }
278

    
279
    /**
280
         * 
281
         */
282
    
283
    public void syncToDisk()throws OGRException{//Excepciones
284
            
285
            if(cPtr <= 0)
286
                        throw new OGRException("Error en syncToDisk(). El constructor no tuvo exito");
287
                
288
            int ogrerr = syncToDiskNat(cPtr);
289
            lanzarExcepcion(ogrerr, "Error en syncToDisk().");
290
    }
291

    
292
    /**
293
         * 
294
         */
295
    
296
    public int reference()throws OGRException{
297
            
298
            String msg1="Error en reference(). El constructor no tuvo exito.";
299
                String msg2="Error en reference().";
300
                return baseSimpleFunctions(6,msg1,msg2);
301
    }
302
    
303
    /**
304
         * 
305
         */
306
    
307
    public int dereference()throws OGRException{
308
            
309
            String msg1="Error en dereference(). El constructor no tuvo exito.";
310
                String msg2="Error en dereference().";
311
                return baseSimpleFunctions(7,msg1,msg2);
312
    }
313
    
314
    /**
315
         * 
316
         */
317
    
318
    public int getRefCount()throws OGRException{
319
            
320
            String msg1="Error en getRefCount(). El constructor no tuvo exito.";
321
                String msg2="Error en getRefCount(). No se ha obtenido un n?mero de referencias valido.";
322
                return baseSimpleFunctions(8,msg1,msg2);
323
    }
324
    
325
    /**
326
         * 
327
         */
328
    
329
    public int getSummaryRefCount()throws OGRException{
330
            
331
            String msg1="Error en getSummaryRefCount(). El constructor no tuvo exito.";
332
                String msg2="Error en getSummaryRefCount().";
333
                return baseSimpleFunctions(9,msg1,msg2);
334
    } 
335
         
336
                  
337
         
338
}
339

    
340

    
341