Revision 12616
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.121/org.gvsig.raster.gdal.io/pom.xml | ||
---|---|---|
1 |
<?xml version="1.0" encoding="ISO-8859-1"?> |
|
2 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
|
3 |
<modelVersion>4.0.0</modelVersion> |
|
4 |
<artifactId>org.gvsig.raster.gdal.io</artifactId> |
|
5 |
<packaging>jar</packaging> |
|
6 |
<name>${project.artifactId}</name> |
|
7 |
<parent> |
|
8 |
<groupId>org.gvsig</groupId> |
|
9 |
<artifactId>org.gvsig.raster.gdal</artifactId> |
|
10 |
<version>2.2.121</version> |
|
11 |
</parent> |
|
12 |
|
|
13 |
<dependencies> |
|
14 |
<dependency> |
|
15 |
<groupId>org.gdal</groupId> |
|
16 |
<artifactId>gdal</artifactId> |
|
17 |
<scope>compile</scope> |
|
18 |
</dependency> |
|
19 |
<dependency> |
|
20 |
<groupId>org.gvsig</groupId> |
|
21 |
<artifactId>org.gvsig.raster.cache.lib.api</artifactId> |
|
22 |
<scope>compile</scope> |
|
23 |
</dependency> |
|
24 |
<dependency> |
|
25 |
<groupId>org.gvsig</groupId> |
|
26 |
<artifactId>org.gvsig.raster.lib.api</artifactId> |
|
27 |
<scope>compile</scope> |
|
28 |
</dependency> |
|
29 |
<dependency> |
|
30 |
<groupId>org.gvsig</groupId> |
|
31 |
<artifactId>org.gvsig.raster.lib.impl</artifactId> |
|
32 |
<scope>compile</scope> |
|
33 |
</dependency> |
|
34 |
<dependency> |
|
35 |
<groupId>org.gvsig</groupId> |
|
36 |
<artifactId>org.gvsig.metadata.lib.basic.api</artifactId> |
|
37 |
<scope>compile</scope> |
|
38 |
</dependency> |
|
39 |
<dependency> |
|
40 |
<groupId>org.gvsig</groupId> |
|
41 |
<artifactId>org.gvsig.remoteclient</artifactId> |
|
42 |
<scope>compile</scope> |
|
43 |
</dependency> |
|
44 |
<dependency> |
|
45 |
<groupId>org.gvsig</groupId> |
|
46 |
<artifactId>org.gvsig.tools.lib</artifactId> |
|
47 |
<scope>compile</scope> |
|
48 |
</dependency> |
|
49 |
<dependency> |
|
50 |
<groupId>org.gvsig</groupId> |
|
51 |
<artifactId>org.gvsig.projection.api</artifactId> |
|
52 |
<scope>compile</scope> |
|
53 |
</dependency> |
|
54 |
<dependency> |
|
55 |
<groupId>org.gvsig</groupId> |
|
56 |
<artifactId>org.gvsig.projection.cresques.impl</artifactId> |
|
57 |
<scope>runtime</scope> |
|
58 |
</dependency> |
|
59 |
<dependency> |
|
60 |
<groupId>org.gvsig</groupId> |
|
61 |
<artifactId>org.gvsig.compat.api</artifactId> |
|
62 |
<scope>compile</scope> |
|
63 |
</dependency> |
|
64 |
<dependency> |
|
65 |
<groupId>org.gvsig</groupId> |
|
66 |
<artifactId>org.gvsig.compat.se</artifactId> |
|
67 |
<scope>runtime</scope> |
|
68 |
</dependency> |
|
69 |
<dependency> |
|
70 |
<groupId>org.gvsig</groupId> |
|
71 |
<artifactId>org.gvsig.fmap.dal.api</artifactId> |
|
72 |
<scope>compile</scope> |
|
73 |
</dependency> |
|
74 |
<dependency> |
|
75 |
<groupId>org.gvsig</groupId> |
|
76 |
<artifactId>org.gvsig.fmap.dal.impl</artifactId> |
|
77 |
<scope>runtime</scope> |
|
78 |
</dependency> |
|
79 |
<dependency> |
|
80 |
<groupId>org.gvsig</groupId> |
|
81 |
<artifactId>org.gvsig.fmap.dal.file.lib</artifactId> |
|
82 |
<scope>compile</scope> |
|
83 |
</dependency> |
|
84 |
<dependency> |
|
85 |
<groupId>org.gvsig</groupId> |
|
86 |
<artifactId>org.gvsig.fmap.dal.spi</artifactId> |
|
87 |
<scope>compile</scope> |
|
88 |
</dependency> |
|
89 |
<dependency> |
|
90 |
<groupId>org.gvsig</groupId> |
|
91 |
<artifactId>org.gvsig.fmap.geometry.api</artifactId> |
|
92 |
<scope>compile</scope> |
|
93 |
</dependency> |
|
94 |
|
|
95 |
</dependencies> |
|
96 |
|
|
97 |
|
|
98 |
</project> |
|
0 | 99 |
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.121/org.gvsig.raster.gdal.io/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/tags/org.gvsig.raster.gdal-2.2.121/org.gvsig.raster.gdal.io/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 { |
|
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 |
int stat = 0; |
|
62 |
|
|
63 |
return stat; |
|
64 |
} |
|
65 |
|
|
66 |
/** |
|
67 |
* Indica la proyecci?n del dataset origen |
|
68 |
* @param s_srs |
|
69 |
*/ |
|
70 |
public void setSsrs(String s_srs) { |
|
71 |
this.s_srs = s_srs; |
|
72 |
} |
|
73 |
|
|
74 |
/** |
|
75 |
* Obtiene el porcentaje de proceso que se ha completado |
|
76 |
*/ |
|
77 |
public int getPercent() { |
|
78 |
return porcentaje; |
|
79 |
} |
|
80 |
|
|
81 |
/** |
|
82 |
* Devuelve la lista de drivers que usa GdalWarp para reproyectar |
|
83 |
* @return |
|
84 |
*/ |
|
85 |
static public ArrayList getDrivers() { |
|
86 |
ArrayList list = new ArrayList(); |
|
87 |
list.add("GTiff"); |
|
88 |
list.add("VRT"); |
|
89 |
list.add("NITF"); |
|
90 |
list.add("HFA"); |
|
91 |
list.add("ELAS"); |
|
92 |
list.add("MEM"); |
|
93 |
list.add("BMP"); |
|
94 |
list.add("PCIDSK"); |
|
95 |
list.add("ILWIS"); |
|
96 |
String os = System.getProperty("os.name"); |
|
97 |
if (!os.toLowerCase().startsWith("windows")) |
|
98 |
list.add("HDF4Image"); |
|
99 |
list.add("PNM"); |
|
100 |
list.add("ENVI"); |
|
101 |
list.add("EHdr"); |
|
102 |
list.add("PAux"); |
|
103 |
list.add("MFF"); |
|
104 |
list.add("MFF2"); |
|
105 |
list.add("BT"); |
|
106 |
list.add("IDA"); |
|
107 |
list.add("RMF"); |
|
108 |
list.add("RST"); |
|
109 |
list.add("Leveller"); |
|
110 |
list.add("Terragen"); |
|
111 |
list.add("ERS"); |
|
112 |
list.add("INGR"); |
|
113 |
list.add("GSAG"); |
|
114 |
list.add("GSBG"); |
|
115 |
list.add("ADRG"); |
|
116 |
return list; |
|
117 |
} |
|
118 |
} |
|
0 | 119 |
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.121/org.gvsig.raster.gdal.io/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.nio.charset.Charset; |
|
26 |
import java.util.StringTokenizer; |
|
27 |
import java.util.Vector; |
|
28 |
|
|
29 |
import org.gdal.gdal.Dataset; |
|
30 |
import org.gdal.gdal.Driver; |
|
31 |
import org.gdal.gdal.gdal; |
|
32 |
/** |
|
33 |
* Representa un driver de un tipo de im?gen |
|
34 |
* |
|
35 |
* @author Nacho Brodin (nachobrodin@gmail.com).<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es |
|
36 |
* @version 0.0 |
|
37 |
* @link http://www.gvsig.gva.es |
|
38 |
*/ |
|
39 |
public class GdalDriver{ |
|
40 |
private Driver driver; |
|
41 |
|
|
42 |
public GdalDriver(Driver drv) { |
|
43 |
this.driver = drv; |
|
44 |
} |
|
45 |
|
|
46 |
/** |
|
47 |
* Crea una copia de una im?gen a partir de un dataset de origen especificado. |
|
48 |
* @param file Nombre del fichero sobre el cual se guardar? la copia |
|
49 |
* @param src Dataset fuente a copiar |
|
50 |
* @param bstrict TRUE si la copia debe ser estrictamente equivalente y FALSE indica que la copia puede |
|
51 |
* adaptarse a las necesidades del formato de salida |
|
52 |
* @return Gdal Dataset de la im?gen de salida |
|
53 |
* @throws GdalException |
|
54 |
*/ |
|
55 |
public GdalDataset createCopy(String file, GdalDataset src, boolean bstrict) throws GdalException { |
|
56 |
String path = file.substring(0, file.lastIndexOf(File.separator)); |
|
57 |
File f = new File(path); |
|
58 |
if (!f.canWrite()) |
|
59 |
throw new GdalException("Ruta de archivo incorrecta."); |
|
60 |
f = null; |
|
61 |
|
|
62 |
if (src == null) |
|
63 |
throw new GdalException("El objeto Gdal es null"); |
|
64 |
|
|
65 |
Dataset data = gdal.Open(file, bstrict ? 1 : 0); |
|
66 |
Dataset copyDataset = this.driver.CreateCopy(file, data, bstrict ? 1 : 0); |
|
67 |
|
|
68 |
return new GdalDataset(copyDataset); |
|
69 |
} |
|
70 |
|
|
71 |
|
|
72 |
/** |
|
73 |
* A partir de las opciones en forma de vector de Strings pasadas por el usuario donde cada |
|
74 |
* elemento del vector tiene la forma VARIABLE=VALOR crea el objeto Options para que sea accesible |
|
75 |
* a las funciones JNI desde C. |
|
76 |
* @param params Vector de strigs con las opciones |
|
77 |
* @return Options Objeto de opciones |
|
78 |
*/ |
|
79 |
private Options selectOptions(String[] params) { |
|
80 |
if (params == null) |
|
81 |
return null; |
|
82 |
|
|
83 |
Options opc = new Options(params.length); |
|
84 |
StringTokenizer st; |
|
85 |
for (int i = 0; i < params.length; i++) { |
|
86 |
st = new StringTokenizer(params[i], "="); |
|
87 |
String var = st.nextToken(); |
|
88 |
String dato = st.nextToken(); |
|
89 |
opc.addOption(var, dato); |
|
90 |
} |
|
91 |
return opc; |
|
92 |
} |
|
93 |
|
|
94 |
/** |
|
95 |
* Crea una copia de una im?gen a partir de un dataset de origen especificado y unos par?metros dados. |
|
96 |
* @param file Nombre del fichero sobre el cual se guardar? la copia |
|
97 |
* @param src Dataset fuente a copiar |
|
98 |
* @param bstrict TRUE si la copia debe ser estrictamente equivalente y FALSE indica que la copia puede |
|
99 |
* adaptarse a las necesidades del formato de salida |
|
100 |
* @param params Vector de strigs con las opciones de la copia |
|
101 |
* @return Gdal Dataset de la im?gen de salida |
|
102 |
* @throws GdalException |
|
103 |
*/ |
|
104 |
public GdalDataset createCopy(String file, GdalDataset src, boolean bstrict, String[] params) throws GdalException { |
|
105 |
String path = file.substring(0, file.lastIndexOf(File.separator)); |
|
106 |
File f = new File(path); |
|
107 |
if (!f.canWrite()) |
|
108 |
throw new GdalException("Ruta de archivo incorrecta."); |
|
109 |
f = null; |
|
110 |
|
|
111 |
Dataset data = gdal.Open(file, bstrict ? 1 : 0); |
|
112 |
Dataset copyDataset = this.driver.CreateCopy(file, src.getDataset(), bstrict ? 1 : 0, params); |
|
113 |
|
|
114 |
if (copyDataset == null) |
|
115 |
throw new GdalException("No se ha podido crear la copia"); |
|
116 |
|
|
117 |
return new GdalDataset(copyDataset); |
|
118 |
} |
|
119 |
|
|
120 |
|
|
121 |
/** |
|
122 |
* Crea un nuevo dataset con el driver actual |
|
123 |
* |
|
124 |
* @param filename Nombre del dataset a crear |
|
125 |
* @param nXSize Ancho en pixels |
|
126 |
* @param nYSize Alto en pixels |
|
127 |
* @param nBands N?mero de bandas |
|
128 |
* @param nType Tipo de raster |
|
129 |
* @param params lista de par?metros especificos del driver |
|
130 |
*/ |
|
131 |
public GdalDataset create(String filename, int nXSize, int nYSize, int nBands, int nType, String[] params) throws GdalException { |
|
132 |
|
|
133 |
byte ptext[] = filename.getBytes(Charset.forName("ISO_8859_1")); |
|
134 |
String value = new String(ptext, Charset.forName("UTF-8")); |
|
135 |
Dataset data = this.driver.Create(value, nXSize, nYSize, nBands, nType, StringArrayToVector(params)); |
|
136 |
|
|
137 |
return new GdalDataset(data); |
|
138 |
} |
|
139 |
|
|
140 |
private static Vector StringArrayToVector(String[] options) |
|
141 |
{ |
|
142 |
if (options == null) |
|
143 |
return null; |
|
144 |
Vector v = new Vector(); |
|
145 |
for(int i=0;i<options.length;i++) |
|
146 |
v.addElement(options[i]); |
|
147 |
return v; |
|
148 |
} |
|
149 |
|
|
150 |
} |
|
0 | 151 |
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.121/org.gvsig.raster.gdal.io/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/tags/org.gvsig.raster.gdal-2.2.121/org.gvsig.raster.gdal.io/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 |
import java.util.Arrays; |
|
25 |
|
|
26 |
/** |
|
27 |
* Buffer para el almacenamiento de los datos de georeferenciaci?n. |
|
28 |
* |
|
29 |
* @author Nacho Brodin (nachobrodin@gmail.com).<BR> Equipo de desarrollo |
|
30 |
* gvSIG.<BR> http://www.gvsig.gva.es |
|
31 |
* @version 0.0 |
|
32 |
* @see http://www.gvsig.gva.es |
|
33 |
* @link http://www.gvsig.gva.es |
|
34 |
*/ |
|
35 |
public class GeoTransform { |
|
36 |
|
|
37 |
public double adfgeotransform[] = new double[6]; |
|
38 |
|
|
39 |
private static double identity[] = {0, 1, 0, 0, 0, 1}; |
|
40 |
|
|
41 |
public boolean isIdentity() { |
|
42 |
return Arrays.equals(this.adfgeotransform, identity); |
|
43 |
} |
|
44 |
|
|
45 |
; |
|
46 |
|
|
47 |
public boolean isValid() { |
|
48 |
boolean valid = false; |
|
49 |
for (int i = 0; i < this.adfgeotransform.length; i++) { |
|
50 |
if (this.adfgeotransform[i] != 0) { |
|
51 |
valid = true; |
|
52 |
} |
|
53 |
} |
|
54 |
return valid; |
|
55 |
} |
|
56 |
|
|
57 |
public static class GeoTransformException extends GdalException { |
|
58 |
|
|
59 |
public GeoTransformException(String msg) { |
|
60 |
super(msg); |
|
61 |
} |
|
62 |
|
|
63 |
public GeoTransformException() { |
|
64 |
super("Invalid GeoTransformation"); |
|
65 |
} |
|
66 |
} |
|
67 |
|
|
68 |
} |
|
0 | 69 |
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.121/org.gvsig.raster.gdal.io/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/tags/org.gvsig.raster.gdal-2.2.121/org.gvsig.raster.gdal.io/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/tags/org.gvsig.raster.gdal-2.2.121/org.gvsig.raster.gdal.io/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 |
|
|
23 |
package org.gvsig.jgdal; |
|
24 |
|
|
25 |
|
|
26 |
public class Options { |
|
27 |
String[] vars; |
|
28 |
String[] datos; |
|
29 |
int longitud; |
|
30 |
int nopc; |
|
31 |
|
|
32 |
public Options(int nopciones) { |
|
33 |
vars=new String[nopciones]; |
|
34 |
datos=new String[nopciones]; |
|
35 |
longitud=nopciones; |
|
36 |
nopc=0; |
|
37 |
} |
|
38 |
|
|
39 |
public void addOption(String var, String dato) { |
|
40 |
vars[nopc]=var; |
|
41 |
datos[nopc]=dato; |
|
42 |
nopc++; |
|
43 |
} |
|
44 |
|
|
45 |
public int getSize() { |
|
46 |
return longitud; |
|
47 |
} |
|
48 |
} |
|
0 | 49 |
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.121/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/jgdal/GdalDataset.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.IOException; |
|
25 |
import java.util.Arrays; |
|
26 |
import java.util.Vector; |
|
27 |
|
|
28 |
import org.gdal.gdal.Band; |
|
29 |
import org.gdal.gdal.Dataset; |
|
30 |
import org.gdal.gdal.Driver; |
|
31 |
import org.gdal.gdal.gdal; |
|
32 |
import org.gdal.ogr.ogr; |
|
33 |
import org.gvsig.jgdal.GeoTransform.GeoTransformException; |
|
34 |
|
|
35 |
import org.gvsig.jogr.OGRTools; |
|
36 |
/** |
|
37 |
* Contiene las funcionalidades necesarias para el acceso a los elementos de un |
|
38 |
* dataset de gdal correspondiente a una imagen |
|
39 |
* |
|
40 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
41 |
*/ |
|
42 |
public class GdalDataset { |
|
43 |
// CONSTANTES |
|
44 |
|
|
45 |
// GDALAccess |
|
46 |
public static int GA_ReadOnly = 0; |
|
47 |
public static int GA_Update = 1; |
|
48 |
|
|
49 |
// GDALDataType |
|
50 |
public static int GDT_Unknown = 0; |
|
51 |
public static int GDT_Byte = 1; // Buffer byte (8) |
|
52 |
public static int GDT_UInt16 = 2; // Buffer short (16) |
|
53 |
public static int GDT_Int16 = 3; // Buffer short (16) |
|
54 |
public static int GDT_UInt32 = 4; // Buffer int (32) |
|
55 |
public static int GDT_Int32 = 5; // Buffer int (32) |
|
56 |
public static int GDT_Float32 = 6; // Buffer float (32) |
|
57 |
public static int GDT_Float64 = 7; // Buffer double (64) |
|
58 |
public static int GDT_CInt16 = 8; // Buffer short (16) |
|
59 |
public static int GDT_CInt32 = 9; // Buffer int (32) |
|
60 |
public static int GDT_CFloat32 = 10; // Buffer float (32) |
|
61 |
public static int GDT_CFloat64 = 11; // Buffer double (64) |
|
62 |
public static int GDT_TypeCount = 12; |
|
63 |
|
|
64 |
// private String pszFilename ; |
|
65 |
private Dataset dataset; |
|
66 |
|
|
67 |
/** |
|
68 |
*Constructor generico |
|
69 |
*/ |
|
70 |
public GdalDataset(){ |
|
71 |
super(); |
|
72 |
} |
|
73 |
|
|
74 |
public GdalDataset(Dataset dataset){ |
|
75 |
super(); |
|
76 |
this.dataset = dataset; |
|
77 |
} |
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
/** |
|
82 |
* Abre el fichero de imagen. |
|
83 |
* |
|
84 |
* @param filename Nombre del fichero. |
|
85 |
* @param access Apertura en solo lectura o escritura. |
|
86 |
* @throws GdalException |
|
87 |
*/ |
|
88 |
public void open(String filename, int access) throws GdalException, IOException { |
|
89 |
if (filename == null) { |
|
90 |
throw new IllegalArgumentException("filename is null"); |
|
91 |
} |
|
92 |
if ((access < 0) || (access > 1)) { |
|
93 |
throw new GdalException("Access type mistmatch (access="+access+")."); |
|
94 |
} |
|
95 |
this.dataset = gdal.Open(filename, access); |
|
96 |
if (this.dataset == null) { |
|
97 |
throw new GdalException("Can't open file '" + filename + "'."); |
|
98 |
} |
|
99 |
} |
|
100 |
|
|
101 |
/** |
|
102 |
* Obtiene un array de Strings con los metadatos |
|
103 |
* |
|
104 |
* @throws GdalException |
|
105 |
* @return Array de Strings que corresponden a los metadatos que ofrece la imagen |
|
106 |
*/ |
|
107 |
public String[] getMetadata()throws GdalException { |
|
108 |
return getMetadata(null); |
|
109 |
|
|
110 |
} |
|
111 |
|
|
112 |
|
|
113 |
/** |
|
114 |
* Obtiene un array de Strings con los metadatos |
|
115 |
* |
|
116 |
* @throws GdalException |
|
117 |
* @return Array de Strings que corresponden a los metadatos que ofrece la imagen |
|
118 |
*/ |
|
119 |
@SuppressWarnings("unchecked") |
|
120 |
public String[] getMetadata(String domain)throws GdalException { |
|
121 |
@SuppressWarnings("rawtypes") |
|
122 |
Vector res = this.dataset.GetMetadata_List(domain); |
|
123 |
if(res == null) |
|
124 |
return new String[0]; |
|
125 |
else |
|
126 |
return OGRTools.safeVectorToStringArray(res); |
|
127 |
|
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Obtiene el n?mero de bandas de la imagen |
|
132 |
* |
|
133 |
* @throws GdalException |
|
134 |
* @param hBand Entero que corresponde al n?mero de banda que se quiere recuperar |
|
135 |
* @return Objeto GdalRasterBand que representa la banda recuperada |
|
136 |
*/ |
|
137 |
|
|
138 |
public GdalRasterBand getRasterBand(int hBand)throws GdalException { |
|
139 |
Band rb; |
|
140 |
|
|
141 |
if ((hBand < 1) || (hBand > getRasterCount())) |
|
142 |
throw new GdalException("Banda seleccionada incorrecta"); |
|
143 |
|
|
144 |
if (this.dataset == null) |
|
145 |
throw new GdalException("No se ha podido acceder al archivo."); |
|
146 |
|
|
147 |
rb = this.dataset.GetRasterBand(hBand); |
|
148 |
|
|
149 |
return new GdalRasterBand(rb); |
|
150 |
} |
|
151 |
|
|
152 |
|
|
153 |
|
|
154 |
/** |
|
155 |
* Obtiene la dimensi?n del raster en el eje X. |
|
156 |
* |
|
157 |
* @return Devuelve un entero con la longitud de la imagen en el eje X en pixels. |
|
158 |
*/ |
|
159 |
public int getRasterXSize() { |
|
160 |
return this.dataset.getRasterXSize(); |
|
161 |
} |
|
162 |
|
|
163 |
|
|
164 |
/** |
|
165 |
* Obtiene la dimensi?n del raster en el eje Y. |
|
166 |
* |
|
167 |
* @return Devuelve un entero con la longitud de la imagen en el eje Y en pixels. |
|
168 |
*/ |
|
169 |
public int getRasterYSize() { |
|
170 |
return this.dataset.getRasterYSize(); |
|
171 |
} |
|
172 |
|
|
173 |
|
|
174 |
/** |
|
175 |
* Obtiene el n?mero de bandas de la imagen |
|
176 |
* |
|
177 |
* @return Devuelve un entero con el n?mero de bandas que contiene la imagen. |
|
178 |
*/ |
|
179 |
public int getRasterCount() { |
|
180 |
return this.dataset.getRasterCount(); |
|
181 |
} |
|
182 |
|
|
183 |
|
|
184 |
/** |
|
185 |
* Obtiene el vector geoTransform de la imagen que contiene los valores Origen y pixelSize |
|
186 |
* |
|
187 |
* @return Devuelve un vector de doubles que contiene los valores de coordenadas de origen y pixelSize. |
|
188 |
* @throws GdalException |
|
189 |
*/ |
|
190 |
public GeoTransform getGeoTransform() throws GdalException { |
|
191 |
GeoTransform gt = new GeoTransform(); |
|
192 |
|
|
193 |
if (this.dataset == null) { |
|
194 |
throw new GdalException("No se ha podido acceder al archivo."); |
|
195 |
} |
|
196 |
|
|
197 |
this.dataset.GetGeoTransform(gt.adfgeotransform); |
|
198 |
if (gt.isIdentity()) { |
|
199 |
// The default transform is (0,1,0,0,0,1) and should be returned even when an error occurs, |
|
200 |
// such as for formats that don't support transformation to projection coordinates. |
|
201 |
// http://gdal.org/java/org/gdal/gdal/Dataset.html#GetGeoTransform%28double[]%29 |
|
202 |
throw new GeoTransformException("Error en getGeoTransform(). No se han obtenido valores para geoTransform."); |
|
203 |
} |
|
204 |
|
|
205 |
return gt; |
|
206 |
} |
|
207 |
|
|
208 |
/** |
|
209 |
* Obtiene el Nombre corto asociado al driver del dataset |
|
210 |
* |
|
211 |
* @return Cadena con el nombre del driver |
|
212 |
* @throws GdalException |
|
213 |
*/ |
|
214 |
public String getDriverShortName()throws GdalException { |
|
215 |
if (this.dataset == null) |
|
216 |
throw new GdalException("No se ha podido acceder al archivo."); |
|
217 |
|
|
218 |
String shortName =this.dataset.GetDriver().getShortName(); |
|
219 |
|
|
220 |
if(shortName == null) |
|
221 |
throw new GdalException("Error en getDriverShortName(). No ha podido obtenerse el driver"); |
|
222 |
else |
|
223 |
return shortName; |
|
224 |
} |
|
225 |
|
|
226 |
/** |
|
227 |
* A?ade el vector geoTransform a la imagen que contiene los valores Origen y pixelSize |
|
228 |
* |
|
229 |
* @return Devuelve un vector de doubles que contiene los valores de coordenadas de origen y pixelSize. |
|
230 |
* @throws GdalException |
|
231 |
*/ |
|
232 |
public void setGeoTransform(GeoTransform gt)throws GdalException { |
|
233 |
if (this.dataset == null) |
|
234 |
throw new GdalException("No se ha podido acceder al archivo."); |
|
235 |
if (gt == null) |
|
236 |
throw new GdalException("el objeto es null"); |
|
237 |
|
|
238 |
@SuppressWarnings("unused") |
|
239 |
int res = this.dataset.SetGeoTransform(gt.adfgeotransform); |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* Obtiene el sistema de coordenadas de referencia de la imagen. |
|
244 |
* |
|
245 |
* @return Devuelve un String con los datos del sistema de coordenadas de referencia. |
|
246 |
* @throws GdalException |
|
247 |
*/ |
|
248 |
public String getProjectionRef()throws GdalException { |
|
249 |
if (this.dataset == null) |
|
250 |
throw new GdalException("No se ha podido acceder al archivo."); |
|
251 |
|
|
252 |
String res = this.dataset.GetProjectionRef(); |
|
253 |
|
|
254 |
if(res == null)return new String(""); |
|
255 |
else return res; |
|
256 |
} |
|
257 |
|
|
258 |
/** |
|
259 |
* Cierra el fichero de imagen. |
|
260 |
* |
|
261 |
* @throws GdalException |
|
262 |
*/ |
|
263 |
public void close()throws GdalException { |
|
264 |
// if (cPtr == 0) |
|
265 |
// throw new GdalException("No se ha podido acceder al archivo."); |
|
266 |
// |
|
267 |
// closeNat(cPtr); |
|
268 |
this.dataset.delete(); |
|
269 |
} |
|
270 |
|
|
271 |
/** |
|
272 |
* Obtiene un driver a trav?s de su nombre |
|
273 |
* |
|
274 |
* @param name Nombre del driver |
|
275 |
*/ |
|
276 |
public static GdalDriver getDriverByName(String name)throws GdalException { |
|
277 |
|
|
278 |
if (name == null) |
|
279 |
throw new GdalException("El nombre del driver es null"); |
|
280 |
gdal.AllRegister(); |
|
281 |
ogr.RegisterAll(); |
|
282 |
Driver ptrdrv = gdal.GetDriverByName(name); |
|
283 |
|
|
284 |
return new GdalDriver(ptrdrv); |
|
285 |
} |
|
286 |
|
|
287 |
|
|
288 |
/** |
|
289 |
* Obtiene el numero de bandas de la imagen |
|
290 |
* |
|
291 |
* @return Devuelve un entero con el numero de bandas que contiene la imagen. |
|
292 |
* @throws GdalException |
|
293 |
*/ |
|
294 |
public int getGCPCount()throws GdalException { |
|
295 |
// String msg1="Error en GDALGetRasterCount. . La llamada GDALOpen no tuvo ?xito"; |
|
296 |
// String msg2="Error en el conteo de n?mero de bandas"; |
|
297 |
return this.dataset.GetGCPCount(); |
|
298 |
} |
|
299 |
|
|
300 |
public Dataset getDataset(){ |
|
301 |
return this.dataset; |
|
302 |
} |
|
303 |
|
|
304 |
/** |
|
305 |
*Asigna la proyecci?n especificada en la cadena que se le pasa por par?metro. |
|
306 |
*@param proj proyecci?n |
|
307 |
*@throws GdalException |
|
308 |
*/ |
|
309 |
public void setProjection(String proj)throws GdalException { |
|
310 |
if (this.dataset == null) |
|
311 |
throw new GdalException("No se ha podido acceder al archivo."); |
|
312 |
if (proj == null) |
|
313 |
throw new GdalException("La proyeccion es null"); |
|
314 |
|
|
315 |
int res = this.dataset.SetProjection(proj); |
|
316 |
|
|
317 |
if(res < 0) |
|
318 |
throw new GdalException("Error en setProjection(). No se ha podido asignar la proyecci?n."); |
|
319 |
} |
|
320 |
|
|
321 |
/** |
|
322 |
* Obtiene la cadena que representa el tipo de banda de color. Los tipos posibles son: |
|
323 |
* <UL> |
|
324 |
* <LI>0 = "Undefined" </LI> |
|
325 |
* <LI>1 = "Gray";</LI> |
|
326 |
* <LI>2 = "Palette";</LI> |
|
327 |
* <LI>3 = "Red";</LI> |
|
328 |
* <LI>4 = "Green";</LI> |
|
329 |
* <LI>5 = "Blue";</LI> |
|
330 |
* <LI>6 = "Alpha";</LI> |
|
331 |
* <LI>7 = "Hue";</LI> |
|
332 |
* <LI>8 = "Saturation";</LI> |
|
333 |
* <LI>9 = "Lightness";</LI> |
|
334 |
* <LI>10 = "Cyan";</LI> |
|
335 |
* <LI>11 = "Magenta";</LI> |
|
336 |
* <LI>12 = "Yellow";</LI> |
|
337 |
* <LI>13 = "Black";</LI> |
|
338 |
* <LI>14 = "YCbCr_Y";</LI> |
|
339 |
* <LI>15 = "YCbCr_Cb";</LI> |
|
340 |
* <LI>16 = "YCbCr_Cr";</LI> |
|
341 |
* </UL> |
|
342 |
* @return Cadena con el nombre del tipo de banda de color |
|
343 |
* @throws GdalException |
|
344 |
*/ |
|
345 |
public String getColorInterpretationName(int colorInterp)throws GdalException { |
|
346 |
if ((colorInterp < 0) || (colorInterp > 16)) |
|
347 |
throw new GdalException("Valor de interpretacion de color fuera de rango"); |
|
348 |
|
|
349 |
String bandTypeName = gdal.GetColorInterpretationName(colorInterp); |
|
350 |
|
|
351 |
if(bandTypeName == null) |
|
352 |
throw new GdalException("Error en getColorInterpretationName(). No ha podido obtenerse el tipo de banda de color"); |
|
353 |
else |
|
354 |
return bandTypeName; |
|
355 |
} |
|
356 |
|
|
357 |
} |
|
0 | 358 |
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.121/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/jgdal/GdalRasterBand.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 |
import java.util.Vector; |
|
26 |
|
|
27 |
import org.gdal.gdal.Band; |
|
28 |
import org.gdal.gdal.ColorTable; |
|
29 |
import org.slf4j.Logger; |
|
30 |
import org.slf4j.LoggerFactory; |
|
31 |
|
|
32 |
/** |
|
33 |
* Representa a una banda simple de la im�gen o canal. |
|
34 |
* |
|
35 |
* @author Nacho Brodin (nachobrodin@gmail.com).<BR> Equipo de desarrollo gvSIG.<BR> http://www.gvsig.gva.es |
|
36 |
* @version 0.0 |
|
37 |
* @link http://www.gvsig.gva.es |
|
38 |
*/ |
|
39 |
|
|
40 |
public class GdalRasterBand { |
|
41 |
|
|
42 |
public static final Logger logger = LoggerFactory.getLogger(GdalRasterBand.class); |
|
43 |
|
|
44 |
private boolean hasNoDataValue = false; |
|
45 |
|
|
46 |
private Band band; |
|
47 |
|
|
48 |
public GdalRasterBand(Band band) { |
|
49 |
this.band = band; |
|
50 |
} |
|
51 |
|
|
52 |
/** |
|
53 |
* Lee datos de la banda de la imagen |
|
54 |
* |
|
55 |
* @return Devuelve un vector de bytes con el trozo de raster le�do. |
|
56 |
* @param nXOff El desplazamiento del pixel desde la esquina superior derecha |
|
57 |
* de la banda accedida. |
|
58 |
* @param nYOff El desplazamiento de l�nea desde la esquina superior derecha |
|
59 |
* de la banda accedida. |
|
60 |
* @param nXSize Ancho de la regi�n en pixels de la banda que ser� accedida |
|
61 |
* @param nYSize Altura de la regi�n en l�neas de la banda que ser� accedida |
|
62 |
* @param bufXSize Ancho del buffer donde la regi�n de la im�gen ser� guardada |
|
63 |
* @param bufYSize Altura del buffer donde la regi�n de la im�gen ser� guardada |
|
64 |
* En caso de que bufXSize o bufYSize sean menores que 1, pasan a tener el mismo valor que |
|
65 |
* nXSize y nYSize respectivamente para evitar buffers con tama?o 0. |
|
66 |
* @param eBufType |
|
67 |
*/ |
|
68 |
|
|
69 |
public GdalBuffer readRaster(int nXOff, int nYOff, int nXSize, int nYSize, |
|
70 |
int bufXSize, int bufYSize, |
|
71 |
int eBufType)throws GdalException { |
|
72 |
|
|
73 |
if ((nXOff<0) || (nXOff > getRasterBandXSize()) || (nYOff < 0) || (nYOff > getRasterBandYSize())) |
|
74 |
throw new GdalException("Desplazamiento de la ventana fuera de rango."); |
|
75 |
|
|
76 |
if ((nXSize < 1) || (nXSize > getRasterBandXSize()) || (nYSize<1) || (nYSize > getRasterBandYSize())) |
|
77 |
throw new GdalException("Tama?o de ventana incorrecto."); |
|
78 |
|
|
79 |
if (((nXSize + nXOff) > (getRasterBandXSize())) || ((nYSize + nYOff) > (getRasterBandYSize()))){ |
|
80 |
throw new GdalException("Posicion de la ventana incorrecta."); |
|
81 |
} |
|
82 |
|
|
83 |
if ((eBufType < 1) || (eBufType > 11)) |
|
84 |
throw new GdalException("Tipo de datos incorrecto."); |
|
85 |
|
|
86 |
if (bufXSize < 1) |
|
87 |
bufXSize = nXSize; |
|
88 |
|
|
89 |
if (bufYSize < 1) |
|
90 |
bufYSize = nYSize; |
|
91 |
|
|
92 |
GdalBuffer buf = new GdalBuffer(); |
|
93 |
int i = 0; |
|
94 |
|
|
95 |
switch(eBufType) { |
|
96 |
case 0: |
|
97 |
i = 0; |
|
98 |
break; |
|
99 |
case 1: |
|
100 |
buf.reservaByte(bufXSize * bufYSize); |
|
101 |
i = this.band.ReadRaster(nXOff, nYOff, nXSize, nYSize, bufXSize, bufYSize, eBufType, buf.buffByte); |
|
102 |
break; |
|
103 |
case 2: |
|
104 |
case 3: |
|
105 |
case 8: |
|
106 |
buf.reservaShort(bufXSize * bufYSize); |
|
107 |
i = this.band.ReadRaster(nXOff, nYOff, nXSize, nYSize, bufXSize, bufYSize, eBufType, buf.buffShort); |
|
108 |
break; |
|
109 |
case 4: |
|
110 |
case 5: |
|
111 |
case 9: |
|
112 |
buf.reservaInt(bufXSize * bufYSize); |
|
113 |
i = this.band.ReadRaster(nXOff, nYOff, nXSize, nYSize, bufXSize, bufYSize, eBufType, buf.buffInt); |
|
114 |
break; |
|
115 |
case 6: |
|
116 |
case 10: |
|
117 |
buf.reservaFloat(bufXSize * bufYSize); |
|
118 |
i = this.band.ReadRaster(nXOff, nYOff, nXSize, nYSize, bufXSize, bufYSize, eBufType, buf.buffFloat); |
|
119 |
break; |
|
120 |
case 7: |
|
121 |
case 11: |
|
122 |
buf.reservaDouble(bufXSize * bufYSize); |
|
123 |
i = this.band.ReadRaster(nXOff, nYOff, nXSize, nYSize, bufXSize, bufYSize, eBufType, buf.buffDouble); |
|
124 |
break; |
|
125 |
case 12: |
|
126 |
i = 0; |
|
127 |
break; |
|
128 |
} |
|
129 |
|
|
130 |
|
|
131 |
if(i>=0) |
|
132 |
return buf; |
|
133 |
else |
|
134 |
return null; |
|
135 |
} |
|
136 |
|
|
137 |
/** |
|
138 |
* Escribe datos en la banda de la imagen |
|
139 |
* |
|
140 |
* @param nXOff El desplazamiento del pixel desde la esquina superior derecha |
|
141 |
* de la banda accedida. |
|
142 |
* @param nYOff El desplazamiento de l�nea desde la esquina superior derecha |
|
143 |
* de la banda accedida. |
|
144 |
* @param nXSize Ancho de la regi�n en pixels de la banda que ser� accedida |
|
145 |
* @param nYSize Altura de la regi�n en l�neas de la banda que ser� accedida |
|
146 |
* @param BufXSize Ancho del buffer donde la regi�n de la im�gen ser� guardada |
|
147 |
* @param BufYSize Altura del buffer donde la regi�n de la im�gen ser� guardada |
|
148 |
* @param eBufType |
|
149 |
*/ |
|
150 |
|
|
151 |
public void writeRaster(int nXOff, int nYOff, int nXSize, int nYSize, GdalBuffer buf, int eBufType)throws GdalException { |
|
152 |
GdalBuffer buffer = new GdalBuffer(); |
|
153 |
|
|
154 |
if ((nXOff < 0) || (nXOff > getRasterBandXSize()) || (nYOff < 0) || (nYOff > getRasterBandYSize())) |
|
155 |
throw new GdalException("Desplazamiento de la ventana fuera de rango."); |
|
156 |
|
|
157 |
if ((nXSize < 1) || (nXSize > getRasterBandXSize()) || (nYSize < 1) || (nYSize > getRasterBandYSize())) |
|
158 |
throw new GdalException("Tama?o de ventana incorrecto."); |
|
159 |
|
|
160 |
if (((nXSize + nXOff) > (getRasterBandXSize())) || ((nYSize + nYOff) > (getRasterBandYSize()))) |
|
161 |
throw new GdalException("Posicion de la ventana incorrecta."); |
|
162 |
|
|
163 |
if ((eBufType < 1) || (eBufType > 11)) |
|
164 |
throw new GdalException("Tipo de datos incorrecto."); |
|
165 |
|
|
166 |
if (buf == null) |
|
167 |
throw new GdalException("Buffer incorrecto"); |
|
168 |
|
|
169 |
switch(eBufType) { |
|
170 |
case 0: |
|
171 |
return; |
|
172 |
case 1: |
|
173 |
buffer.buffByte = buf.buffByte; |
|
174 |
break; |
|
175 |
case 2: |
|
176 |
case 3: |
|
177 |
case 8: |
|
178 |
buffer.buffShort = buf.buffShort; |
|
179 |
break; |
|
180 |
case 4: |
|
181 |
case 5: |
|
182 |
case 9: |
|
183 |
buffer.buffInt = buf.buffInt; |
|
184 |
break; |
|
185 |
case 6: |
|
186 |
case 10: |
|
187 |
buffer.buffFloat = buf.buffFloat; |
|
188 |
break; |
|
189 |
case 7: |
|
190 |
case 11: |
|
191 |
buffer.buffDouble = buf.buffDouble; |
|
192 |
break; |
|
193 |
case 12: |
|
194 |
return; |
|
195 |
} |
|
196 |
|
|
197 |
|
|
198 |
|
|
199 |
switch(eBufType) { |
|
200 |
case 0: |
|
201 |
break; |
|
202 |
case 1: |
|
203 |
this.band.WriteRaster(nXOff, nYOff, nXSize, nYSize, eBufType, buffer.buffByte); |
|
204 |
break; |
|
205 |
case 2: |
|
206 |
case 3: |
|
207 |
case 8: |
|
208 |
this.band.WriteRaster(nXOff, nYOff, nXSize, nYSize, eBufType, buffer.buffShort); |
|
209 |
break; |
|
210 |
case 4: |
|
211 |
case 5: |
|
212 |
case 9: |
|
213 |
this.band.WriteRaster(nXOff, nYOff, nXSize, nYSize, eBufType, buffer.buffInt); |
|
214 |
break; |
|
215 |
case 6: |
|
216 |
case 10: |
|
217 |
this.band.WriteRaster(nXOff, nYOff, nXSize, nYSize, eBufType, buffer.buffFloat); |
|
218 |
break; |
|
219 |
case 7: |
|
220 |
case 11: |
|
221 |
this.band.WriteRaster(nXOff, nYOff, nXSize, nYSize, eBufType, buffer.buffDouble); |
|
222 |
break; |
|
223 |
case 12: |
|
224 |
break; |
|
225 |
} |
|
226 |
} |
|
227 |
|
|
228 |
/** |
|
229 |
*Obtiene el tama�o en pixeles de la im�gen en el eje de las X |
|
230 |
*@return Tama�o en pixeles del eje X |
|
231 |
*@throws GdalException |
|
232 |
*/ |
|
233 |
|
|
234 |
public int getRasterBandXSize()throws GdalException { |
|
235 |
return this.band.GetXSize(); |
|
236 |
} |
|
237 |
|
|
238 |
/** |
|
239 |
*Obtiene el tama?o en pixeles de la im?gen en el eje de las Y |
|
240 |
*@return Tama�o en pixeles del eje Y |
|
241 |
*@throws GdalException |
|
242 |
*/ |
|
243 |
|
|
244 |
public int getRasterBandYSize()throws GdalException { |
|
245 |
return this.band.GetYSize(); |
|
246 |
} |
|
247 |
|
|
248 |
|
|
249 |
/** |
|
250 |
* Devuelve el n�mero de overviews que contiene la banda. |
|
251 |
* @return N�mero de overviews |
|
252 |
* @throws GdalException |
|
253 |
*/ |
|
254 |
|
|
255 |
public int getOverviewCount()throws GdalException { |
|
256 |
return this.band.GetOverviewCount(); |
|
257 |
} |
|
258 |
|
|
259 |
|
|
260 |
/** |
|
261 |
* Obtiene el overview indicado por el �ndice "i". |
|
262 |
* |
|
263 |
* @param i indice del overview que se quiere recuperar. |
|
264 |
* @return GdalRasterBand Banda correspondiente al overview selecccionado |
|
265 |
* @throws GdalException |
|
266 |
*/ |
|
267 |
|
|
268 |
public GdalRasterBand getOverview(int i)throws GdalException { |
|
269 |
Band band_ov; |
|
270 |
|
|
271 |
if((i < 0) || (i >= getOverviewCount())) |
|
272 |
throw new GdalException("El overview seleccionado no existe"); |
|
273 |
|
|
274 |
band_ov = this.band.GetOverview(i); |
|
275 |
|
|
276 |
if (band_ov == null || !(band_ov instanceof Band)) |
|
277 |
throw new GdalException("No se ha podido obtener el overview"); |
|
278 |
|
|
279 |
return new GdalRasterBand(band_ov); |
|
280 |
} |
|
281 |
|
|
282 |
|
|
283 |
/** |
|
284 |
* Devuelve el tama�o en X del bloque para esa banda |
|
285 |
* @return Tama�o en pixeles del bloque en el eje X |
|
286 |
* @throws GdalException |
|
287 |
*/ |
|
288 |
|
|
289 |
public int getBlockXSize()throws GdalException { |
|
290 |
return this.band.GetBlockXSize(); |
|
291 |
} |
|
292 |
|
|
293 |
|
|
294 |
/** |
|
295 |
* Devuelve el tama�o en Y del bloque para esa banda |
|
296 |
* @return Tama�o en pixeles del bloque en el eje Y |
|
297 |
* @throws GdalException |
|
298 |
*/ |
|
299 |
|
|
300 |
public int getBlockYSize()throws GdalException { |
|
301 |
return this.band.GetBlockYSize(); |
|
302 |
} |
|
303 |
|
|
304 |
/** |
|
305 |
* Devuelve el tipo de datos de la banda |
|
306 |
* @return Tama�o en pixeles del bloque en el eje Y |
|
307 |
* @throws GdalException |
|
308 |
*/ |
|
309 |
|
|
310 |
public int getRasterDataType()throws GdalException { |
|
311 |
return this.band.getDataType(); |
|
312 |
} |
|
313 |
|
|
314 |
/** |
|
315 |
* Obtiene la tabla de color asociada a la imagen |
|
316 |
*/ |
|
317 |
public GdalColorTable getRasterColorTable()throws GdalException { |
|
318 |
ColorTable ct = this.band.GetColorTable(); |
|
319 |
|
|
320 |
if ((ct == null)) { |
|
321 |
return null; |
|
322 |
} |
|
323 |
|
|
324 |
return new GdalColorTable(ct); |
|
325 |
} |
|
326 |
|
|
327 |
/** |
|
328 |
* Lee datos de la banda de la im�gen con una paleta asociada |
|
329 |
* |
|
330 |
* @return Devuelve un vector de bytes con el trozo de raster le�do. |
|
331 |
* @param nXOff El desplazamiento del pixel desde la esquina superior derecha |
|
332 |
* de la banda accedida. |
|
333 |
* @param nYOff El desplazamiento de l�nea desde la esquina superior derecha |
|
334 |
* de la banda accedida. |
Also available in: Unified diff