root / trunk / libraries / libjni-gdal / src / es / gva / cit / jgdal / GdalDriver.java @ 7765
History | View | Annotate | Download (6.85 KB)
1 |
/**********************************************************************
|
---|---|
2 |
* $Id: GdalDriver.java 7765 2006-10-03 07:05:18Z nacho $
|
3 |
*
|
4 |
* Name: Gdal.java
|
5 |
* Project: JGDAL. Interface java to gdal (Frank Warmerdam).
|
6 |
* Purpose:
|
7 |
* Author: Nacho Brodin, brodin_ign@gva.es
|
8 |
*
|
9 |
**********************************************************************/
|
10 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
11 |
*
|
12 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
13 |
*
|
14 |
* This program is free software; you can redistribute it and/or
|
15 |
* modify it under the terms of the GNU General Public License
|
16 |
* as published by the Free Software Foundation; either version 2
|
17 |
* of the License, or (at your option) any later version.
|
18 |
*
|
19 |
* This program is distributed in the hope that it will be useful,
|
20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22 |
* GNU General Public License for more details.
|
23 |
*
|
24 |
* You should have received a copy of the GNU General Public License
|
25 |
* along with this program; if not, write to the Free Software
|
26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
27 |
*
|
28 |
* For more information, contact:
|
29 |
*
|
30 |
* Generalitat Valenciana
|
31 |
* Conselleria d'Infraestructures i Transport
|
32 |
* Av. Blasco Ib??ez, 50
|
33 |
* 46010 VALENCIA
|
34 |
* SPAIN
|
35 |
*
|
36 |
* +34 963862235
|
37 |
* gvsig@gva.es
|
38 |
* www.gvsig.gva.es
|
39 |
*
|
40 |
* or
|
41 |
*
|
42 |
* IVER T.I. S.A
|
43 |
* Salamanca 50
|
44 |
* 46005 Valencia
|
45 |
* Spain
|
46 |
*
|
47 |
* +34 963163400
|
48 |
* dac@iver.es
|
49 |
*//* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
50 |
*
|
51 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
52 |
*
|
53 |
* This program is free software; you can redistribute it and/or
|
54 |
* modify it under the terms of the GNU General Public License
|
55 |
* as published by the Free Software Foundation; either version 2
|
56 |
* of the License, or (at your option) any later version.
|
57 |
*
|
58 |
* This program is distributed in the hope that it will be useful,
|
59 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
60 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
61 |
* GNU General Public License for more details.
|
62 |
*
|
63 |
* You should have received a copy of the GNU General Public License
|
64 |
* along with this program; if not, write to the Free Software
|
65 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
66 |
*
|
67 |
* For more information, contact:
|
68 |
*
|
69 |
* Generalitat Valenciana
|
70 |
* Conselleria d'Infraestructures i Transport
|
71 |
* Av. Blasco Ib??ez, 50
|
72 |
* 46010 VALENCIA
|
73 |
* SPAIN
|
74 |
*
|
75 |
* +34 963862235
|
76 |
* gvsig@gva.es
|
77 |
* www.gvsig.gva.es
|
78 |
*
|
79 |
* or
|
80 |
*
|
81 |
* IVER T.I. S.A
|
82 |
* Salamanca 50
|
83 |
* 46005 Valencia
|
84 |
* Spain
|
85 |
*
|
86 |
* +34 963163400
|
87 |
* dac@iver.es
|
88 |
*/
|
89 |
|
90 |
package es.gva.cit.jgdal; |
91 |
|
92 |
import java.util.StringTokenizer; |
93 |
|
94 |
/**
|
95 |
* Representa un driver de un tipo de im?gen
|
96 |
*
|
97 |
* @author Nacho Brodin <brodin_ign@gva.es>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
|
98 |
* @version 0.0
|
99 |
* @link http://www.gvsig.gva.es
|
100 |
*/
|
101 |
|
102 |
public class GdalDriver extends JNIBase{ |
103 |
|
104 |
private native long createCopyNat(long cPtr, String file, long src, int bstrict); |
105 |
private native long createCopyParamsNat(long cPtr, String file, long src, int bstrict, Options opc); |
106 |
private native long createNat(long cPtr, String filename, int nXSize, int nYSize, int nBands, int nType, Options opc); |
107 |
|
108 |
|
109 |
/**
|
110 |
* Constructor de Driver pasandole como par?metro la referencia al objeto
|
111 |
* GdalDriver en C
|
112 |
*
|
113 |
* @param cPtr direcci?n de memoria del objeto
|
114 |
*/
|
115 |
|
116 |
public GdalDriver(long cPtr){ |
117 |
this.cPtr=cPtr;
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* Crea una copia de una im?gen a partir de un dataset de origen especificado.
|
122 |
* @param file Nombre del fichero sobre el cual se guardar? la copia
|
123 |
* @param src Dataset fuente a copiar
|
124 |
* @param bstrict TRUE si la copia debe ser estrictamente equivalente y FALSE indica que la copia puede
|
125 |
* adaptarse a las necesidades del formato de salida
|
126 |
* @return Gdal Dataset de la im?gen de salida
|
127 |
* @throws GdalException
|
128 |
*/
|
129 |
|
130 |
public Gdal createCopy( String file, Gdal src, boolean bstrict )throws GdalException{ |
131 |
|
132 |
if(cPtr <= 0) |
133 |
throw new GdalException("Error en createCopy(). La llamada Open no tuvo exito"); |
134 |
|
135 |
long ptr;
|
136 |
if(bstrict)
|
137 |
ptr = createCopyNat(cPtr,file,src.getPtro(),1);
|
138 |
else
|
139 |
ptr = createCopyNat(cPtr,file,src.getPtro(),0);
|
140 |
|
141 |
if (ptr<0) |
142 |
throw new GdalException("Error en createCopy(). No se ha podido obtener el dataset."); |
143 |
else
|
144 |
return (new Gdal(ptr)); |
145 |
} |
146 |
|
147 |
|
148 |
/**
|
149 |
* A partir de las opciones en forma de vector de Strings pasadas por el usuario donde cada
|
150 |
* elemento del vector tiene la forma VARIABLE=VALOR crea el objeto Options para que sea accesible
|
151 |
* a las funciones JNI desde C.
|
152 |
* @param params Vector de strigs con las opciones
|
153 |
* @return Options Objeto de opciones
|
154 |
*/
|
155 |
|
156 |
private Options selectOptions(String[] params){ |
157 |
|
158 |
if(params==null)return null; |
159 |
|
160 |
Options opc=new Options(params.length);
|
161 |
StringTokenizer st;
|
162 |
for(int i=0;i<params.length;i++){ |
163 |
st = new StringTokenizer(params[i],"="); |
164 |
String var=st.nextToken();
|
165 |
String dato=st.nextToken();
|
166 |
opc.addOption(var,dato); |
167 |
} |
168 |
return opc;
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* Crea una copia de una im?gen a partir de un dataset de origen especificado y unos par?metros dados.
|
173 |
* @param file Nombre del fichero sobre el cual se guardar? la copia
|
174 |
* @param src Dataset fuente a copiar
|
175 |
* @param bstrict TRUE si la copia debe ser estrictamente equivalente y FALSE indica que la copia puede
|
176 |
* adaptarse a las necesidades del formato de salida
|
177 |
* @param params Vector de strigs con las opciones de la copia
|
178 |
* @return Gdal Dataset de la im?gen de salida
|
179 |
* @throws GdalException
|
180 |
*/
|
181 |
|
182 |
public Gdal createCopy( String file, Gdal src, boolean bstrict, String[] params )throws GdalException{ |
183 |
|
184 |
long papszOptions=-1; |
185 |
|
186 |
if(cPtr <= 0) |
187 |
throw new GdalException("Error en createCopy(). La llamada Open no tuvo exito"); |
188 |
|
189 |
long ptr;
|
190 |
if(bstrict)
|
191 |
ptr = createCopyParamsNat(cPtr, file, src.getPtro(), 1, selectOptions(params));
|
192 |
else
|
193 |
ptr = createCopyParamsNat(cPtr, file, src.getPtro(), 0, selectOptions(params));
|
194 |
|
195 |
if (ptr<0) |
196 |
throw new GdalException("Error en createCopy(). No se ha podido obtener el dataset."); |
197 |
else
|
198 |
return (new Gdal(ptr)); |
199 |
} |
200 |
|
201 |
|
202 |
/**
|
203 |
* Crea un nuevo dataset con el driver actual
|
204 |
*
|
205 |
* @param filename Nombre del dataset a crear
|
206 |
* @param nXSize Ancho en pixels
|
207 |
* @param nYSize Alto en pixels
|
208 |
* @param nBands N?mero de bandas
|
209 |
* @param nType Tipo de raster
|
210 |
* @param params lista de par?metros especificos del driver
|
211 |
*/
|
212 |
|
213 |
public Gdal create(String filename, int nXSize, int nYSize, int nBands, int nType, String[] params)throws GdalException{ |
214 |
|
215 |
long papszOptions=-1; |
216 |
|
217 |
if(cPtr <= 0) |
218 |
throw new GdalException("Error en create. La llamada Open no tuvo exito"); |
219 |
|
220 |
long ptr = createNat(cPtr, filename, nXSize, nYSize, nBands, nType, selectOptions(params));
|
221 |
|
222 |
if (ptr<0) |
223 |
throw new GdalException("Error en createCopy(). No se ha podido obtener el dataset."); |
224 |
else
|
225 |
return (new Gdal(ptr)); |
226 |
|
227 |
} |
228 |
|
229 |
|
230 |
} |