svn-gvsig-desktop / trunk / libraries / libjni-gdal / src / es / gva / cit / jogr / OGRLayer.java @ 1249
History | View | Annotate | Download (12.4 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: OGRLayer.java 1249 2005-01-28 12:22:25Z igbrotru $
|
3 |
*
|
4 |
* Name: OGRLayer.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 |
|
38 |
public class OGRLayer extends JNIBase{ |
39 |
|
40 |
public native long getLayerDefnNat(long cPtr); |
41 |
public native void resetReadingNat(long cPtr); |
42 |
public native int getExtentNat(long cPtr, OGREnvelope extent, boolean bForce); |
43 |
private native void FreeOGRLayerNat(long cPtr); |
44 |
private native long getNextFeatureNat(long cPtr); |
45 |
|
46 |
private native long getSpatialFilterNat(long cPtr); |
47 |
private native void setSpatialFilterNat( long cPtr, long geom ); |
48 |
private native int setAttributeFilterNat( long cPtr, String att ); //Excepciones |
49 |
private native long getFeatureNat( long cPtr, long nFID ); |
50 |
private native int setFeatureNat( long cPtr, long poFeature );//Excepciones |
51 |
private native int createFeatureNat( long cPtr, long poFeature );//Excepciones |
52 |
private native int deleteFeatureNat( long cPtr, long nFID );//Excepciones |
53 |
private native long getSpatialRefNat(long cPtr); |
54 |
private native int testCapabilityNat( long cPtr, String od ); |
55 |
private native String getInfoNat( long cPtr, String s ); |
56 |
private native int createFieldNat( long cPtr, long poField, int bApproxOK);//Excepciones |
57 |
private native long getStyleTableNat(long cPtr); |
58 |
private native void setStyleTableNat(long cPtr, long poStyleTable); |
59 |
private native int initializeIndexSupportNat( long cPtr, String s );//Excepciones |
60 |
private native long getIndexNat(long cPtr); |
61 |
private native int syncToDiskNat(long cPtr); |
62 |
private native int commitTransactionNat(long cPtr); |
63 |
private native int rollbackTransactionNat(long cPtr); |
64 |
private native int referenceNat(long cPtr); |
65 |
private native int dereferenceNat(long cPtr); |
66 |
private native int startTransactionNat(long cPtr); |
67 |
|
68 |
/**
|
69 |
* Constructor
|
70 |
* @param cPtr direcci?n de memoria al objeto OGRLayer de C.
|
71 |
*/
|
72 |
|
73 |
public OGRLayer(long cPtr){ |
74 |
this.cPtr=cPtr;
|
75 |
} |
76 |
|
77 |
|
78 |
/**
|
79 |
*
|
80 |
* @throws OGRException
|
81 |
* @return
|
82 |
*/
|
83 |
|
84 |
public OGRFeatureDefn getLayerDefn()throws OGRException{ |
85 |
|
86 |
if(cPtr <= 0) |
87 |
throw new OGRException("Error en getLayerDefn(). El constructor no tuvo exito"); |
88 |
|
89 |
long layer = getLayerDefnNat(cPtr);
|
90 |
|
91 |
if(layer<=0) |
92 |
throw new OGRException("Error en getLayerDefn(). No se ha podido obtener el objeto OGRFeatureDefn."); |
93 |
|
94 |
return new OGRFeatureDefn(layer); |
95 |
|
96 |
} |
97 |
|
98 |
/**
|
99 |
*
|
100 |
*/
|
101 |
public void resetReading()throws OGRException{ |
102 |
|
103 |
if(cPtr <= 0) |
104 |
throw new OGRException("Error en resetReading(). El constructor no tuvo exito"); |
105 |
|
106 |
resetReadingNat(cPtr); |
107 |
} |
108 |
|
109 |
/**
|
110 |
* Obtiene el n?mero de caracteristicas
|
111 |
* @throws OGRException
|
112 |
* @return N?mero de caracteristicas
|
113 |
*/
|
114 |
|
115 |
public int getFeatureCount()throws OGRException{ |
116 |
|
117 |
String msg1="Error en getFeatureCount. El constructor no tuvo exito."; |
118 |
String msg2="Error en el conteo de caracteristicas."; |
119 |
return baseSimpleFunctions(2,msg1,msg2); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Obtiene el extent de la capa
|
124 |
* @throws OGRException
|
125 |
* @return objeto conteniendo el extent
|
126 |
*/
|
127 |
|
128 |
public OGREnvelope getExtent(boolean bForce)throws OGRException{ |
129 |
|
130 |
if(cPtr <= 0) |
131 |
throw new OGRException("Error en getExtent(). El constructor no tuvo exito"); |
132 |
|
133 |
OGREnvelope extent = new OGREnvelope();
|
134 |
|
135 |
int err;
|
136 |
err = getExtentNat(cPtr, extent, bForce); |
137 |
|
138 |
if(err!=0) |
139 |
lanzarExcepcion(err,"Error em getFeatureCount()");
|
140 |
|
141 |
return extent;
|
142 |
|
143 |
} |
144 |
|
145 |
/**
|
146 |
*
|
147 |
*/
|
148 |
|
149 |
public OGRFeature getNextFeature()throws OGRException{ |
150 |
|
151 |
OGRFeature feature = null;
|
152 |
if(cPtr <= 0) |
153 |
throw new OGRException("Error en getNextFeature(). El constructor no tuvo exito"); |
154 |
|
155 |
long ptro_feat = getNextFeatureNat(cPtr);
|
156 |
if(ptro_feat >=0) |
157 |
feature = new OGRFeature(ptro_feat);
|
158 |
return feature;
|
159 |
} |
160 |
|
161 |
/**
|
162 |
* Destructor
|
163 |
*/
|
164 |
|
165 |
protected void finalize(){ |
166 |
if(cPtr > 0) |
167 |
FreeOGRLayerNat(cPtr); |
168 |
} |
169 |
|
170 |
/**
|
171 |
*
|
172 |
*/
|
173 |
|
174 |
public OGRGeometry getSpatialFilter()throws OGRException{ |
175 |
|
176 |
if(cPtr <= 0) |
177 |
throw new OGRException("Error en getSpatialFilter(). El constructor no tuvo exito"); |
178 |
|
179 |
long ptr_sf = getSpatialFilterNat(cPtr);
|
180 |
|
181 |
if(ptr_sf <= 0) |
182 |
throw new OGRException("Error en getSpatialFilter(). No se ha podido obtener un OGRGeometry valido."); |
183 |
|
184 |
OGRGeometry geom = new OGRGeometry(ptr_sf);
|
185 |
return geom;
|
186 |
|
187 |
} |
188 |
|
189 |
/**
|
190 |
*
|
191 |
*/
|
192 |
|
193 |
public void setSpatialFilter( OGRGeometry geom )throws OGRException{ |
194 |
|
195 |
if(cPtr <= 0) |
196 |
throw new OGRException("Error en setSpatialFilter(). El constructor no tuvo exito"); |
197 |
|
198 |
if(geom.getPtro()<=0) |
199 |
throw new OGRException("Error en setSpatialFilter(). El objeto OGRGeometry no tiene un puntero valido."); |
200 |
|
201 |
setSpatialFilterNat(cPtr,geom.getPtro()); |
202 |
} |
203 |
|
204 |
/**
|
205 |
*
|
206 |
*/
|
207 |
|
208 |
public void setAttributeFilter( String att) throws OGRException{ //Excepciones |
209 |
|
210 |
if(cPtr <= 0) |
211 |
throw new OGRException("Error en setAttributeFilter(). El constructor no tuvo exito"); |
212 |
|
213 |
setAttributeFilterNat(cPtr, att); |
214 |
} |
215 |
|
216 |
/**
|
217 |
*
|
218 |
*/
|
219 |
|
220 |
public OGRFeature getFeature( long nFID )throws OGRException{ |
221 |
|
222 |
if(cPtr <= 0) |
223 |
throw new OGRException("Error en getFeature(). El constructor no tuvo exito"); |
224 |
|
225 |
long ptr_f = getFeatureNat(cPtr, nFID);
|
226 |
|
227 |
if(ptr_f <= 0) |
228 |
throw new OGRException("Error en getFeature(). No se ha podido obtener un OGRFeature valido."); |
229 |
|
230 |
OGRFeature feature = new OGRFeature(ptr_f);
|
231 |
return feature;
|
232 |
|
233 |
} |
234 |
|
235 |
/**
|
236 |
*
|
237 |
*/
|
238 |
|
239 |
public void setFeature( OGRFeature poFeature )throws OGRException{//Excepciones |
240 |
|
241 |
if(cPtr <= 0) |
242 |
throw new OGRException("Error en setFeature(). El constructor no tuvo exito"); |
243 |
|
244 |
if(poFeature.getPtro()<=0) |
245 |
throw new OGRException("Error en setFeature(). El objeto OGRFeature no tiene un puntero valido."); |
246 |
|
247 |
setFeatureNat(cPtr, poFeature.getPtro()); |
248 |
} |
249 |
|
250 |
/**
|
251 |
*
|
252 |
*/
|
253 |
|
254 |
public void createFeature( OGRFeature poFeature )throws OGRException{//Excepciones |
255 |
|
256 |
if(cPtr <= 0) |
257 |
throw new OGRException("Error en createFeature(). El constructor no tuvo exito"); |
258 |
|
259 |
if(poFeature.getPtro()<=0) |
260 |
throw new OGRException("Error en createFeature(). El objeto OGRFeature no tiene un puntero valido."); |
261 |
|
262 |
createFeatureNat(cPtr,poFeature.getPtro()); |
263 |
|
264 |
} |
265 |
|
266 |
/**
|
267 |
*
|
268 |
*/
|
269 |
|
270 |
public void deleteFeature( long nFID )throws OGRException{//Excepciones |
271 |
|
272 |
if(cPtr <= 0) |
273 |
throw new OGRException("Error en deleteFeature(). El constructor no tuvo exito"); |
274 |
|
275 |
deleteFeatureNat(cPtr, nFID); |
276 |
|
277 |
} |
278 |
|
279 |
/**
|
280 |
* Obtiene el sistema de referencia espacial para esta capa o nulo si no tiene.
|
281 |
* @throws OGRException
|
282 |
* @return Sistema de referencia espacial
|
283 |
*/
|
284 |
|
285 |
public OGRSpatialReference getSpatialRef()throws OGRException{ |
286 |
|
287 |
OGRSpatialReference sr=null;
|
288 |
|
289 |
if(cPtr <= 0) |
290 |
throw new OGRException("Error en getSpatialRef(). El constructor no tuvo exito"); |
291 |
|
292 |
long ptr_sr = getSpatialRefNat(cPtr);
|
293 |
|
294 |
if(ptr_sr > 0) |
295 |
sr = new OGRSpatialReference(ptr_sr);
|
296 |
|
297 |
return sr;
|
298 |
} |
299 |
|
300 |
/**
|
301 |
*
|
302 |
*/
|
303 |
|
304 |
public int testCapability( String od )throws OGRException{ |
305 |
|
306 |
if(cPtr <= 0) |
307 |
throw new OGRException("Error en testCapability(). El constructor ha fallado."); |
308 |
|
309 |
int res=-1; |
310 |
res = testCapabilityNat(cPtr, od); |
311 |
|
312 |
if(res<0) |
313 |
throw new OGRException("Error en testCapability(). No se ha podido obtener un valor de retorno valido."); |
314 |
|
315 |
return res;
|
316 |
|
317 |
} |
318 |
|
319 |
/**
|
320 |
*
|
321 |
*/
|
322 |
|
323 |
public String getInfo( String s )throws OGRException{ |
324 |
|
325 |
if(cPtr <= 0) |
326 |
throw new OGRException("Error en getInfo(). El constructor no tuvo exito"); |
327 |
|
328 |
String info = getInfoNat(cPtr, s);
|
329 |
if(info==null) |
330 |
throw new OGRException("Error en getInfo(). No se ha podido obtener informaci?n valida."); |
331 |
|
332 |
return info;
|
333 |
} |
334 |
|
335 |
/**
|
336 |
*
|
337 |
*/
|
338 |
|
339 |
public void createField( OGRFieldDefn poField, int bApproxOK)throws OGRException{//Excepciones |
340 |
|
341 |
if(cPtr <= 0) |
342 |
throw new OGRException("Error en greateField(). El constructor no tuvo exito"); |
343 |
|
344 |
if(poField.getPtro() <= 0) |
345 |
throw new OGRException("Error en greateField(). El objeto OGRFieldDefn no tiene una direcci?n de memoria valida."); |
346 |
|
347 |
int res = createFieldNat(cPtr, poField.getPtro(), bApproxOK);
|
348 |
lanzarExcepcion(res, "Error en greateField().");
|
349 |
|
350 |
} |
351 |
|
352 |
/**
|
353 |
*
|
354 |
*/
|
355 |
|
356 |
public void syncToDisk()throws OGRException{//Excepciones |
357 |
|
358 |
if(cPtr <= 0) |
359 |
throw new OGRException("Error en syncToDisk(). El constructor no tuvo exito"); |
360 |
int ogrerr = syncToDiskNat(cPtr);
|
361 |
lanzarExcepcion(ogrerr, "Error en syncToDisk()");
|
362 |
|
363 |
} |
364 |
|
365 |
/**
|
366 |
*
|
367 |
*/
|
368 |
|
369 |
public OGRStyleTable getStyleTable()throws OGRException{ |
370 |
|
371 |
if(cPtr <= 0) |
372 |
throw new OGRException("Error en getStyleTable(). El constructor no tuvo exito"); |
373 |
|
374 |
long ptr_st = getStyleTableNat(cPtr);
|
375 |
if(ptr_st<=0) |
376 |
throw new OGRException("Error en getStyleTable(). No se ha podido obtener un objeto OGRStyleTable valido."); |
377 |
OGRStyleTable st=new OGRStyleTable(ptr_st);
|
378 |
|
379 |
return st;
|
380 |
} |
381 |
|
382 |
/**
|
383 |
*
|
384 |
*/
|
385 |
|
386 |
public void setStyleTable(OGRStyleTable poStyleTable)throws OGRException{ |
387 |
|
388 |
if(cPtr <= 0) |
389 |
throw new OGRException("Error en setStyleTable(). El constructor no tuvo exito"); |
390 |
|
391 |
setStyleTableNat(cPtr, poStyleTable.getPtro()); |
392 |
|
393 |
} |
394 |
|
395 |
/**
|
396 |
*
|
397 |
*/
|
398 |
|
399 |
public void startTransaction()throws OGRException{//Excepciones |
400 |
|
401 |
if(cPtr <= 0) |
402 |
throw new OGRException("Error en startTransaction(). El constructor no tuvo exito"); |
403 |
|
404 |
int ogrerr = startTransactionNat(cPtr);
|
405 |
lanzarExcepcion(ogrerr,"Error en startTransaction().");
|
406 |
} |
407 |
|
408 |
/**
|
409 |
*
|
410 |
*/
|
411 |
|
412 |
public void commitTransaction()throws OGRException{//Excepciones |
413 |
|
414 |
if(cPtr <= 0) |
415 |
throw new OGRException("Error en commitTransaction(). El constructor no tuvo exito"); |
416 |
|
417 |
int ogrerr = commitTransactionNat(cPtr);
|
418 |
lanzarExcepcion(ogrerr,"Error en commitTransaction().");
|
419 |
|
420 |
} |
421 |
|
422 |
/**
|
423 |
*
|
424 |
*/
|
425 |
|
426 |
public void rollbackTransaction()throws OGRException{//Excepciones |
427 |
|
428 |
if(cPtr <= 0) |
429 |
throw new OGRException("Error en rollbackTransaction(). El constructor no tuvo exito"); |
430 |
|
431 |
int ogrerr = rollbackTransactionNat(cPtr);
|
432 |
lanzarExcepcion(ogrerr,"Error en rollbackTransaction().");
|
433 |
} |
434 |
|
435 |
/**
|
436 |
*
|
437 |
*/
|
438 |
|
439 |
public int reference()throws OGRException{ |
440 |
|
441 |
if(cPtr <= 0) |
442 |
throw new OGRException("Error en reference(). El constructor no tuvo exito"); |
443 |
|
444 |
return referenceNat(cPtr);
|
445 |
} |
446 |
|
447 |
/**
|
448 |
*
|
449 |
*/
|
450 |
|
451 |
public int dereference()throws OGRException{ |
452 |
|
453 |
if(cPtr <= 0) |
454 |
throw new OGRException("Error en dereference(). El constructor no tuvo exito"); |
455 |
|
456 |
return dereferenceNat(cPtr);
|
457 |
} |
458 |
|
459 |
/**
|
460 |
*
|
461 |
*/
|
462 |
|
463 |
public int getRefCount()throws OGRException{ |
464 |
|
465 |
String msg1="Error en getRefCount. El constructor no tuvo exito."; |
466 |
String msg2="Error en getRefCount. No se ha podido obtener un n?mero de referencias valido."; |
467 |
return baseSimpleFunctions(20,msg1,msg2); |
468 |
} |
469 |
|
470 |
/**
|
471 |
*
|
472 |
*/
|
473 |
|
474 |
public void initializeIndexSupport( String s )throws OGRException{//Excepciones |
475 |
|
476 |
if(cPtr <= 0) |
477 |
throw new OGRException("Error en initializeIndexSupport(). El constructor no tuvo exito"); |
478 |
|
479 |
initializeIndexSupportNat(cPtr, s); |
480 |
} |
481 |
|
482 |
/**
|
483 |
*
|
484 |
*/
|
485 |
|
486 |
public OGRLayerAttrIndex getIndex()throws OGRException{ |
487 |
|
488 |
if(cPtr <= 0) |
489 |
throw new OGRException("Error en getIndex(). El constructor no tuvo exito"); |
490 |
|
491 |
long ptr_lai = getIndexNat(cPtr);
|
492 |
if(ptr_lai<=0) |
493 |
throw new OGRException("Error en getIndex(). No se ha podido obtener un OGRLayerAttrIndex valido."); |
494 |
OGRLayerAttrIndex layerattrin = new OGRLayerAttrIndex(ptr_lai);
|
495 |
return layerattrin;
|
496 |
|
497 |
} |
498 |
} |