gvsig-raster / org.gvsig.raster.gdal / trunk / org.gvsig.raster.gdal / org.gvsig.raster.gdal.jni / src / main / java / org / gvsig / jogr / OGRLayer.java @ 2453
History | View | Annotate | Download (12.6 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: OGRLayer.java 7765 2006-10-03 07:05:18Z nacho $
|
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 org.gvsig.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 |
throwException(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() throws OGRFailureException{ |
166 |
if(cPtr == 0) |
167 |
throw new OGRFailureException("Fallo al acceder al dato."); |
168 |
|
169 |
FreeOGRLayerNat(cPtr); |
170 |
} |
171 |
|
172 |
/**
|
173 |
*
|
174 |
*/
|
175 |
|
176 |
public OGRGeometry getSpatialFilter()throws OGRException{ |
177 |
|
178 |
if(cPtr == 0) |
179 |
throw new OGRException("Error en getSpatialFilter(). El constructor no tuvo exito"); |
180 |
|
181 |
long ptr_sf = getSpatialFilterNat(cPtr);
|
182 |
|
183 |
if(ptr_sf == 0) |
184 |
throw new OGRException("Error en getSpatialFilter(). No se ha podido obtener un OGRGeometry valido."); |
185 |
|
186 |
OGRGeometry geom = new OGRGeometry(ptr_sf);
|
187 |
return geom;
|
188 |
|
189 |
} |
190 |
|
191 |
/**
|
192 |
*
|
193 |
*/
|
194 |
|
195 |
public void setSpatialFilter( OGRGeometry geom )throws OGRException{ |
196 |
|
197 |
if(cPtr == 0) |
198 |
throw new OGRException("Error en setSpatialFilter(). El constructor no tuvo exito"); |
199 |
|
200 |
if(geom.getPtro() == 0) |
201 |
throw new OGRException("Error en setSpatialFilter(). El objeto OGRGeometry no tiene un puntero valido."); |
202 |
|
203 |
setSpatialFilterNat(cPtr,geom.getPtro()); |
204 |
} |
205 |
|
206 |
/**
|
207 |
*
|
208 |
*/
|
209 |
|
210 |
public void setAttributeFilter( String att) throws OGRException{ //Excepciones |
211 |
|
212 |
if(cPtr == 0) |
213 |
throw new OGRException("Error en setAttributeFilter(). El constructor no tuvo exito"); |
214 |
|
215 |
setAttributeFilterNat(cPtr, att); |
216 |
} |
217 |
|
218 |
/**
|
219 |
*
|
220 |
*/
|
221 |
|
222 |
public OGRFeature getFeature( long nFID )throws OGRException{ |
223 |
|
224 |
if(cPtr == 0) |
225 |
throw new OGRException("Error en getFeature(). El constructor no tuvo exito"); |
226 |
|
227 |
long ptr_f = getFeatureNat(cPtr, nFID);
|
228 |
|
229 |
if(ptr_f == 0) |
230 |
throw new OGRException("Error en getFeature(). No se ha podido obtener un OGRFeature valido."); |
231 |
|
232 |
OGRFeature feature = new OGRFeature(ptr_f);
|
233 |
return feature;
|
234 |
|
235 |
} |
236 |
|
237 |
/**
|
238 |
*
|
239 |
*/
|
240 |
|
241 |
public void setFeature( OGRFeature poFeature )throws OGRException{//Excepciones |
242 |
|
243 |
if(cPtr == 0) |
244 |
throw new OGRException("Error en setFeature(). El constructor no tuvo exito"); |
245 |
|
246 |
if(poFeature.getPtro() == 0) |
247 |
throw new OGRException("Error en setFeature(). El objeto OGRFeature no tiene un puntero valido."); |
248 |
|
249 |
setFeatureNat(cPtr, poFeature.getPtro()); |
250 |
} |
251 |
|
252 |
/**
|
253 |
*
|
254 |
*/
|
255 |
|
256 |
public void createFeature( OGRFeature poFeature )throws OGRException{//Excepciones |
257 |
|
258 |
if(cPtr == 0) |
259 |
throw new OGRException("Error en createFeature(). El constructor no tuvo exito"); |
260 |
|
261 |
if(poFeature.getPtro()==0) |
262 |
throw new OGRException("Error en createFeature(). El objeto OGRFeature no tiene un puntero valido."); |
263 |
|
264 |
createFeatureNat(cPtr,poFeature.getPtro()); |
265 |
|
266 |
} |
267 |
|
268 |
/**
|
269 |
*
|
270 |
*/
|
271 |
|
272 |
public void deleteFeature( long nFID )throws OGRException{//Excepciones |
273 |
|
274 |
if(cPtr == 0) |
275 |
throw new OGRException("Error en deleteFeature(). El constructor no tuvo exito"); |
276 |
|
277 |
deleteFeatureNat(cPtr, nFID); |
278 |
|
279 |
} |
280 |
|
281 |
/**
|
282 |
* Obtiene el sistema de referencia espacial para esta capa o nulo si no tiene.
|
283 |
* @throws OGRException
|
284 |
* @return Sistema de referencia espacial
|
285 |
*/
|
286 |
|
287 |
public OGRSpatialReference getSpatialRef()throws OGRException{ |
288 |
|
289 |
OGRSpatialReference sr=null;
|
290 |
|
291 |
if(cPtr == 0) |
292 |
throw new OGRException("Error en getSpatialRef(). El constructor no tuvo exito"); |
293 |
|
294 |
long ptr_sr = getSpatialRefNat(cPtr);
|
295 |
|
296 |
if(ptr_sr == 0) |
297 |
throw new OGRException("Error en getSpatialRef()."); |
298 |
|
299 |
sr = new OGRSpatialReference(ptr_sr);
|
300 |
|
301 |
return sr;
|
302 |
} |
303 |
|
304 |
/**
|
305 |
*
|
306 |
*/
|
307 |
|
308 |
public int testCapability( String od )throws OGRException{ |
309 |
|
310 |
if(cPtr == 0) |
311 |
throw new OGRException("Error en testCapability(). El constructor ha fallado."); |
312 |
|
313 |
int res=-1; |
314 |
res = testCapabilityNat(cPtr, od); |
315 |
|
316 |
if(res==0) |
317 |
throw new OGRException("Error en testCapability(). No se ha podido obtener un valor de retorno valido."); |
318 |
|
319 |
return res;
|
320 |
|
321 |
} |
322 |
|
323 |
/**
|
324 |
*
|
325 |
*/
|
326 |
|
327 |
public String getInfo( String s )throws OGRException{ |
328 |
|
329 |
if(cPtr == 0) |
330 |
throw new OGRException("Error en getInfo(). El constructor no tuvo exito"); |
331 |
|
332 |
String info = getInfoNat(cPtr, s);
|
333 |
|
334 |
if(info == null) |
335 |
throw new OGRException("Error en getInfo(). No se ha podido obtener informaci?n valida."); |
336 |
|
337 |
return info;
|
338 |
} |
339 |
|
340 |
/**
|
341 |
*
|
342 |
*/
|
343 |
|
344 |
public void createField( OGRFieldDefn poField, int bApproxOK)throws OGRException{//Excepciones |
345 |
|
346 |
if(cPtr == 0) |
347 |
throw new OGRException("Error en greateField(). El constructor no tuvo exito"); |
348 |
|
349 |
if(poField.getPtro() == 0) |
350 |
throw new OGRException("Error en greateField(). El objeto OGRFieldDefn no tiene una direcci?n de memoria valida."); |
351 |
|
352 |
int res = createFieldNat(cPtr, poField.getPtro(), bApproxOK);
|
353 |
throwException(res, "Error en greateField().");
|
354 |
|
355 |
} |
356 |
|
357 |
/**
|
358 |
*
|
359 |
*/
|
360 |
|
361 |
public void syncToDisk()throws OGRException{//Excepciones |
362 |
|
363 |
if(cPtr == 0) |
364 |
throw new OGRException("Error en syncToDisk(). El constructor no tuvo exito"); |
365 |
int ogrerr = syncToDiskNat(cPtr);
|
366 |
throwException(ogrerr, "Error en syncToDisk()");
|
367 |
|
368 |
} |
369 |
|
370 |
/**
|
371 |
*
|
372 |
*/
|
373 |
|
374 |
public OGRStyleTable getStyleTable()throws OGRException{ |
375 |
|
376 |
if(cPtr == 0) |
377 |
throw new OGRException("Error en getStyleTable(). El constructor no tuvo exito"); |
378 |
|
379 |
long ptr_st = getStyleTableNat(cPtr);
|
380 |
|
381 |
if(ptr_st == 0) |
382 |
throw new OGRException("Error en getStyleTable(). No se ha podido obtener un objeto OGRStyleTable valido."); |
383 |
|
384 |
OGRStyleTable st=new OGRStyleTable(ptr_st);
|
385 |
|
386 |
return st;
|
387 |
} |
388 |
|
389 |
/**
|
390 |
*
|
391 |
*/
|
392 |
|
393 |
public void setStyleTable(OGRStyleTable poStyleTable)throws OGRException{ |
394 |
|
395 |
if(cPtr == 0) |
396 |
throw new OGRException("Error en setStyleTable(). El constructor no tuvo exito"); |
397 |
|
398 |
setStyleTableNat(cPtr, poStyleTable.getPtro()); |
399 |
|
400 |
} |
401 |
|
402 |
/**
|
403 |
*
|
404 |
*/
|
405 |
|
406 |
public void startTransaction()throws OGRException{//Excepciones |
407 |
|
408 |
if(cPtr == 0) |
409 |
throw new OGRException("Error en startTransaction(). El constructor no tuvo exito"); |
410 |
|
411 |
int ogrerr = startTransactionNat(cPtr);
|
412 |
throwException(ogrerr,"Error en startTransaction().");
|
413 |
} |
414 |
|
415 |
/**
|
416 |
*
|
417 |
*/
|
418 |
|
419 |
public void commitTransaction()throws OGRException{//Excepciones |
420 |
|
421 |
if(cPtr == 0) |
422 |
throw new OGRException("Error en commitTransaction(). El constructor no tuvo exito"); |
423 |
|
424 |
int ogrerr = commitTransactionNat(cPtr);
|
425 |
throwException(ogrerr,"Error en commitTransaction().");
|
426 |
|
427 |
} |
428 |
|
429 |
/**
|
430 |
*
|
431 |
*/
|
432 |
|
433 |
public void rollbackTransaction()throws OGRException{//Excepciones |
434 |
|
435 |
if(cPtr == 0) |
436 |
throw new OGRException("Error en rollbackTransaction(). El constructor no tuvo exito"); |
437 |
|
438 |
int ogrerr = rollbackTransactionNat(cPtr);
|
439 |
throwException(ogrerr,"Error en rollbackTransaction().");
|
440 |
} |
441 |
|
442 |
/**
|
443 |
*
|
444 |
*/
|
445 |
|
446 |
public int reference()throws OGRException{ |
447 |
|
448 |
if(cPtr == 0) |
449 |
throw new OGRException("Error en reference(). El constructor no tuvo exito"); |
450 |
|
451 |
return referenceNat(cPtr);
|
452 |
} |
453 |
|
454 |
/**
|
455 |
*
|
456 |
*/
|
457 |
|
458 |
public int dereference()throws OGRException{ |
459 |
|
460 |
if(cPtr == 0) |
461 |
throw new OGRException("Error en dereference(). El constructor no tuvo exito"); |
462 |
|
463 |
return dereferenceNat(cPtr);
|
464 |
} |
465 |
|
466 |
/**
|
467 |
*
|
468 |
*/
|
469 |
|
470 |
public int getRefCount()throws OGRException{ |
471 |
|
472 |
String msg1="Error en getRefCount. El constructor no tuvo exito."; |
473 |
String msg2="Error en getRefCount. No se ha podido obtener un n?mero de referencias valido."; |
474 |
return baseSimpleFunctions(20,msg1,msg2); |
475 |
} |
476 |
|
477 |
/**
|
478 |
*
|
479 |
*/
|
480 |
|
481 |
public void initializeIndexSupport( String s )throws OGRException{//Excepciones |
482 |
|
483 |
if(cPtr == 0) |
484 |
throw new OGRException("Error en initializeIndexSupport(). El constructor no tuvo exito"); |
485 |
|
486 |
initializeIndexSupportNat(cPtr, s); |
487 |
} |
488 |
|
489 |
/**
|
490 |
*
|
491 |
*/
|
492 |
|
493 |
public OGRLayerAttrIndex getIndex()throws OGRException{ |
494 |
|
495 |
if(cPtr == 0) |
496 |
throw new OGRException("Error en getIndex(). El constructor no tuvo exito"); |
497 |
|
498 |
long ptr_lai = getIndexNat(cPtr);
|
499 |
|
500 |
if(ptr_lai == 0) |
501 |
throw new OGRException("Error en getIndex(). No se ha podido obtener un OGRLayerAttrIndex valido."); |
502 |
|
503 |
OGRLayerAttrIndex layerattrin = new OGRLayerAttrIndex(ptr_lai);
|
504 |
return layerattrin;
|
505 |
|
506 |
} |
507 |
} |