Revision 1904

View differences:

org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.gvsig.jgdal</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
	</buildSpec>
9
	<natures>
10
	</natures>
11
</projectDescription>
0 12

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/test/java/TestReadBand.java
1

  
2
import java.io.IOException;
3
import org.gvsig.jgdal.*;
4

  
5
/**
6
 * Test de acceso a datos de las bandas de una imagen.
7
 * javac -classpath ./:/.../org.gvsig.jgdal/target/org.gvsig.jgdal-2.0.3-SNAPSHOT.jar TestReadBand.java
8
 * 
9
 * java -classpath ./:/.../org.gvsig.jgdal/target/org.gvsig.jgdal-2.0.3-SNAPSHOT.jar -Djava.library.path=/... TestReadBand
10
 * @author Nacho Brodin <nachobrodin@gmail.com>
11
 *
12
 */
13
public class TestReadBand {
14
	private Gdal gdal = null;
15
	private GdalRasterBand band = null;
16
	private String baseDir = "../../../test-images/";
17
	private String file1 = baseDir + "testGdal.tif";
18
	
19

  
20
	public static void main(String[] args) {
21
		TestReadBand t = new TestReadBand();
22
		try {
23
		t.testStack();	
24
		} catch(Exception e) {
25
		}
26
	}
27
	public void testStack() throws GdalException, IOException {
28

  
29
		gdal = new Gdal();
30
		gdal.open(file1, Gdal.GA_Update);
31
		//Llamada sin dominio
32
		String[] metadata = gdal.getMetadata();
33

  
34
		for (int i = 0 ; i < metadata.length; i++) { 
35
			System.out.println("Metadato: " + metadata[i]);
36
		}
37
		
38
		//Llamada con dominio "Image Structure Metadata"
39
		metadata = gdal.getMetadata("Image Structure Metadata");
40
		for (int i = 0 ; i < metadata.length; i++) {
41
			System.out.println("Metadato: " + metadata[i]);
42
		}
43
		
44
		//Comprobaci?n del tama?o de la imagen
45
		System.out.println(gdal.getRasterXSize());
46
		System.out.println(gdal.getRasterYSize());
47
		
48
		//Comprobaci?n del n?mero de bandas
49
		System.out.println("Bands: " + gdal.getRasterCount());
50
		
51
		//Comprobaci?n del driver de la imagen
52
		System.out.println("Driver: " + gdal.getDriverShortName());
53
		
54
		//Comprobaci?n del acceso a las bandas
55
		for (int i = 0 ; i < gdal.getRasterCount() ; i++) {
56
			GdalRasterBand b = gdal.getRasterBand(i+1);
57
			System.out.println("Band:" + i + "  X:" + b.getRasterBandXSize());
58
			System.out.println("Band:" + i + "  Y:" + b.getRasterBandYSize());
59
			System.out.println("Overviews Band:" + i + " " + b.getOverviewCount());
60
			for (int j = 0 ; j < b.getOverviewCount() ; j++) {
61
				GdalRasterBand ov = b.getOverview(j);
62
				System.out.println("    " + ov.getRasterBandXSize() + " x " + ov.getRasterBandYSize());
63
			}
64
		}
65
	}
66
}
0 67

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/test/java/org/gvsig/addo/TestBuildOverviews.java
1
package org.gvsig.addo;
2

  
3
import java.io.IOException;
4

  
5
import junit.framework.TestCase;
6
import org.gvsig.jgdal.Gdal;
7
import org.gvsig.jgdal.GdalException;
8

  
9
/**
10
 * Test para la generacion de overviews sobre una imagen raster.
11
 * Registra un listener para mostrar el incremento de la tarea.
12
 *
13
 * 18-nov-2007
14
 * @author Nacho Brodin (nachobrodin@gmail.com)
15
 */
