Statistics
| Revision:

root / branches / v10 / libraries / libjni-gdal / src / es / gva / cit / jogr / OGRSFDriver.java @ 7847

History | View | Annotate | Download (5.53 KB)

1
/**********************************************************************
2
 * $Id: OGRSFDriver.java 7847 2006-10-04 06:55:46Z nacho $
3
 *
4
 * Name:     OGRSFDriver.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
 * 
32
 * @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
33
 * @version 0.0
34
 * @link http://www.gvsig.gva.es
35
 */
36

    
37
public class OGRSFDriver extends JNIBase{
38
        
39
        public native String getNameNat(long cPtr);
40
        private native long openNat( long cPtr, String pszName, boolean bUpdate );
41
        private native int testCapabilityNat( long cPtr,String cap );
42
        private native long createDataSourceNat( long cPtr, String pszName);                                             
43
    private native int deleteDataSourceNat( long cPtr,String pszName );//Excepciones
44
    private native long copyDataSourceNat( long cPtr, 
45
                                                                                            long poSrcDS,
46
                                                                                                String pszNewName,
47
                                                                                                String[] papszOptions);
48
        
49
        public OGRSFDriver(long cPtr){
50
                this.cPtr=cPtr;
51
        }
52

    
53
        /**
54
         * Obtiene el nombre del driver
55
         * @throws OGRException
56
         * @return Nombre del driver
57
         */
58
        
59
        public String getName()throws OGRException{
60
                
61
                if(cPtr <= 0)
62
                        throw new OGRException("Error en getName(). El constructor ha fallado.");
63
                    
64
                String name = getNameNat(cPtr);
65
                
66
                if(name==null)
67
                        throw new OGRException("Error en getName(). No se ha podido obtener el nombre del driver.");
68
                return name;
69
        }
70
        
71
        
72
        /**
73
         * 
74
         */
75
        
76
        public OGRDataSource open( String pszName, boolean bUpdate )throws OGRException{
77
                
78
                if(cPtr <= 0)
79
                        throw new OGRException("Error en open(). El constructor ha fallado.");
80
                long ptr_ds = openNat(cPtr, pszName, bUpdate);
81
                
82
                if(ptr_ds<=0)
83
                        throw new OGRException("Error en open(). No se ha podido obtener un dataset valido.");
84
                
85
                return new OGRDataSource(ptr_ds);
86
                
87
        }
88

    
89
        /**
90
         * @param capability        Capacidad del driver a testear
91
         * <UL>
92
         *   <LI>"RandomRead"</LI>
93
     *         <LI>"SequentialWrite"</LI>
94
     *   <LI>"RandomWrite"</LI>
95
     *   <LI>"FastSpatialFilter"</LI>
96
     *   <LI>"FastFeatureCount"</LI>
97
     *   <LI>"FastGetExtent"</LI>
98
     *   <LI>"CreateField"</LI>
99
     *   <LI>"Transactions"</LI>
100
     *   <LI>"DeleteFeature"</LI>
101
     *   <LI>"CreateLayer"</LI>
102
     *   <LI>"DeleteLayer"</LI>
103
     *   <LI>"CreateDataSource"</LI>
104
     *   <LI>"DeleteDataSource"</LI>
105
     * </UL>
106
         */
107
        
108
        public boolean testCapability( String capability )throws OGRException{
109
                
110
                if(cPtr <= 0)
111
                        throw new OGRException("Error en testCapability(). El constructor ha fallado.");
112
                
113
                if(capability==null || capability.equals(""))
114
                        throw new OGRException("Error en testCapability(). El par?metro pasado a la funci?n no es valido.");
115
                
116
                int res=-1;
117
                res = testCapabilityNat(cPtr, capability);
118
                
119
                if(res<0)
120
                        throw new OGRException("Error en testCapability(). No se ha podido obtener un valor de retorno valido.");
121
                
122
                if(res>=1)return true;
123
                return false;
124
        }
125

    
126
        /**
127
         * 
128
         */
129
        
130
        public OGRDataSource createDataSource( String pszName )throws OGRException{ 
131
                
132
                if(cPtr <= 0 )
133
                        throw new OGRException("Error en createDataSource(). El constructor ha fallado.");
134
                
135
                if(pszName==null || pszName.equals(""))
136
                        throw new OGRException("Error en createDataSource(). El par?metro pasado a la funci?n no es valido.");
137
                                
138
                long ptr_ds = createDataSourceNat(cPtr, pszName);
139
                
140
                if(ptr_ds<=0)
141
                        throw new OGRException("Error en createDataSource(). No se ha podido obtener un dataset valido.");
142
                
143
                return new OGRDataSource(ptr_ds);
144
        }
145

    
146
        /**
147
         * 
148
         */
149
        
150
    public void deleteDataSource( String pszName )throws OGRException{//Excepciones
151
            
152
            if(cPtr <= 0)
153
                        throw new OGRException("Error en deleteDataSource(). El constructor ha fallado.");
154
            
155
            if(pszName==null || pszName.equals(""))
156
                        throw new OGRException("Error en deleteDataSource(). El par?metro pasado a la funci?n no es valido.");
157
                
158
            int ogrerr = deleteDataSourceNat(cPtr, pszName);   
159
            lanzarExcepcion(ogrerr, "Error en deleteDataSource().");
160
   
161
    }
162

    
163
        /**
164
         * 
165
         */
166
        
167
    public OGRDataSource copyDataSource( OGRDataSource poSrcDS,
168
                                                   String pszNewName,
169
                                                   String[] papszOptions)throws OGRException{
170
            
171
            if(cPtr <= 0)
172
                        throw new OGRException("Error en copyDataSource(). El constructor ha fallado.");
173
            
174
            if(poSrcDS==null || pszNewName==null || pszNewName.equals(""))
175
                        throw new OGRException("Error en deleteDataSource().Alg?n par?metro pasado a la funci?n no es valido.");
176
                
177
            long ptr_ds = copyDataSourceNat(cPtr, poSrcDS.getPtro(), pszNewName, papszOptions);
178
                
179
                if(ptr_ds<=0)
180
                        throw new OGRException("Error en copyDataSource(). No se ha podido obtener un dataset valido.");
181
                
182
                return new OGRDataSource(ptr_ds);
183

    
184
    }
185
    
186

    
187
}