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 / OGRDataSource.java @ 3497
History | View | Annotate | Download (10.4 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: OGRDataSource.java 7765 2006-10-03 07:05:18Z nacho $
|
3 |
*
|
4 |
* Name: OGRDataSource.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 java.util.Arrays; |
30 |
import java.util.Vector; |
31 |
|
32 |
import org.gdal.ogr.DataSource; |
33 |
import org.gdal.ogr.Layer; |
34 |
import org.gdal.ogr.StyleTable; |
35 |
|
36 |
|
37 |
/**
|
38 |
* Esta clase representa a una fuente de datos
|
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 |
public class OGRDataSource extends DataSource { |
46 |
|
47 |
// private native String getNameNat(long cPtr);
|
48 |
// private native long getLayerNat(long cPtr, int i);
|
49 |
// private native void FreeOGRDataSource(long cPtr);
|
50 |
//
|
51 |
// private native long getLayerByNameNat(long cPtr, String name);
|
52 |
// private native int deleteLayerNat(long cPtr, int iLayer); //Excepciones
|
53 |
// private native int testCapabilityNat(long cPtr, String odr );
|
54 |
// private native long createLayerNat(long cPtr, String pszName,
|
55 |
// long poSpatialRef,
|
56 |
// String eGType, //OGRwkbGeometryType OGRFeatureDefn
|
57 |
// String[] papszOptions);
|
58 |
// private native long copyLayerNat(long cPtr, long poSrcLayer,
|
59 |
// String pszNewName,
|
60 |
// String[] papszOptions);
|
61 |
// private native long getStyleTableNat(long cPtr);
|
62 |
// private native long executeSQLNat(long cPtr, String pszStatement,
|
63 |
// long poSpatialFilter,
|
64 |
// String pszDialect );
|
65 |
// private native void releaseResultSetNat(long cPtr, long poResultsSet );
|
66 |
// private native int syncToDiskNat(long cPtr); //Excepciones
|
67 |
|
68 |
|
69 |
/**
|
70 |
* Constructor
|
71 |
* @param cPtr direcci?n de memoria al objeto OGRDataSource de C.
|
72 |
*/
|
73 |
|
74 |
public OGRDataSource(long cPtr){ |
75 |
super(cPtr, true); |
76 |
} |
77 |
|
78 |
/**
|
79 |
* Obtiene el nombre del datasource
|
80 |
* @return Nombre del datasource
|
81 |
*/
|
82 |
|
83 |
public String getName(){ |
84 |
|
85 |
// if(cPtr == 0)
|
86 |
// throw new OGRException("Error en getName(). El constructor ha fallado.");
|
87 |
|
88 |
String name = this.GetName(); |
89 |
|
90 |
// if(name==null)
|
91 |
// throw new OGRException("Error en getName(). No se ha podido obtener el nombre del datasource.");
|
92 |
|
93 |
return name;
|
94 |
} |
95 |
|
96 |
/**
|
97 |
* Obtiene el n?mero de capas
|
98 |
* @throws OGRException
|
99 |
* @return N?mero de capas
|
100 |
*/
|
101 |
|
102 |
public int getLayerCount()throws OGRException{ |
103 |
return this.GetLayerCount(); |
104 |
} |
105 |
|
106 |
/**
|
107 |
* Obtiene la capa indicada por el ?ndice
|
108 |
* @throws OGRException
|
109 |
* @return una capa
|
110 |
*/
|
111 |
|
112 |
public OGRLayer getLayer(int i)throws OGRException{ |
113 |
|
114 |
// if(cPtr == 0)
|
115 |
// throw new OGRException("Error en getLayer(). El constructor no tuvo exito");
|
116 |
|
117 |
if(i<0) |
118 |
throw new OGRException("Error en getLayer(). Par?metro no valido"); |
119 |
|
120 |
Layer layer = this.GetLayer(i);
|
121 |
|
122 |
if(layer==null || !(layer instanceof OGRLayer)) |
123 |
throw new OGRException("Error en getLayer(). No se ha podido obtener la capa indicada."); |
124 |
|
125 |
return (OGRLayer)layer;
|
126 |
|
127 |
} |
128 |
|
129 |
|
130 |
/**
|
131 |
* Destructor
|
132 |
*/
|
133 |
|
134 |
protected void finalize() { |
135 |
// if(cPtr == 0)
|
136 |
// throw new OGRFailureException("Fallo al acceder al dato.");
|
137 |
//
|
138 |
// FreeOGRDataSource(cPtr);
|
139 |
this.delete();
|
140 |
} |
141 |
|
142 |
/**
|
143 |
*
|
144 |
*/
|
145 |
|
146 |
public OGRLayer getLayerByName(String name)throws OGRException{ |
147 |
|
148 |
// if(cPtr == 0)
|
149 |
// throw new OGRException("Error en getLayerByName(). El constructor no tuvo exito");
|
150 |
|
151 |
if(name==null || name.equals("")) |
152 |
throw new OGRException("Error en getLayerByName(). Par?metro no valido"); |
153 |
|
154 |
Layer ptr_name = this.GetLayerByName(name);
|
155 |
|
156 |
if(ptr_name==null || !(ptr_name instanceof OGRLayer)) |
157 |
throw new OGRException("Error en getLayerByName(). No se ha podido obtener un puntero a un OGRLayer valido."); |
158 |
|
159 |
return (OGRLayer)ptr_name;
|
160 |
|
161 |
} |
162 |
|
163 |
/**
|
164 |
*
|
165 |
*/
|
166 |
|
167 |
public void deleteLayer(int iLayer)throws OGRException{ //Excepciones |
168 |
|
169 |
// if(cPtr == 0)
|
170 |
// throw new OGRException("Error en deleteLayer(). El constructor no tuvo exito");
|
171 |
|
172 |
if(iLayer<0) |
173 |
throw new OGRException("Error en deleteLayer(). Par?metro no valido"); |
174 |
|
175 |
int ogrerr = this.DeleteLayer(iLayer); |
176 |
// throwException(ogrerr, "Error en deleteLayer()");
|
177 |
} |
178 |
|
179 |
/**
|
180 |
*
|
181 |
*/
|
182 |
|
183 |
public int testCapability( String odr )throws OGRException{ |
184 |
|
185 |
// if(cPtr == 0)
|
186 |
// throw new OGRException("Error en testCapability(). El constructor no tuvo exito");
|
187 |
|
188 |
if(odr==null || odr.equals("")) |
189 |
throw new OGRException("Error en testCapability(). Par?metro no valido"); |
190 |
|
191 |
boolean res= this.TestCapability(odr); |
192 |
|
193 |
// if(res == 0)
|
194 |
// throw new OGRException("Error en testCapability(). No se ha podido obtener un valor de retorno valido.");
|
195 |
|
196 |
int r = 0; |
197 |
if(res){
|
198 |
r=1;
|
199 |
} |
200 |
|
201 |
return r;
|
202 |
} |
203 |
|
204 |
/**
|
205 |
*
|
206 |
*/
|
207 |
|
208 |
public OGRLayer createLayer(String pszName, |
209 |
OGRSpatialReference poSpatialRef, |
210 |
String eGType, //OGRwkbGeometryType OGRFeatureDefn |
211 |
String[] papszOptions)throws OGRException{ |
212 |
long ptro_sr = 0; |
213 |
|
214 |
// if(cPtr == 0)
|
215 |
// throw new OGRException("Error en createLayer(). El constructor no tuvo exito");
|
216 |
|
217 |
if(pszName==null || pszName.equals("")) |
218 |
throw new OGRException("Error en createLayer(). Par?metros en la funci?n no validos."); |
219 |
|
220 |
if(poSpatialRef == null || poSpatialRef == null) |
221 |
throw new OGRException("Error en createLayer(). Par?metro OGRSpatialReference no valido."); |
222 |
|
223 |
|
224 |
Layer layer = this.CreateLayer(
|
225 |
pszName, |
226 |
poSpatialRef, |
227 |
OGRTools.getTypeID(eGType), |
228 |
new Vector(Arrays.asList(papszOptions))); |
229 |
|
230 |
if(layer == null && !(layer instanceof OGRLayer)) |
231 |
throw new OGRException("Error en createLayer(). No se ha podido obtener una referencia valida a un OGRLayer."); |
232 |
|
233 |
return ((OGRLayer)layer);
|
234 |
} |
235 |
|
236 |
/**
|
237 |
*
|
238 |
*/
|
239 |
|
240 |
public OGRLayer copyLayer( OGRLayer poSrcLayer,
|
241 |
String pszNewName,
|
242 |
String[] papszOptions)throws OGRException{ |
243 |
// if(cPtr == 0)
|
244 |
// throw new OGRException("Error en copyLayer(). El constructor no tuvo exito");
|
245 |
|
246 |
if(pszNewName == null || pszNewName.equals("") || poSrcLayer == null) |
247 |
throw new OGRException("Error en copyLayer(). Par?metros en la funci?n no validos."); |
248 |
|
249 |
Layer layer = this.CopyLayer(poSrcLayer, pszNewName, OGRTools.safeStringArrayToVector(papszOptions));
|
250 |
if(layer == null || !(layer instanceof OGRLayer)) |
251 |
throw new OGRException("Error en copyLayer(). No se ha podido obtener una referencia valida a un OGRLayer."); |
252 |
|
253 |
return ((OGRLayer)layer);
|
254 |
|
255 |
} |
256 |
|
257 |
/**
|
258 |
*
|
259 |
*/
|
260 |
|
261 |
public OGRStyleTable getStyleTable()throws OGRException{ |
262 |
|
263 |
// if(cPtr == 0)
|
264 |
// throw new OGRException("Error en getStyleTable(). El constructor no tuvo exito");
|
265 |
|
266 |
StyleTable styletable = this.GetStyleTable();
|
267 |
if(styletable==null) |
268 |
throw new OGRException("Error en getStyleTable(). No se ha podido obtener una referencia valida a un OGRStyleTable."); |
269 |
|
270 |
return (OGRStyleTable)styletable;
|
271 |
|
272 |
} |
273 |
|
274 |
/**
|
275 |
*
|
276 |
*/
|
277 |
|
278 |
public OGRLayer executeSQL( String pszStatement, |
279 |
OGRGeometry poSpatialFilter, |
280 |
String pszDialect )throws OGRException{ |
281 |
|
282 |
// if(cPtr == 0)
|
283 |
// throw new OGRException("Error en executeSQL(). El constructor no tuvo exito");
|
284 |
|
285 |
if(pszStatement==null || pszStatement.equals("") || poSpatialFilter==null) |
286 |
throw new OGRException("Error en executeSQL(). Par?metros en la funci?n no validos."); |
287 |
|
288 |
Layer layer = this.ExecuteSQL(pszStatement, poSpatialFilter, pszDialect);
|
289 |
if(layer == null || !(layer instanceof OGRLayer)) |
290 |
throw new OGRException("Error en executeSQL(). No se ha podido obtener una referencia valida a un OGRLayer."); |
291 |
|
292 |
return ((OGRLayer)layer);
|
293 |
|
294 |
} |
295 |
|
296 |
/**
|
297 |
*
|
298 |
*/
|
299 |
|
300 |
public void releaseResultSet( OGRLayer poResultsSet )throws OGRException{ |
301 |
|
302 |
// if(cPtr == 0)
|
303 |
// throw new OGRException("Error en poResultsSet(). El constructor no tuvo exito");
|
304 |
|
305 |
if(poResultsSet == null) |
306 |
throw new OGRException("Error en releaseResultSet(). Par?metro en la funci?n no valido."); |
307 |
|
308 |
// if(poResultsSet.getPtro() == 0)
|
309 |
// throw new OGRException("Error en poResultsSet(). Referencia del par?metro OGRLayer invalida.");
|
310 |
|
311 |
this.ReleaseResultSet(poResultsSet);
|
312 |
} |
313 |
|
314 |
/**
|
315 |
*
|
316 |
*/
|
317 |
|
318 |
public void syncToDisk()throws OGRException{//Excepciones |
319 |
|
320 |
// if(cPtr == 0)
|
321 |
// throw new OGRException("Error en syncToDisk(). El constructor no tuvo exito");
|
322 |
|
323 |
int ogrerr = this.SyncToDisk(); |
324 |
// throwException(ogrerr, "Error en syncToDisk().");
|
325 |
} |
326 |
|
327 |
/**
|
328 |
*
|
329 |
*/
|
330 |
|
331 |
// public int reference()throws OGRException{
|
332 |
//
|
333 |
// String msg1="Error en reference(). El constructor no tuvo exito.";
|
334 |
// String msg2="Error en reference().";
|
335 |
// return baseSimpleFunctions(6,msg1,msg2);
|
336 |
// }
|
337 |
|
338 |
/**
|
339 |
*
|
340 |
*/
|
341 |
|
342 |
// public int dereference()throws OGRException{
|
343 |
//
|
344 |
// String msg1="Error en dereference(). El constructor no tuvo exito.";
|
345 |
// String msg2="Error en dereference().";
|
346 |
// return baseSimpleFunctions(7,msg1,msg2);
|
347 |
// }
|
348 |
|
349 |
/**
|
350 |
*
|
351 |
*/
|
352 |
|
353 |
public int getRefCount()throws OGRException{ |
354 |
return this.GetRefCount(); |
355 |
} |
356 |
|
357 |
/**
|
358 |
*
|
359 |
*/
|
360 |
|
361 |
public int getSummaryRefCount()throws OGRException{ |
362 |
return this.GetSummaryRefCount(); |
363 |
} |
364 |
|
365 |
|
366 |
|
367 |
} |
368 |
|
369 |
|
370 |
|