16
public class TestBuildOverviews extends TestCase implements IOverviewIncrement {
17
	private int value = 0;
18

  
19
	private Jaddo addo = null;
20
	private Gdal gdal = null;
21
	private String path = "./test-images/testGdalWarp.tif";
22
	
23
	public void start(){
24
		setUp();
25
		testStack();
26
	}
27
	
28
	
29
	public void setUp(){
30
		addo = new Jaddo();
31
		addo.setIncrementListener(this);
32
		gdal = new Gdal();
33
	}
34
	
35
	
36
	public void testStack(){
37
		try {
38
			addo.buildOverviews(Jaddo.AVERAGE, path, new int[]{2, 4, 8, 16});
39
			gdal.open(path, Gdal.GA_ReadOnly);
40
			assertTrue("No hay overviews!!", gdal.getRasterBand(1).getOverviewCount()>0);
41
		} catch (BuildingOverviewsException e) {
42
			System.err.println(e);
43
		} catch (WritingException e) {
44
			System.err.println(e);
45
		} catch (GdalException e) {
46
			e.printStackTrace();
47
		} catch (IOException e) {
48
			e.printStackTrace();
49
		}
50
		
51
	}
52

  
53
	public int getPercent() {
54
		return value;
55
	}
56

  
57
	public void setPercent(int value) {
58
		this.value = value;
59
		System.out.println("Increment:" + value);
60
	}
61
}
0 62

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/main/java/org/gvsig/jgdal/GdalColorTable.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.jgdal;
23

  
24
public class GdalColorTable extends JNIBase {
25
	
26
	private native int getColorEntryCountNat(long cPtr);
27
	private native short[] getColorEntryAsRGBNat(long cPtr, int pos);
28
	
29
	
30
	/**
31
	 * Constructor de ColorTable pasandole como par?metro la referencia al objeto 
32
	 * GdalColorTable en C
33
	 * 
34
	 * @param cPtr	direcci?n de memoria del objeto 
35
	 */
36
	
37
	public GdalColorTable(long cPtr){
38
		this.cPtr=cPtr;
39
	}
40
	
41
	/**
42
	 * Obtiene
43
	 * @return
44
	 * @throws GdalException
45
	 */
46
	public int getColorEntryCount() throws GdalException{
47
		if (cPtr == 0)
48
	    	throw new GdalException("No se ha podido acceder al archivo.");
49
		return getColorEntryCountNat(cPtr);
50
	}
51
	
52
	/**
53
	 * Obtiene la entrada de la tabla de color de la posici?n pasada por par?metro
54
	 * y la devuelve en forma de objeto GdalColorEntry.
55
	 * @param pos Posici?n de la entrada de la tabla
56
	 * @return Objeto GdalColorEntry correspondiente a pos
57
	 * @throws GdalException
58
	 */
59
	public GdalColorEntry getColorEntryAsRGB(int pos) throws GdalException{
60
		if (cPtr == 0)
61
	    	throw new GdalException("No se ha podido acceder al archivo.");
62
		
63
		if ((pos < 0) || (pos >= getColorEntryCount()))
64
			throw new GdalException("Entrada de la tabla de color fuera de rango");
65
		
66
		GdalColorEntry entry = new GdalColorEntry();
67
		short[] values =  getColorEntryAsRGBNat(cPtr, pos);
68
		entry.c1 = values[0];
69
		entry.c2 = values[1];
70
		entry.c3 = values[2];
71
		entry.c4 = values[3];
72
		if(values == null)
73
			throw new GdalException("Error en getColorEntryAsRGB(). Posici?n de la tabla de color inexistente.");
74
		return entry;
75
	}
76
}
0 77

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/main/java/org/gvsig/jgdal/GdalBuffer.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
package org.gvsig.jgdal;
24

  
25

  
26
/**  
27
 * Buffer para el almacenamiento de l?neas de la im?g?n. Esta clase es instanciada desde C para que se pueda acceder a sus datos desde el cliente java.
28
 * 
29
 * @author Nacho Brodin (nachobrodin@gmail.com).<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
30
 * @version 0.0
31
 * @link http://www.gvsig.gva.es
32
 */
33

  
34
public class GdalBuffer{
35
	
36
    public byte[] buffByte;			//8 bits
37
    public short[] buffShort;		//16 bits
38
    public int[] buffInt;			//32 bits
39
    public float[] buffFloat;		//32 bits
40
    public double[] buffDouble;		//64 bits
41
    
42
    public byte[] buffAPalette;
43
    public byte[] buffRPalette;
44
    public byte[] buffGPalette;
45
    public byte[] buffBPalette;
46
    
47
    public void reservaByte(int r){
48
    	//buffByte = new byte[r];
49
    }
50
    
51
    public void reservaShort(int r){
52
    	//buffShort = new short[r];
53
    }
54
    
55
    public void reservaInt(int r){
56
    	//buffInt = new int[r];
57
    }
58
    
59
    public void reservaFloat(int r){
60
    	//buffFloat = new float[r];
61
    }
62
    
63
    public void reservaDouble(int r){
64
    	//buffDouble = new double[r];
65
    }
66
    
67
    public void reservaPalette(int r){
68
    	/*buffAPalette = new byte[r];
69
    	buffRPalette = new byte[r];
70
        buffGPalette = new byte[r];
71
        buffBPalette = new byte[r];*/
72
    }
73
    
74
    public int getSize(){
75
      for(int i=0;i<5;i++){
76
      	if(buffByte!=null)return buffByte.length;
77
    	if(buffShort!=null)return buffShort.length;
78
    	if(buffInt!=null)return buffInt.length;
79
    	if(buffFloat!=null)return buffFloat.length;
80
    	if(buffDouble!=null)return buffDouble.length;
81
    	if(buffRPalette!=null)return buffRPalette.length;
82
      }
83
      return 0;
84
    }
85
  
86
}
0 87

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/main/java/org/gvsig/jgdal/GdalGCP.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.jgdal;
23
/**
24
 * Contiene las funcionalidades necesarias para el acceso a los
25
 * elementos de un dataset de gdal correspondiente a una im?gen 
26
 * 
27
 * @author Nacho Brodin (nachobrodin@gmail.com).<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
28
 * @link http://www.gvsig.gva.es
29
 */
