root / trunk / libraries / libjni-gdal / src / es / gva / cit / jogr / OGRFeatureDefn.java @ 7765
History | View | Annotate | Download (8.53 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 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 OGRFeatureDefn extends JNIBase{ |
38 |
|
39 |
|
40 |
private native String getNameNat(long cPtr); |
41 |
private native int getGeomTypeNat(long cPtr); |
42 |
private native void FreeOGRFeatureDefnNat(long cPtr); |
43 |
private native long getFieldDefnNat(long cPtr, int i); |
44 |
|
45 |
private native int getFieldIndexNat( long cPtr, String indice ); |
46 |
private native void addFieldDefnNat( long cPtr, long fd ); |
47 |
private native void setGeomTypeNat( long cPtr, String gtype ); //OGRwkbGeometryType OGRFeatureDefn |
48 |
private native long cloneFeatureDefnNat(long cPtr ); |
49 |
private native static long createFeatureDefnNat( String pszName); |
50 |
private native static void destroyFeatureDefnNat( long fd ); |
51 |
|
52 |
|
53 |
/**
|
54 |
* Constructor
|
55 |
* @param cPtr direcci?n de memoria al objeto OGRFeatureDefn de C.
|
56 |
*/
|
57 |
|
58 |
public OGRFeatureDefn(long cPtr){ |
59 |
this.cPtr=cPtr;
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* Obtiene el nombre de la feature
|
64 |
* @throws OGRException
|
65 |
* @return Nombre de la feature
|
66 |
*/
|
67 |
|
68 |
public String getName()throws OGRException{ |
69 |
|
70 |
if(cPtr <= 0) |
71 |
throw new OGRException("Error en getName(). El constructor ha fallado."); |
72 |
|
73 |
String name = getNameNat(cPtr);
|
74 |
|
75 |
if(name==null) |
76 |
throw new OGRException("Error en getName(). No se ha podido obtener el nombre."); |
77 |
return name;
|
78 |
} |
79 |
|
80 |
/**
|
81 |
* Obtiene el tipo de geometria
|
82 |
* @throws OGRException
|
83 |
* @return Tipo de geometria
|
84 |
*/
|
85 |
|
86 |
public String getGeomType()throws OGRException{ |
87 |
|
88 |
if(cPtr <= 0) |
89 |
throw new OGRException("Error en getGeomType(). El constructor ha fallado."); |
90 |
|
91 |
int tipo = getGeomTypeNat(cPtr);
|
92 |
|
93 |
if(tipo<0 || tipo>16) |
94 |
throw new OGRException("Error en getGeomType(). No se ha podido obtener un tipo de geometria valido."); |
95 |
|
96 |
String tipogeom=null; |
97 |
switch(tipo){
|
98 |
case 0:tipogeom="wkbUnknown";break; /* non-standard */ |
99 |
case 1:tipogeom="wkbPoint"; break; /* rest are standard WKB type codes */ |
100 |
case 2:tipogeom="wkbLineString";break; |
101 |
case 3:tipogeom="wkbPolygon";break; |
102 |
case 4:tipogeom="wkbMultiPoint";break; |
103 |
case 5:tipogeom="wkbMultiLineString";break; |
104 |
case 6:tipogeom="wkbMultiPolygon";break; |
105 |
case 7:tipogeom="wkbGeometryCollection";break; |
106 |
case 8:tipogeom="wkbNone";break; /* non-standard, for pure attribute records */ |
107 |
case 9:tipogeom="wkbLinearRing";break; /* non-standard, just for createGeometry() */ |
108 |
case 10:tipogeom="wkbPoint25D";break; /* 2.5D extensions as per 99-402 */ |
109 |
case 11:tipogeom="wkbLineString25D";break; |
110 |
case 12:tipogeom="wkbPolygon25D";break; |
111 |
case 13:tipogeom="wkbMultiPoint25D";break; |
112 |
case 14:tipogeom="wkbMultiLineString25D";break; |
113 |
case 15:tipogeom="wkbMultiPolygon25D";break; |
114 |
case 16:tipogeom="wkbGeometryCollection25D";break; |
115 |
} |
116 |
return tipogeom;
|
117 |
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* Obtiene el n?mero de campos
|
122 |
* @throws OGRException
|
123 |
* @return N?mero de campos
|
124 |
*/
|
125 |
|
126 |
public int getFieldCount()throws OGRException{ |
127 |
|
128 |
String msg1="Error en getFieldCount. El constructor ha fallado."; |
129 |
String msg2="Error obteniendo el n?mero de campos"; |
130 |
return baseSimpleFunctions(3,msg1,msg2); |
131 |
} |
132 |
|
133 |
/**
|
134 |
* Obtiene el campo referenciado por el ?ndice
|
135 |
* @throws OGRException
|
136 |
* @return Objeto que contiene el campo seleccionado
|
137 |
*/
|
138 |
|
139 |
public OGRFieldDefn getFieldDefn(int i)throws OGRException{ |
140 |
|
141 |
if(cPtr <= 0) |
142 |
throw new OGRException("Error en getFieldDefn(). El constructor ha fallado."); |
143 |
|
144 |
long id = getFieldDefnNat(cPtr,i);
|
145 |
if(id<=0) |
146 |
throw new OGRException("Error en getGeomType(). No se ha podido obtener un tipo de geometria valido."); |
147 |
|
148 |
OGRFieldDefn field = new OGRFieldDefn(id);
|
149 |
return field;
|
150 |
} |
151 |
|
152 |
/**
|
153 |
* Destructor
|
154 |
*/
|
155 |
|
156 |
protected void finalize(){ |
157 |
if(cPtr > 0) |
158 |
FreeOGRFeatureDefnNat(cPtr); |
159 |
} |
160 |
|
161 |
/**
|
162 |
*
|
163 |
*/
|
164 |
|
165 |
public int getFieldIndex( String field )throws OGRException{ |
166 |
|
167 |
if(cPtr <= 0) |
168 |
throw new OGRException("Error en getFieldIndex(). El constructor ha fallado."); |
169 |
|
170 |
if(field==null) |
171 |
throw new OGRException("Error en getFieldIndex(). Par?metro invalido."); |
172 |
int index = getFieldIndexNat(cPtr, field);
|
173 |
|
174 |
if(index<0) |
175 |
throw new OGRException("Error en getFieldIndex(). No se ha podido obtener un ?ndice valido."); |
176 |
return index;
|
177 |
|
178 |
} |
179 |
|
180 |
/**
|
181 |
*
|
182 |
*/
|
183 |
|
184 |
public void addFieldDefn( OGRFieldDefn fd )throws OGRException{ |
185 |
|
186 |
if(cPtr <= 0) |
187 |
throw new OGRException("Error en addFieldDefn(). El constructor ha fallado."); |
188 |
|
189 |
if(fd==null || fd.getPtro() <= 0) |
190 |
throw new OGRException("Error en addFieldDefn(). La referencia del par?metro OGRFieldDefn no es valida."); |
191 |
|
192 |
addFieldDefnNat(cPtr, fd.getPtro()); |
193 |
|
194 |
} |
195 |
|
196 |
/**
|
197 |
*
|
198 |
*/
|
199 |
|
200 |
public void setGeomType( String gtype )throws OGRException{ //OGRwkbGeometryType OGRFeatureDefn |
201 |
|
202 |
if(cPtr <= 0) |
203 |
throw new OGRException("Error en setGeomType(). El constructor ha fallado."); |
204 |
|
205 |
boolean ok=false; |
206 |
if(gtype!=null && (gtype.equals("wkbUnknown") || |
207 |
gtype.equals("wkbPoint") ||
|
208 |
gtype.equals("wkbLineString") ||
|
209 |
gtype.equals("wkbPolygon") ||
|
210 |
gtype.equals("wkbMultiPoint") ||
|
211 |
gtype.equals("wkbMultiLineString") ||
|
212 |
gtype.equals("wkbMultiPolygon") ||
|
213 |
gtype.equals("wkbGeometryCollection") ||
|
214 |
gtype.equals("wkbNone") ||
|
215 |
gtype.equals("wkbLinearRing") ||
|
216 |
gtype.equals("wkbPoint25D") ||
|
217 |
gtype.equals("wkbLineString25D") ||
|
218 |
gtype.equals("wkbPolygon25D") ||
|
219 |
gtype.equals("wkbMultiPoint25D") ||
|
220 |
gtype.equals("wkbMultiLineString25D") ||
|
221 |
gtype.equals("wkbMultiPolygon25D") ||
|
222 |
gtype.equals("wkbGeometryCollection25D")))ok=true; |
223 |
|
224 |
if(!ok)
|
225 |
throw new OGRException("Error en setGeomType(). Par?metro invalido"); |
226 |
|
227 |
setGeomTypeNat(cPtr, gtype); |
228 |
} |
229 |
|
230 |
/**
|
231 |
*
|
232 |
*/
|
233 |
|
234 |
public OGRFeatureDefn cloneFeatureDefn()throws OGRException{ |
235 |
|
236 |
if(cPtr <= 0) |
237 |
throw new OGRException("Error en cloneFeatureDefn(). El constructor ha fallado."); |
238 |
|
239 |
long ptr_fd = cloneFeatureDefnNat(cPtr);
|
240 |
if(ptr_fd<=0) |
241 |
throw new OGRException("Error en cloneFeatureDefn(). No se ha podido obtener un valor de referencia valido para OGRFeatureDefn."); |
242 |
return new OGRFeatureDefn(ptr_fd); |
243 |
|
244 |
} |
245 |
|
246 |
/**
|
247 |
*
|
248 |
*/
|
249 |
|
250 |
public int reference()throws OGRException{//* |
251 |
|
252 |
String msg1="Error en reference(). El constructor no tuvo exito."; |
253 |
String msg2="Error en reference()."; |
254 |
return baseSimpleFunctions(10,msg1,msg2); |
255 |
} |
256 |
|
257 |
/**
|
258 |
*
|
259 |
*/
|
260 |
|
261 |
public int dereference()throws OGRException{//* |
262 |
|
263 |
String msg1="Error en dereference(). El constructor no tuvo exito."; |
264 |
String msg2="Error en dereference()."; |
265 |
return baseSimpleFunctions(11,msg1,msg2); |
266 |
} |
267 |
|
268 |
/**
|
269 |
*
|
270 |
*/
|
271 |
|
272 |
public int getReferenceCount()throws OGRException{ |
273 |
|
274 |
String msg1="Error en getReferenceCount(). El constructor no tuvo exito."; |
275 |
String msg2="Error en getReferenceCount(). No se ha obtenido un n?mero de referencias valido."; |
276 |
return baseSimpleFunctions(12,msg1,msg2); |
277 |
} |
278 |
|
279 |
/**
|
280 |
*
|
281 |
*/
|
282 |
|
283 |
public static OGRFeatureDefn createFeatureDefn( String pszName)throws OGRException{ |
284 |
|
285 |
if(pszName == null) |
286 |
throw new OGRException("Error en createFeatureDefn(). Par?metro invalido."); |
287 |
|
288 |
long ptr_fd = createFeatureDefnNat( pszName);
|
289 |
|
290 |
if(ptr_fd<=0) |
291 |
throw new OGRException("Error en cloneFeatureDefn(). No se ha podido obtener un valor de referencia valido para OGRFeatureDefn."); |
292 |
return new OGRFeatureDefn(ptr_fd); |
293 |
|
294 |
|
295 |
|
296 |
} |
297 |
|
298 |
/**
|
299 |
*
|
300 |
*/
|
301 |
|
302 |
|
303 |
public static void destroyFeatureDefn( OGRFeatureDefn fd )throws OGRException{ |
304 |
|
305 |
if(fd == null || fd.getPtro()<=0) |
306 |
throw new OGRException("Error en destroyFeatureDefn(). Par?metro invalido."); |
307 |
|
308 |
destroyFeatureDefnNat( fd.getPtro()); |
309 |
} |
310 |
|
311 |
|
312 |
} |