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