Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libjni-gdal-macosx / src / es / gva / cit / jbsb / Bsb.java @ 8219

History | View | Annotate | Download (4.86 KB)

1
/**********************************************************************
2
 * $Id: Bsb.java 8219 2006-10-23 06:25:39Z nacho $
3
 *
4
 * Name:     Bsb.java
5
 * Project:  JGDAL. Interface java to gdal (Frank Warmerdam).
6
 * Purpose:  Funcions to Open, Close and read data of bsb files. 
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
*/
50

    
51
package es.gva.cit.jbsb;
52

    
53
import java.io.*;
54
import java.util.Date;
55

    
56

    
57

    
58
/**
59
 * Ofrece las funcionalidades de la librería BSB de C a las
60
 * aplicaciones de java.
61
 * 
62
 * @author Nacho Brodin <brodin_ign@gva.es>
63
 */
64

    
65

    
66
public class Bsb {
67
        
68
        /**
69
         *Objeto que contiene la cabecera del fichero que ha sido cargada
70
         *desde la librer&iacute;a de C. 
71
         */
72
        
73
        public BsbInfo g_psInfo = null;
74
        
75
        /**
76
         *Objeto que contiene el buffer para una l&iacute;nea que sea le&iacute;da
77
         *desde el fichero bsb. 
78
         */
79
        
80
        public BsbBuffer g_buffer = null;
81
        
82
        /**
83
         *Variable que controla que BSBReadLine llame a BSBReadInfoLineNat (1) o a 
84
         *BSBReadLineNat (0). 
85
         * 
86
         */
87
        public long cPtr;
88
        
89
        
90
        /**
91
         * Nombre del fichero abierto
92
         */
93
        
94
        private String id;
95
        
96
                 
97
        //Definici?n de m?todos nativos 
98
        //********************************************************
99
        
100
        
101
        private native BsbInfo bsbOpenNat(String pszFilename);
102
        
103
        
104
        /**
105
         * Lee la l&iacute;nea del fichero bsb indicada por nScanline manteniendo la BSBInfo sin retornar
106
         * al cliente java. Esto hace que la llamada tenga un menor coste computacional pero que
107
         * no sea posible acceder a los datos modificados en cada llamada por la funci&oacute;n de libreria 
108
         * de C BSBReadScanLine.
109
         *         
110
         * @param buf        Buffer que contiene la l&iacute;nea le&iacute;da en cada llamada
111
         * @param nScanline        N&uacute;mero de l&iacute;nea procesada
112
         * 
113
         * @return 0 si hay error y 1 si la lectura de l&iacute;nea ha sido correcta
114
         */
115
        
116
        private native int bsbReadLineNat(         long cPtr,
117
                                                                                        BsbBuffer buf, 
118
                                                                                        int nScanline,
119
                                                                                        String pszFilename);
120
        
121
        
122
    private native void bsbCloseNat( long cPtr);
123

    
124
        
125
    //Recubrimiento de los m?todos nativos e interfaz exterior 
126
    //********************************************************    
127
    
128
    
129
    /**
130
     *Abre el fichero de im?gen 
131
     *
132
     *@param pszFilename        Nombre del fichero bsb
133
     */
134
    
135
    public void bsbOpen(String fil)throws BsbException,IOException{
136
            
137
            //Comprobaciones
138
            
139
            File f = new File( fil );
140
                if(!f.exists())
141
                  throw new IOException("El archivo "+fil+" no existe");
142
                  
143
            if(!f.canRead())
144
              throw new IOException("El archivo no puede leerse");
145
            
146
            //Abrimos el fichero y obtenemos la cabecera
147
            
148
            g_psInfo = bsbOpenNat(fil);
149
            if(g_psInfo.cPtr<=0)
150
                    throw new BsbException("Error en Open de BSB");
151
            
152
            //Creamos el buffer
153
            
154
            g_buffer = new BsbBuffer();
155
            g_buffer.reserva(g_psInfo.nXSize);
156
    }
157
    
158
    
159
    /**
160
     *Lee una l?nea del fichero de imagen
161
     *
162
     *@param sScanline -> N?mero de l?nea a procesar
163
     *@param flag        0: No devuelve la estructura BSBInfo
164
     *                                1: Devuelve a java la BSBInfo modificado 
165
     */
166
    
167
  
168
    public void bsbReadLine(int nScanline)throws BsbException{
169
            int res = 0;
170
            
171
            if(g_psInfo.cPtr <= 0)
172
                        throw new BsbException("Error en BSBReadLine(). La llamada BSBOpen no tuvo exito");
173
            
174
            res = bsbReadLineNat(g_psInfo.cPtr,g_buffer,nScanline,id);
175
  
176
            
177
            if(res == 0)throw new BsbException();
178
    
179
    }
180
    
181
    
182
    
183
    /**
184
     *Cierra el fichero de im?gen y elimina la cabecera 
185
     */
186
    
187
    public void bsbClose()throws BsbException{
188
            
189
            if(g_psInfo.cPtr <= 0)
190
                        throw new BsbException("Error en BSBClose(). La llamada BSBOpen no tuvo exito");
191
            
192
            bsbCloseNat(g_psInfo.cPtr);
193
    }
194
    
195
    
196
        static{
197
                
198
                System.loadLibrary("jgdal");
199
                
200
        } 
201
}
202

    
203