Statistics
| Revision:

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 / OGRFeatureDefn.java @ 3497

History | View | Annotate | Download (7.79 KB)

1
/**********************************************************************
2
 * $Id: OGRFeatureDefn.java 7765 2006-10-03 07:05:18Z nacho $
3
 *
4
 * Name:     OGRFeatureDefn.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 org.gvsig.jogr;
28

    
29
import org.gdal.ogr.FeatureDefn;
30
import org.gdal.ogr.FieldDefn;
31

    
32

    
33
/** 
34
 * 
35
 * @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
36
 * @version 0.0
37
 * @link http://www.gvsig.gva.es
38
 */
39

    
40
public class OGRFeatureDefn extends FeatureDefn{
41

    
42
        
43
//        private native String getNameNat(long cPtr);
44
//        private native int getGeomTypeNat(long cPtr);
45
//        private native void FreeOGRFeatureDefnNat(long cPtr);
46
//        private native long getFieldDefnNat(long cPtr, int i);
47
//        
48
//        private native int getFieldIndexNat( long cPtr, String indice );
49
//        private native void addFieldDefnNat( long cPtr, long fd );
50
//        private native void setGeomTypeNat( long cPtr, String gtype ); //OGRwkbGeometryType OGRFeatureDefn
51
//        private native long cloneFeatureDefnNat(long cPtr );
52
        private native static long createFeatureDefnNat( String pszName);
53
//        private native static void destroyFeatureDefnNat( long fd );
54
        
55
        
56
        /**
57
         * Constructor
58
         * @param cPtr        direcci?n de memoria al objeto OGRFeatureDefn de C. 
59
         */
60
        
61
        public OGRFeatureDefn(long cPtr){
62
                super(cPtr, true);
63
        }
64
        
65
        /**
66
         * Obtiene el nombre de la feature
67
         * @throws OGRException
68
         * @return Nombre de la feature
69
         */
70
        
71
        public String getName()throws OGRException{
72
                
73
//                if(cPtr == 0)
74
//                        throw new OGRException("Error en getName(). El constructor ha fallado.");
75
                    
76
                String name = this.GetName();
77
                
78
                if(name==null)
79
                        throw new OGRException("Error en getName(). No se ha podido obtener el nombre.");
80
                return name;
81
        }
82
        
83
        /**
84
         * Obtiene el tipo de geometria
85
         * @throws OGRException
86
         * @return Tipo de geometria 
87
         */
88
        
89
        public String getGeomType()throws OGRException{
90
                
91
//                if(cPtr == 0)
92
//                        throw new OGRException("Error en getGeomType(). El constructor ha fallado.");
93
                    
94
                int tipo = this.GetGeomType();
95
                
96
                if(tipo<0 || tipo>16)
97
                        throw new OGRException("Error en getGeomType(). No se ha podido obtener un tipo de geometria valido.");
98
                
99
                String tipogeom=null;
100
                switch(tipo){
101
                        case 0:tipogeom="wkbUnknown";break;                   /* non-standard */
102
                        case 1:tipogeom="wkbPoint"; break;              /* rest are standard WKB type codes */
103
                        case 2:tipogeom="wkbLineString";break;
104
                        case 3:tipogeom="wkbPolygon";break;
105
                        case 4:tipogeom="wkbMultiPoint";break;
106
                        case 5:tipogeom="wkbMultiLineString";break;
107
                        case 6:tipogeom="wkbMultiPolygon";break;
108
                        case 7:tipogeom="wkbGeometryCollection";break;
109
                        case 8:tipogeom="wkbNone";break;                           /* non-standard, for pure attribute records */
110
                        case 9:tipogeom="wkbLinearRing";break;                     /* non-standard, just for createGeometry() */
111
                        case 10:tipogeom="wkbPoint25D";break;                   /* 2.5D extensions as per 99-402 */
112
                        case 11:tipogeom="wkbLineString25D";break;
113
                        case 12:tipogeom="wkbPolygon25D";break;
114
                        case 13:tipogeom="wkbMultiPoint25D";break;
115
                        case 14:tipogeom="wkbMultiLineString25D";break;
116
                        case 15:tipogeom="wkbMultiPolygon25D";break;
117
                        case 16:tipogeom="wkbGeometryCollection25D";break;
118
                }
119
                return tipogeom;
120
                
121
        }
122
        
123
        /**
124
         * Obtiene el n?mero de campos
125
         * @throws OGRException
126
         * @return N?mero de campos
127
         */
128
        
129
        public int getFieldCount()throws OGRException{
130
                
131
                return this.GetFieldCount();
132
        }
133
        
134
        /**
135
         * Obtiene el campo referenciado por el ?ndice
136
         * @throws OGRException
137
         * @return Objeto que contiene el campo seleccionado
138
         */
139
        
140
        public OGRFieldDefn getFieldDefn(int i)throws OGRException{
141
                
142
//                if(cPtr == 0)
143
//                        throw new OGRException("Error en getFieldDefn(). El constructor ha fallado.");
144
                
145
                FieldDefn f = this.GetFieldDefn(i);
146
                if(f == null || !(f instanceof OGRFieldDefn))
147
                        throw new OGRException("Error en getGeomType(). No se ha podido obtener un tipo de geometria valido.");
148
                 
149
                OGRFieldDefn field = ((OGRFieldDefn)f);
150
                return field;
151
        }
152
        
153
        /**
154
         * Destructor 
155
         */
156
        
157
        protected void finalize(){
158
//                if(cPtr == 0)
159
//                        throw new OGRFailureException("Fallo al acceder al dato.");
160
//                
161
//                FreeOGRFeatureDefnNat(cPtr);
162
                this.delete();
163
        }
164
        
165
        /**
166
         * 
167
         */
168
        
169
        public int getFieldIndex( String field )throws OGRException{
170
                
171
//                if(cPtr == 0)
172
//                        throw new OGRException("Error en getFieldIndex(). El constructor ha fallado.");
173
                
174
                if(field == null)
175
                        throw new OGRException("Error en getFieldIndex(). Par?metro invalido.");
176
                
177
                int index =  this.GetFieldIndex(field);
178
                
179
                if(index == 0)
180
                        throw new OGRException("Error en getFieldIndex(). No se ha podido obtener un ?ndice valido.");
181
                return index;
182
                
183
        }
184
        
185
        /**
186
         * 
187
         */
188
        
189
        public void addFieldDefn( OGRFieldDefn fd )throws OGRException{
190
                
191
//                if(cPtr == 0)
192
//                        throw new OGRException("Error en addFieldDefn(). El constructor ha fallado.");
193
                
194
                if(fd == null)
195
                        throw new OGRException("Error en addFieldDefn(). La referencia del par?metro OGRFieldDefn no es valida.");
196
                
197
                this.AddFieldDefn(fd);
198
                
199
        }
200
        
201
        /**
202
         * 
203
         */
204
                
205
        public void setGeomType( String gtype )throws OGRException{ //OGRwkbGeometryType OGRFeatureDefn
206
                
207
//                if(cPtr == 0)
208
//                        throw new OGRException("Error en setGeomType(). El constructor ha fallado.");
209
                
210
                this.SetGeomType(OGRTools.getTypeID(gtype));
211
        }
212

    
213
        /**
214
         * 
215
         */
216
                
217
        public OGRFeatureDefn cloneFeatureDefn()throws OGRException{
218
                
219
//                if(cPtr == 0)
220
//                        throw new OGRException("Error en cloneFeatureDefn(). El constructor ha fallado.");
221
                
222
                OGRFeatureDefn fd;
223
                try {
224
                        fd = (OGRFeatureDefn) this.clone();
225
                } catch (CloneNotSupportedException e) {
226
                        throw new OGRException(e.getMessage());
227
                }
228
                
229
                if(fd == null)
230
                        throw new OGRException("Error en cloneFeatureDefn(). No se ha podido obtener un valor de referencia valido para OGRFeatureDefn.");
231
                
232
                return fd;
233
                
234
        }
235

    
236
        /**
237
         * 
238
         */
239
                
240
//        public int reference()throws OGRException{//*
241
//                
242
//                String msg1="Error en reference(). El constructor no tuvo exito.";
243
//                String msg2="Error en reference().";
244
//                return baseSimpleFunctions(10,msg1,msg2);
245
//        }
246

    
247
        /**
248
         * 
249
         */
250
                
251
//        public int dereference()throws OGRException{//*
252
//
253
//                String msg1="Error en dereference(). El constructor no tuvo exito.";
254
//                String msg2="Error en dereference().";
255
//                return baseSimpleFunctions(11,msg1,msg2);
256
//        }
257

    
258
        /**
259
         * 
260
         */
261
                
262
        public int getReferenceCount()throws OGRException{
263
                
264
                return this.GetReferenceCount();
265
        }
266
        
267
        /**
268
         * 
269
         */
270

    
271
        public static OGRFeatureDefn createFeatureDefn( String pszName)throws OGRException{
272
                
273
                if(pszName == null)
274
                        throw new OGRException("Error en createFeatureDefn(). Par?metro invalido.");
275
                
276
                long ptr_fd = createFeatureDefnNat( pszName);
277
                
278
                if(ptr_fd == 0)
279
                        throw new OGRException("Error en cloneFeatureDefn(). No se ha podido obtener un valor de referencia valido para OGRFeatureDefn.");
280
                
281
                return new OGRFeatureDefn(ptr_fd);
282
                
283
                
284
                
285
        }
286

    
287
        /**
288
         * 
289
         */
290

    
291
        
292
        public static void destroyFeatureDefn( OGRFeatureDefn fd )throws OGRException{
293
                
294
                if(fd == null)
295
                        throw new OGRException("Error en destroyFeatureDefn(). Par?metro invalido.");
296
                
297
                fd.delete();
298
        }
299

    
300

    
301
}