30
public class GdalGCP extends JNIBase{
31

  
32
	private native long GdalGCPNat();
33
	private native long GdalGCPPointsNat(	double pixelXGCP, 
34
											double pixelYGCP,
35
											double mapXGCP,
36
											double mapYGCP,
37
											double mapZGCP);
38
	private native void FreeGdalGCPNat();
39
	
40
	private String id; 			//identificador 
41
	private String info;		//informaci?n
42
	private double pixelXGCP;	/** Pixel (x) location of GCP on raster */
43
	private double pixelYGCP;	/** Line (y) location of GCP on raster */
44
	private double mapXGCP;		/** X position of GCP in georeferenced space */
45
	private double mapYGCP; 	/** Y position of GCP in georeferenced space */
46
	private double mapZGCP;		/** Elevation of GCP, or zero if not known */
47
		
48
	/**
49
	 * Constructor
50
	 */
51
	public GdalGCP(){
52
		cPtr = this.GdalGCPNat();
53
	}
54
	
55
	/**
56
	 * Constructor
57
	 * @param pixelXGCP
58
	 * @param pixelYGCP
59
	 * @param mapXGCP
60
	 * @param mapYGCP
61
	 * @param mapZGCP
62
	 */
63
	public GdalGCP(	double pixelXGCP, 
64
					double pixelYGCP,
65
					double mapXGCP,
66
					double mapYGCP,
67
					double mapZGCP){
68
		this.pixelXGCP = pixelXGCP;  
69
		this.pixelYGCP = pixelYGCP;
70
		this.mapXGCP = mapXGCP; 
71
		this.mapYGCP = mapYGCP;
72
		this.mapZGCP = mapYGCP;
73
	}
74
	
75
	protected void finalize(){
76
		
77
	}
78
	
79
	/**
80
	 * @return Returns the mapXGCP.
81
	 */
82
	public double getMapXGCP() {
83
		return mapXGCP;
84
	}
85
	/**
86
	 * @param mapXGCP The mapXGCP to set.
87
	 */
88
	public void setMapXGCP(double mapXGCP) {
89
		this.mapXGCP = mapXGCP;
90
	}
91
	/**
92
	 * @return Returns the mapYGCP.
93
	 */
94
	public double getMapYGCP() {
95
		return mapYGCP;
96
	}
97
	/**
98
	 * @param mapYGCP The mapYGCP to set.
99
	 */
100
	public void setMapYGCP(double mapYGCP) {
101
		this.mapYGCP = mapYGCP;
102
	}
103
	/**
104
	 * @return Returns the mapZGCP.
105
	 */
106
	public double getMapZGCP() {
107
		return mapZGCP;
108
	}
109
	/**
110
	 * @param mapZGCP The mapZGCP to set.
111
	 */
112
	public void setMapZGCP(double mapZGCP) {
113
		this.mapZGCP = mapZGCP;
114
	}
115
	/**
116
	 * @return Returns the pixelXGCP.
117
	 */
118
	public double getPixelXGCP() {
119
		return pixelXGCP;
120
	}
121
	/**
122
	 * @param pixelXGCP The pixelXGCP to set.
123
	 */
124
	public void setPixelXGCP(double pixelXGCP) {
125
		this.pixelXGCP = pixelXGCP;
126
	}
127
	/**
128
	 * @return Returns the pixelYGCP.
129
	 */
130
	public double getPixelYGCP() {
131
		return pixelYGCP;
132
	}
133
	/**
134
	 * @param pixelYGCP The pixelYGCP to set.
135
	 */
136
	public void setPixelYGCP(double pixelYGCP) {
137
		this.pixelYGCP = pixelYGCP;
138
	}
139
}
0 140

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/main/java/org/gvsig/jgdal/GdalWarp.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.jgdal;
23

  
24
import java.util.ArrayList;
25

  
26
/**
27
 * Clase que recubre la funci?n de reproyecci?n de gdal.
28
 *  
29
 * @author Miguel ?ngel Querol Carratal?
30
 */
31
public class GdalWarp extends JNIBase {
32
	private int    porcentaje;
33

  
34
	/**
35
	 * Par?metros de la operaci?n de reproyecci?n
36
	 */
37
	private String s_srs = null;
38

  
39
	/**
40
	 * M?todo nativo para el warp desde gdal.
41
	 */
42
	private native int warpDataset(String s_srs, String t_srs, String source, String dest, String format);
43

  
44
	/**
45
	 * Constructor generico.
46
	 */
47
	public GdalWarp() {}
48

  
49
	/**
50
	 * Reproyecta una imagen raster, creando una imagen de salida
51
	 * @param proj EPSG:code o proj4
52
	 * @param source Ruta del fichero fuente
53
	 * @param dest Ruta del fichero destino
54
	 * @param format
55
	 * @return 0 si ha ocurrido algun error o 1 si la ejecuci?n ha sido correcta.
56
	 * @throws GdalException
57
	 */
58
	public int warp(String t_srs, String source, String dest, String format) {
59

  
60
		int stat = warpDataset(s_srs, t_srs, source, dest, format);
61
		
62
		return stat;
63
	}
64

  
65
	/**
66
	 * Indica la proyecci?n del dataset origen
67
	 * @param s_srs
68
	 */
69
	public void setSsrs(String s_srs) {
70
		this.s_srs = s_srs;
71
	}
72

  
73
	/**
74
	 * Obtiene el porcentaje de proceso que se ha completado
75
	 */
76
	public int getPercent() {
77
		return porcentaje;
78
	}
79
	
80
	/**
81
	 * Devuelve la lista de drivers que usa GdalWarp para reproyectar
82
	 * @return
83
	 */
84
	static public ArrayList getDrivers() {
85
		ArrayList list = new ArrayList();
86
		list.add("GTiff");
87
		list.add("VRT");
88
		list.add("NITF");
89
		list.add("HFA");
90
		list.add("ELAS");
91
		list.add("MEM");
92
		list.add("BMP");
93
		list.add("PCIDSK");
94
		list.add("ILWIS");
95
		String os = System.getProperty("os.name");
96
		if (!os.toLowerCase().startsWith("windows"))
97
			list.add("HDF4Image");
98
		list.add("PNM");
99
		list.add("ENVI");
100
		list.add("EHdr");
101
		list.add("PAux");
102
		list.add("MFF");
103
		list.add("MFF2");
104
		list.add("BT");
105
		list.add("IDA");
106
		list.add("RMF");
107
		list.add("RST");
108
		list.add("Leveller");
109
		list.add("Terragen");
110
		list.add("ERS");
111
		list.add("INGR");
112
		list.add("GSAG");
113
		list.add("GSBG");
114
		list.add("ADRG");
115
		return list;
116
	}
117
}
0 118

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/main/java/org/gvsig/jgdal/GdalDriver.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.jgdal;
23

  
24
import java.io.File;
25
import java.util.StringTokenizer;
26
/**
27
 * Representa un driver de un tipo de im?gen 
28
 * 
29
 * @author Nacho Brodin (nachobrodin@gmail.com).<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
30
 * @version 0.0
31
 * @link http://www.gvsig.gva.es
32
 */
