Statistics
| Revision:

root / branches / v10 / libraries / libjni-gdal / src / es / gva / cit / jgdal / GdalDriver.java @ 10988

History | View | Annotate | Download (6.22 KB)

1
/**********************************************************************
2
 * $Id: GdalDriver.java 10988 2007-03-30 11:54:34Z 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
                long ptr;
133
                if(bstrict)
134
                        ptr = createCopyNat(cPtr,file,src.getPtro(),1);
135
                else
136
                        ptr = createCopyNat(cPtr,file,src.getPtro(),0);
137
        
138
                return (new Gdal(ptr));
139
        }
140
        
141
        
142
        /**
143
         * A partir de las opciones en forma de vector de Strings pasadas por el usuario donde cada
144
         * elemento del vector tiene la forma VARIABLE=VALOR crea el objeto Options para que sea accesible
145
         * a las funciones JNI desde C.
146
         * @param params        Vector de strigs con las opciones
147
         * @return Options        Objeto de opciones
148
         */
149
        
150
        private Options selectOptions(String[] params){
151
                
152
                if(params==null)return null;
153
                
154
                Options opc=new Options(params.length);
155
                StringTokenizer st;
156
                for(int i=0;i<params.length;i++){
157
                        st = new StringTokenizer(params[i],"=");
158
                    String var=st.nextToken();
159
                    String dato=st.nextToken();
160
                    opc.addOption(var,dato);                            
161
                }
162
                return opc;
163
        }
164
        
165
        /**
166
         * Crea una copia de una im?gen a partir de un dataset de origen especificado y unos par?metros dados.
167
         * @param file        Nombre del fichero sobre el cual se guardar? la copia
168
         * @param src        Dataset fuente a copiar
169
         * @param bstrict        TRUE si la copia debe ser estrictamente equivalente y FALSE indica que la copia puede
170
         * adaptarse a las necesidades del formato de salida
171
         * @param params        Vector de strigs con las opciones de la copia
172
         * @return Gdal        Dataset de la im?gen de salida
173
         * @throws GdalException
174
         */
175
        
176
        public Gdal createCopy( String file, Gdal src, boolean bstrict, String[] params )throws GdalException{
177
                
178
                long papszOptions=-1;
179
                
180
                long ptr;
181
                if(bstrict)
182
                        ptr = createCopyParamsNat(cPtr, file, src.getPtro(), 1, selectOptions(params));
183
                else
184
                        ptr = createCopyParamsNat(cPtr, file, src.getPtro(), 0, selectOptions(params));
185
        
186
                return (new Gdal(ptr));
187
        }
188
        
189
        
190
        /**
191
         * Crea un nuevo dataset con el driver actual
192
         * 
193
         * @param filename        Nombre del dataset a crear
194
         * @param nXSize        Ancho en pixels
195
         * @param nYSize        Alto en pixels
196
         * @param nBands        N?mero de bandas
197
         * @param nType        Tipo de raster
198
         * @param params        lista de par?metros especificos del driver
199
         */
200
        
201
        public Gdal create(String filename, int nXSize, int nYSize, int nBands, int nType, String[] params)throws GdalException{
202
                
203
                long papszOptions=-1;
204
                        
205
                long ptr = createNat(cPtr, filename, nXSize, nYSize, nBands, nType, selectOptions(params));
206
        
207
                return (new Gdal(ptr));
208
                
209
        }
210
        
211
        
212
}