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