33
public class GdalDriver extends JNIBase {
34
	private native long createCopyNat(long cPtr, String file, long src, int bstrict);
35
	private native long createCopyParamsNat(long cPtr, String file, long src, int bstrict, Options opc);
36
	private native long createNat(long cPtr, String filename, int nXSize, int nYSize, int nBands, int nType, Options opc);
37
	
38
	/**
39
	 * Constructor de Driver pasandole como par?metro la referencia al objeto 
40
	 * GdalDriver en C
41
	 * 
42
	 * @param cPtr	direcci?n de memoria del objeto 
43
	 */
44
	public GdalDriver(long cPtr) {
45
		this.cPtr=cPtr;
46
	}
47

  
48
	/**
49
	 * Crea una copia de una im?gen a partir de un dataset de origen especificado.
50
	 * @param file	Nombre del fichero sobre el cual se guardar? la copia
51
	 * @param src	Dataset fuente a copiar
52
	 * @param bstrict	TRUE si la copia debe ser estrictamente equivalente y FALSE indica que la copia puede
53
	 * adaptarse a las necesidades del formato de salida
54
	 * @return Gdal	Dataset de la im?gen de salida
55
	 * @throws GdalException
56
	 */
57
	public Gdal createCopy(String file, Gdal src, boolean bstrict) throws GdalException {
58
		String path = file.substring(0, file.lastIndexOf(File.separator));
59
		File f = new File(path);
60
		if (!f.canWrite())
61
			throw new GdalException("Ruta de archivo incorrecta.");
62
		f = null;
63

  
64
		if (src == null)
65
			throw new GdalException("El objeto Gdal es null");
66

  
67
		if (cPtr == 0)
68
			throw new GdalException("No se ha podido acceder al archivo.");
69

  
70
		long ptr = createCopyNat(cPtr, file, src.getPtro(), bstrict ? 1 : 0);
71
	
72
//		if (ptr == 0)
73
//			throw new GdalException("No se ha podido crear la copia");
74

  
75
		return (new Gdal(ptr));
76
	}
77
	
78
	
79
	/**
80
	 * A partir de las opciones en forma de vector de Strings pasadas por el usuario donde cada
81
	 * elemento del vector tiene la forma VARIABLE=VALOR crea el objeto Options para que sea accesible
82
	 * a las funciones JNI desde C.
83
	 * @param params	Vector de strigs con las opciones
84
	 * @return Options	Objeto de opciones
85
	 */
86
	private Options selectOptions(String[] params) {
87
		if (params == null)
88
			return null;
89

  
90
		Options opc = new Options(params.length);
91
		StringTokenizer st;
92
		for (int i = 0; i < params.length; i++) {
93
			st = new StringTokenizer(params[i], "=");
94
			String var = st.nextToken();
95
			String dato = st.nextToken();
96
			opc.addOption(var, dato);
97
		}
98
		return opc;
99
	}
100
	
101
	/**
102
	 * Crea una copia de una im?gen a partir de un dataset de origen especificado y unos par?metros dados.
103
	 * @param file	Nombre del fichero sobre el cual se guardar? la copia
104
	 * @param src	Dataset fuente a copiar
105
	 * @param bstrict	TRUE si la copia debe ser estrictamente equivalente y FALSE indica que la copia puede
106
	 * adaptarse a las necesidades del formato de salida
107
	 * @param params	Vector de strigs con las opciones de la copia
108
	 * @return Gdal	Dataset de la im?gen de salida
109
	 * @throws GdalException
110
	 */
111
	public Gdal createCopy(String file, Gdal src, boolean bstrict, String[] params) throws GdalException {
112
		String path = file.substring(0, file.lastIndexOf(File.separator));
113
		File f = new File(path);
114
		if (!f.canWrite())
115
			throw new GdalException("Ruta de archivo incorrecta.");
116
		f = null;
117

  
118
		if (cPtr == 0)
119
			throw new GdalException("No se ha podido acceder al archivo.");
120

  
121
		if (src == null)
122
			throw new GdalException("El objeto Gdal es null");
123

  
124
		long ptr = createCopyParamsNat(cPtr, file, src.getPtro(), bstrict ? 1 : 0, selectOptions(params));
125

  
126
		if (ptr == 0)
127
			throw new GdalException("No se ha podido crear la copia");
128

  
129
		return (new Gdal(ptr));
130
	}
131
	
132
	
133
	/**
134
	 * Crea un nuevo dataset con el driver actual
135
	 * 
136
	 * @param filename	Nombre del dataset a crear
137
	 * @param nXSize	Ancho en pixels
138
	 * @param nYSize	Alto en pixels
139
	 * @param nBands	N?mero de bandas
140
	 * @param nType	Tipo de raster
141
	 * @param params	lista de par?metros especificos del driver
142
	 */
143
	public Gdal create(String filename, int nXSize, int nYSize, int nBands, int nType, String[] params) throws GdalException {
144
		if (cPtr == 0)
145
			throw new GdalException("No se ha podido acceder al archivo.");
146

  
147
		long ptr = createNat(cPtr, filename, nXSize, nYSize, nBands, nType, selectOptions(params));
148

  
149
		return (new Gdal(ptr));
150
	}
151
}
0 152

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/main/java/org/gvsig/jgdal/GdalException.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
 
23
package org.gvsig.jgdal;
24

  
25
/**
26
 * Es generada cuando los c?digos de retorno de las funciones de Gdal significan que algo ha ido mal.
27
 * 
28
 * @author Nacho Brodin (nachobrodin@gmail.com).<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
29
 * @version 0.0
30
 * @link http://www.gvsig.gva.es
31
 */
32

  
33

  
34
public class GdalException extends Exception{
35

  
36
	public GdalException(String msg){
37
		super(msg);
38
	}
39
	
40
	
41
}
0 42

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/main/java/org/gvsig/jgdal/GeoTransform.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.jgdal;
23

  
24

  
25
/**
26
 * Buffer para el almacenamiento de los datos de georeferenciaci?n.
27
 * 
28
 * @author Nacho Brodin (nachobrodin@gmail.com).<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
29
 * @version 0.0
30
 * @see http://www.gvsig.gva.es
31
 * @link http://www.gvsig.gva.es
32
 */
33

  
34
public class GeoTransform{
35
	
36
   public double adfgeotransform[]=new double[6];   
37
   
38
}
0 39

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/main/java/org/gvsig/jgdal/Gdal.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.jgdal;
23

  
24
import java.io.File;
25
import java.io.IOException;
26
/**
27
 * Contiene las funcionalidades necesarias para el acceso a los elementos de un
28
 * dataset de gdal correspondiente a una imagen
29
 * 
30
 * @author Nacho Brodin (nachobrodin@gmail.com)
31
 */
32
public class Gdal extends JNIBase {
33
	// CONSTANTES
34

  
35
	// GDALAccess
36
	public static int GA_ReadOnly   = 0;
37
	public static int GA_Update     = 1;
38

  
39
	// GDALDataType
40
	public static int GDT_Unknown   = 0;
41
	public static int GDT_Byte      = 1; // Buffer byte (8)
42
	public static int GDT_UInt16    = 2; // Buffer short (16)
43
	public static int GDT_Int16     = 3; // Buffer short (16)
44
	public static int GDT_UInt32    = 4; // Buffer int (32)
45
	public static int GDT_Int32     = 5; // Buffer int (32)
46
	public static int GDT_Float32   = 6; // Buffer float (32)
47
	public static int GDT_Float64   = 7; // Buffer double (64)
48
	public static int GDT_CInt16    = 8; // Buffer short (16)
49
	public static int GDT_CInt32    = 9; // Buffer int (32)
50
	public static int GDT_CFloat32  = 10; // Buffer float (32)
51
	public static int GDT_CFloat64  = 11; // Buffer double (64)
52
	public static int GDT_TypeCount = 12;
53

  
54
	private String    pszFilename   = "";
55

  
56
	private native long openNat(String pszFilename, int access);
57
	private native long openArrayNat(byte[] pszFilename, int access);
58
	private native int getGeoTransformNat(long cPtr, GeoTransform adfgeotransform);
59
	private native int setGeoTransformNat(long cPtr, GeoTransform adfgeotransform);
60
	private native String[] getMetadataNat(long cPtr, String pszDomain);
61
	private native String getProjectionRefNat(long cPtr);
62
	private native void closeNat(long cPtr);
63
	private native long getRasterBandNat(long cPtr, int hBand);
64
	private native int setProjectionNat(long cPtr, String proj);
65
	private native String getDriverShortNameNat(long cPtr);
66
	
67
	//private static native long getGDALDriverManagerNat(); 
68
	private static native long getDriverByNameNat(String name);
69
	private native String getColorInterpretationNameNat(long cPtr, int colorInterp);
70
	
71
	/**
72
	 *Constructor a partir de la direcci?n de memoria 
73
	 */
74
	public Gdal(long cPtr){
75
		this.cPtr=cPtr;
76
	}
77
	
78
	/**
79
	 *Constructor generico
80
	 */
81
	public Gdal(){}
82
	
83
	/**
84
	 * Devuelve la direcci?n de memoria del objeto dataset en C.
85
	 */
86
	public long getPtro(){return cPtr;}
87
	
88
	/**
89
	 * Abre el fichero de imagen.
90
	 *
91
	 * @param pszFilename	Nombre del fichero.
92
	 * @param access	Apertura en solo lectura o escritura.
93
	 * @throws GdalException
94
	 */
95
	public void open(String pszFilename, int access)throws GdalException, IOException {
96
		if ((access < 0) || (access > 1))
97
			throw new GdalException("Tipo de acceso al dataset incorrecto");
98

  
99
		cPtr = openArrayNat(pszFilename.getBytes(), access);
100

  
101
		if (cPtr == 0)
102
			throw new GdalException("No se ha podido acceder al archivo.");
103
	}
104
	
105
	/**
106
	 * Obtiene un array de Strings con los metadatos
107
	 * 
108
	 * @throws GdalException
109
	 * @return Array de Strings que corresponden a los metadatos que ofrece la imagen
110
	 */
111
	public String[] getMetadata()throws GdalException {
112
		return getMetadata(null);
113
		
114
	}
115
	
116
	
117
	/**
118
	 * Obtiene un array de Strings con los metadatos
119
	 * 
120
	 * @throws GdalException
121
	 * @return Array de Strings que corresponden a los metadatos que ofrece la imagen
122
	 */
123
	public String[] getMetadata(String domain)throws GdalException {
124
		String[] res = getMetadataNat(cPtr, domain);
125
		if(res == null)
126
			return new String[0];
127
		else return res;
128
		
129
	}
130
	
131
	/**
132
	 * Obtiene el n?mero de bandas de la imagen
133
	 * 
134
	 * @throws GdalException
135
	 * @param hBand	Entero que corresponde al n?mero de banda que se quiere recuperar
136
	 * @return Objeto GdalRasterBand que representa la banda recuperada	
137
	 */
138
	
139
	public GdalRasterBand getRasterBand(int hBand)throws GdalException {
140
		long cPtr_rb;
141
			
142
		if ((hBand < 1) || (hBand > getRasterCount()))
143
			throw new GdalException("Banda seleccionada incorrecta");
144
		
145
		if (cPtr == 0)
146
				throw new GdalException("No se ha podido acceder al archivo.");
147
		
148
		cPtr_rb = getRasterBandNat(cPtr,hBand);
149
		
150
		return new GdalRasterBand(cPtr_rb);	
151
	}
152
	
153
		
154
	
155
	/**
156
	 * Obtiene la dimensi?n del raster en el eje X.
157
	 * 
158
	 * @return	Devuelve un entero con la longitud de la imagen en el eje X en pixels.
159
	 * @throws GdalException 
160
	 */
161
	public int getRasterXSize()throws GdalException {
162
		String msg1="Error en GDALGetRasterXSize. La llamada GDALOpen no tuvo ?xito";
163
		String msg2="Error en tama?o X";
164
		return baseSimpleFunctions(5,msg1,msg2);
165
	}
166
		
167
	
168
	/**
169
	 * Obtiene la dimensi?n del raster en el eje Y.
170
	 * 
171
	 * @return	Devuelve un entero con la longitud de la imagen en el eje Y en pixels.
172
	 * @throws GdalException 
173
	 */
174
	public int getRasterYSize()throws GdalException {
175
		String msg1="Error en GDALGetRasterYSize. La llamada GDALOpen no tuvo ?xito";
176
		String msg2="Error en tama?o Y";
177
		return baseSimpleFunctions(6,msg1,msg2);
178
	}
179
	
180
	
181
	/**
182
	 * Obtiene el n?mero de bandas de la imagen
183
	 * 
184
	 * @return	Devuelve un entero con el n?mero de bandas que contiene la imagen.
185
	 * @throws GdalException
186
	 */
187
	public int getRasterCount()throws GdalException {
188
		String msg1="Error en GDALGetRasterCount. . La llamada GDALOpen no tuvo ?xito";
189
		String msg2="Error en el conteo de n?mero de bandas";
190
		return baseSimpleFunctions(7,msg1,msg2);
191
	}
192
	
193
	
194
	/**
195
	 * Obtiene el vector geoTransform de la imagen que contiene los valores Origen y pixelSize
196
	 * 
197
	 * @return	Devuelve un vector de doubles que contiene los valores de coordenadas de origen y pixelSize.
198
	 * @throws GdalException
199
	 */
200
	public GeoTransform getGeoTransform()throws GdalException {
201
		GeoTransform gt=new GeoTransform();
202
				
203
		if (cPtr == 0)
204
				throw new GdalException("No se ha podido acceder al archivo.");
205
		
206
		if(getGeoTransformNat(cPtr,gt) < 0)
207
			throw new GdalException("Error en getGeoTransform(). No se han obtenido valores para geoTransform.");
208
		else{
209
			return gt;
210
		}
211
	}
212
	
213
	/**
214
	 * Obtiene el Nombre corto asociado al driver del dataset
215
	 * 
216
	 * @return	Cadena con el nombre del driver
217
	 * @throws GdalException
218
	 */
219
	public String getDriverShortName()throws GdalException {
220
		if (cPtr == 0)
221
				throw new GdalException("No se ha podido acceder al archivo.");
222
		
223
		String shortName = getDriverShortNameNat(cPtr);
224
		
225
		if(shortName == null)
226
			throw new GdalException("Error en getDriverShortName(). No ha podido obtenerse el driver");
227
		else 
228
			return shortName;
229
	}
230
	
231
	/**
232
	 * A?ade el vector geoTransform a la imagen que contiene los valores Origen y pixelSize
233
	 * 
234
	 * @return	Devuelve un vector de doubles que contiene los valores de coordenadas de origen y pixelSize.
235
	 * @throws GdalException
236
	 */
237
	public void setGeoTransform(GeoTransform gt)throws GdalException {
238
		if (cPtr == 0)
239
				throw new GdalException("No se ha podido acceder al archivo.");
240
		if (gt == null)
241
			throw new GdalException("el objeto " + gt.getClass().getName() + " es null");
242
		
243
		int res = setGeoTransformNat(cPtr,gt);
244
	}
245
	
246
	/**
247
	 * Obtiene el sistema de coordenadas de referencia de la imagen.
248
	 * 
249
	 * @return	Devuelve un String con los datos del sistema de coordenadas de referencia.
250
	 * @throws GdalException
251
	 */
252
	public String getProjectionRef()throws GdalException {
253
		if (cPtr == 0)
254
				throw new GdalException("No se ha podido acceder al archivo.");
255
		
256
		String res = getProjectionRefNat(cPtr);
257
		
258
		if(res == null)return new String("");
259
		else return res;
260
	}
261
	
262
	/**
263
	 * Cierra el fichero de imagen.
264
	 *
265
	 * @throws GdalException 
266
	 */
267
	public void close()throws GdalException {
268
		if (cPtr == 0)
269
				throw new GdalException("No se ha podido acceder al archivo.");
270
		
271
		closeNat(cPtr);	
272
	}
273
	
274
	/**
275
	 * Obtiene un driver a trav?s de su nombre
276
	 * 
277
	 * @param name	Nombre del driver
278
	 */
279
	public static GdalDriver getDriverByName(String name)throws GdalException {
280
		long ptrdrv = -1;
281
		
282
		if (name == null)
283
			throw new GdalException("El nombre del driver es null");
284
		
285
		ptrdrv = getDriverByNameNat(name);
286
		
287
		return (new GdalDriver(ptrdrv));
288
	}
289
	
290
	
291
	/**
292
	 * Obtiene el numero de bandas de la imagen
293
	 * 
294
	 * @return	Devuelve un entero con el numero de bandas que contiene la imagen.
295
	 * @throws GdalException
296
	 */
297
	public int getGCPCount()throws GdalException {
298
		String msg1="Error en GDALGetRasterCount. . La llamada GDALOpen no tuvo ?xito";
299
		String msg2="Error en el conteo de n?mero de bandas";
300
		return baseSimpleFunctions(8,msg1,msg2);
301
	}
302
	
303
	/**
304
	 *Asigna la proyecci?n especificada en la cadena que se le pasa por par?metro.
305
	 *@param proj	proyecci?n
306
	 *@throws GdalException 
307
	 */
308
	public void setProjection(String proj)throws GdalException {
309
		if (cPtr == 0)
310
				throw new GdalException("No se ha podido acceder al archivo.");
311
		if (proj == null)
312
				throw new GdalException("La proyeccion es null");
313
		
314
		int res = setProjectionNat(cPtr, proj);
315
		
316
		if(res < 0)
317
			throw new GdalException("Error en setProjection(). No se ha podido asignar la proyecci?n.");
318
	}
319
	
320
	/**
321
	 * Obtiene la cadena que representa el tipo de banda de color. Los tipos posibles son:
322
	 * <UL>
323
	 *  <LI>0 = "Undefined" </LI>
324
	 *  <LI>1 = "Gray";</LI>
325
	 *  <LI>2 = "Palette";</LI>
326
	 *  <LI>3 = "Red";</LI>
327
	 *  <LI>4 = "Green";</LI>
328
	 *  <LI>5 = "Blue";</LI>
329
	 *  <LI>6 = "Alpha";</LI>
330
	 *  <LI>7 = "Hue";</LI>
331
	 *  <LI>8 = "Saturation";</LI>
332
	 *  <LI>9 = "Lightness";</LI>
333
	 *  <LI>10 = "Cyan";</LI>
334
	 *  <LI>11 = "Magenta";</LI>
335
	 *  <LI>12 = "Yellow";</LI>
336
	 *  <LI>13 = "Black";</LI>
337
	 *  <LI>14 = "YCbCr_Y";</LI>
338
	 *  <LI>15 = "YCbCr_Cb";</LI>
339
	 *  <LI>16 = "YCbCr_Cr";</LI>
340
	 * </UL>
341
	 * @return	Cadena con el nombre del tipo de banda de color
342
	 * @throws GdalException
343
	 */
344
	public String getColorInterpretationName(int colorInterp)throws GdalException {
345
		if ((colorInterp < 0) || (colorInterp > 16))
346
			throw new GdalException("Valor de interpretacion de color fuera de rango");
347
		
348
		String bandTypeName = getColorInterpretationNameNat(cPtr, colorInterp);
349
		
350
		if(bandTypeName == null)
351
			throw new GdalException("Error en getColorInterpretationName(). No ha podido obtenerse el tipo de banda de color");
352
		else 
353
			return bandTypeName;
354
	}	
355
	
356
}
0 357

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/main/java/org/gvsig/jgdal/GdalColorEntry.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22
package org.gvsig.jgdal;
23

  
24
/**
25
 * Clase que representa una entrada de la tabla de color.
26
 * @author Nacho Brodin (nachobrodin@gmail.com)
27
 *
28
 */
29
public class GdalColorEntry{
30
	 /*! gray, red, cyan or hue */
31
    public short      c1;      
32

  
33
    /*! green, magenta, or lightness */    
34
    public short      c2;      
35

  
36
    /*! blue, yellow, or saturation */
37
    public short      c3;      
38

  
39
    /*! alpha or blackband */
40
    public short      c4;      
41
}
0 42

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/main/java/org/gvsig/jgdal/GdalTools.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23
package org.gvsig.jgdal;
24

  
25
public class GdalTools {
26
	
27
	static public int CSLFindString(String[] lista, String target) {
28
		
29
		if(lista==null || lista.length==0)return -1;
30
		
31
		for( int i = 0; i<lista.length; i++ ) {
32
	        if( lista[i].equals(target) )
33
	            return i;
34
	    }
35
	    return -1;
36
		
37
	}
38
	
39
}
0 40

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/main/java/org/gvsig/jgdal/JNIBase.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
23

  
24
/**
25
 * @author Nacho Brodin <nachobrodin@gmail.com>.<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es
26
 * @version 0.0
27
 * @link http://www.gvsig.gva.es
28
 */
29

  
30
package org.gvsig.jgdal;
31

  
32
public class JNIBase{
33
	
34
	protected long cPtr;
35
	
36
	private native int getRasterBandXSizeNat(long cPtr);
37
	private native int getRasterBandYSizeNat(long cPtr);
38
	private native int getOverviewCountNat(long cPtr);
39
	private native int getBlockXSizeNat(long cPtr);
40
	private native int getBlockYSizeNat(long cPtr);
41
	private native int getRasterXSizeNat(long cPtr);
42
	private native int getRasterYSizeNat(long cPtr);
43
	private native int getRasterCountNat(long cPtr);
44
	private native int getGCPCountNat(long cPtr);
45
	private native int getRasterDataTypeNat(long cPtr);
46
	private native int getDriverCountNat(long cPtr);
47
	private native int getLayerCountNat(long cPtr);
48
	
49
	
50
	 /**
51
	 * Funci?n que sirve como base para funcionalidades de gdal que admiten como par?metro un entero y devuelven un entero.
52
	 * 
53
	 * @throws GdalException.
54
	 * @param msg1	Mensaje de error que se muestra cuando el puntero a objeto pasado es vacio.
55
	 * @param msg2	Mensaje de error que se muestra cuando el resultado de la llamada a la funci�n de gdal es menor o igual que 0.
56
	 */
57
	 
58
	 
59
	protected int baseSimpleFunctions(int n,String msg1,String msg2)throws GdalException{
60
			
61
		int res = 0;
62
			
63
		switch(n){
64
			case 0: res = getRasterBandXSizeNat(cPtr);break;
65
			case 1: res = getRasterBandYSizeNat(cPtr);break;
66
			case 2: res = getOverviewCountNat(cPtr);break;
67
			case 3: res = getBlockXSizeNat(cPtr);break;
68
			case 4: res = getBlockYSizeNat(cPtr);break;
69
			case 5: res = getRasterXSizeNat(cPtr);break;
70
			case 6: res = getRasterYSizeNat(cPtr);break;
71
			case 7: res = getRasterCountNat(cPtr);break;
72
			case 8: res = getGCPCountNat(cPtr);break;
73
			case 9: res = getRasterDataTypeNat(cPtr);break;
74
		}
75

  
76
		if (res < 0)
77
			throw new GdalException(msg2);
78
		else
79
			return res;
80
	}
81
	
82
	static {
83
		/*String os = System.getProperty("os.name");
84
		if (os.toLowerCase().startsWith("windows"))
85
			System.loadLibrary("jgdal201");
86
		else*/
87
			System.loadLibrary("jgdal2.0.4");
88
	}
89
}
0 90

  
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.jni/src/main/java/org/gvsig/jgdal/Options.java
1
/* gvSIG. Geographic Information System of the Valencian Government
2
*
3
* Copyright (C) 2007-2008 Infrastructures and Transports Department
4
* of the Valencian Government (CIT)
5
* 
6
* This program is free software; you can redistribute it and/or
7
* modify it under the terms of the GNU General Public License
8
* as published by the Free Software Foundation; either version 2
9
* of the License, or (at your option) any later version.
10
* 
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
* GNU General Public License for more details.
15
* 
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
* MA  02110-1301, USA.
20
* 
21
*/
22

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff