Revision 30

View differences:

org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/dataset/MultiRasterDataSet.java
103 103
	 * @param f fichero a a?adir.
104 104
	 * @throws RasterDriverException 
105 105
	 */
106
	public void addDataset(RasterDataSet[] f)throws FileNotFoundInListException, OperationNotSupportedException, InvalidSourceException;
106
	public void addDataset(RasterDataSet f)throws FileNotFoundInListException, OperationNotSupportedException, InvalidSourceException;
107 107
	
108 108
	/**
109 109
	 * A?ade un fichero a la lista de datasets a partir de su nombre. Si se trata de un multiRasterDataset
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/dataset/ColorInterpretation.java
29 29
 * @author Nacho Brodin (nachobrodin@gmail.com)
30 30
 */
31 31
public interface ColorInterpretation {
32
	// Identificadores de color interpretation
33
	public static final String RED_BAND            = "Red";
34
	public static final String GREEN_BAND          = "Green";
35
	public static final String BLUE_BAND           = "Blue";
36
	public static final String ALPHA_BAND          = "Alpha";
37
	public static final String GRAY_BAND           = "Gray";
38
	public static final String PAL_BAND            = "Palette";
39
	public static final String UNDEF_BAND          = "Undefined";
40
	
32 41
	/**
33 42
	 * Asigna un valor para la interpretaci?n de color de una banda
34 43
	 * @param band Banda 
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/grid/RasterFilterListManager.java
77 77
		 * @return RasterFilterList
78 78
		 */
79 79
		public RasterFilterList getFilterList();
80
		
80 81
}
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/grid/Grid.java
22 22
package org.gvsig.fmap.dal.coverage.grid;
23 23

  
24 24

  
25
import org.gvsig.fmap.dal.coverage.buffer.Buffer;
25 26
import org.gvsig.fmap.dal.coverage.dataset.BasicStats;
26 27
import org.gvsig.fmap.dal.coverage.dataset.ColorTable;
27 28
import org.gvsig.fmap.dal.coverage.datastruct.GridCell;
......
35 36
 * Interfaz que deben implementar los grid en los que se puede consultar sus datos.
36 37
 * @author Nacho Brodin (nachobrodin@gmail.com)
37 38
 */
38
public interface Grid {	  
39
public interface Grid {	
40
	
39 41
	/**
42
	 *Aplica la lista de filtros sobre el buffer
43
	 * @throws InterruptedException
44
	 */
45
	public void applyFilters() throws InterruptedException;
46
	
47
	/**
40 48
	 * Carga el buffer de datos desde el reader para poder escribir sobre los datos de
41 49
	 * la ventana original. Esto es ?til cuando el GridWriter se crea asociado a un raster
42 50
	 * pero el buffer est? vacio, por ejemplo en el caso de crear un GridInterpolated. Un
......
47 55
	public void loadWriterData() throws GridException;
48 56
	
49 57
	/**
58
	 * Obtiene el buffer de datos del grid
59
	 * @return RasterBuf
60
	 */
61
	public Buffer getRasterBuf();
62
	
63
	/**
50 64
	 * Exporta el grid a ASCII
51 65
	 * @param sFilename
52 66
	 */
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/grid/RasterFilter.java
101 101
		public String getName();
102 102
		
103 103
		/**
104
		 * @param name the fName to set
105
		 */
106
		public void setName(String name);
107
		
108
		/**
104 109
		 * Obtiene el TreeMap con los par?metros del entorno
105 110
		 * @return TreeMap
106 111
		 */
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/buffer/Buffer.java
25 25
import java.awt.image.DataBuffer;
26 26

  
27 27
import org.gvsig.fmap.dal.coverage.datastruct.Band;
28
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram;
28 29

  
29 30
/**
30 31
 * Interfaz que contiene las operaciones que debe soportar un buffer de datos.
......
167 168
	public void setDataExtent(Rectangle2D r);
168 169
    
169 170
	/**
171
	 * Gets the histogram of this buffer
172
	 * @return
173
	 * @throws InterruptedException
174
	 */
175
	public BufferHistogram getHistogram() throws InterruptedException;
176
	
177
	/**
170 178
	 * Libera el buffer de memoria
171 179
	 */
172 180
	public void free();
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/buffer/RasterDataSource.java
45 45
	public Buffer getLastBuffer();
46 46
	
47 47
	/**
48
	 * Gets the step
49
	 * @return
50
	 */
51
	public double[] getStep();
52
	
53
	/**
48 54
	 * Hace una consulta para la carga de un buffer de datos.
49 55
	 * @param query 
50 56
	 * @return IBuffer
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/RasterManager.java
26 26

  
27 27
import org.cresques.cts.IProjection;
28 28
import org.gvsig.fmap.dal.coverage.buffer.Buffer;
29
import org.gvsig.fmap.dal.coverage.buffer.RasterDataSource;
29 30
import org.gvsig.fmap.dal.coverage.buffer.RasterQuery;
31
import org.gvsig.fmap.dal.coverage.dataset.ColorInterpretation;
30 32
import org.gvsig.fmap.dal.coverage.dataset.DataServerWriter;
31
import org.gvsig.fmap.dal.coverage.dataset.MultiRasterDataSet;
32 33
import org.gvsig.fmap.dal.coverage.dataset.RasterWriter;
33 34
import org.gvsig.fmap.dal.coverage.datastruct.Params;
34 35
import org.gvsig.fmap.dal.coverage.datastruct.RasterLegend;
35 36
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
36 37
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
37 38
import org.gvsig.fmap.dal.coverage.exception.RasterLegendIONotFound;
39
import org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder;
40
import org.gvsig.fmap.dal.coverage.process.vector.Vectorization;
38 41
import org.gvsig.tools.service.ServiceException;
39 42

  
40 43
/**
......
85 88
	 * @throws NotSupportedExtensionException
86 89
	 * @throws RasterDriverException
87 90
	 */
88
	public MultiRasterDataSet open(IProjection proj, Object datasetOpenParam) throws NotSupportedExtensionException, RasterDriverException;
91
	public RasterDataSource open(IProjection proj, Object datasetOpenParam) throws NotSupportedExtensionException, RasterDriverException;
89 92
	
90 93
	/**
91 94
	 * Builds a new empty RasterQuery object
92 95
	 * @return
93 96
	 */
94
	public RasterQuery getQuery();
97
	public RasterQuery createQuery();
95 98
	
96 99
	/**
97 100
	 * Genera instancias del buffer de datos adecuado al tama?o del raster. Si no hay muchos datos
......
113 116
	 * @throws NotSupportedExtensionException 
114 117
	 * @throws FileNotFoundException 
115 118
	 */
116
	public Buffer getBuffer(int dataType, int width, int height, int bandNr, boolean malloc);
119
	public Buffer createBuffer(int dataType, int width, int height, int bandNr, boolean malloc);
117 120
	
118 121
	/**
119 122
	 * Genera una instancia del buffer de solo lectura. Este buffer consta de una cache y unos apuntadores
......
124 127
	 * @param height Alto
125 128
	 * @param bandNr Banda
126 129
	 */
127
	public Buffer getReadOnlyBuffer(int dataType, int width, int height, int bandNr);
130
	public Buffer createReadOnlyBuffer(int dataType, int width, int height, int bandNr);
128 131
	
129 132
	/**
130 133
	 * Genera una instancia del buffer de solo lectura. Este buffer consta de una cache y unos apuntadores
......
138 141
	 * para el buffer de forma normal y si est? a false no se reserva por lo que la reserva deber? ser
139 142
	 * posterior. 
140 143
	 */
141
	public Buffer getMemoryBuffer(int dataType, int width, int height, int bandNr, boolean malloc);
144
	public Buffer createMemoryBuffer(int dataType, int width, int height, int bandNr, boolean malloc);
142 145
	
143 146
	/**
144 147
	 * Factoria para obtener escritores de los distintos tipos de raster.
145 148
	 * @param fName Nombre del fichero.
146 149
	 * @return GeoRasterWriter, o null si hay problemas.
147 150
	 */
148
	public RasterWriter getWriter(String fName) throws NotSupportedExtensionException, RasterDriverException;
151
	public RasterWriter createWriter(String fName) throws NotSupportedExtensionException, RasterDriverException;
149 152

  
150 153
	/**
151 154
	 * Factoria para obtener escritores de los distintos tipos de raster.
......
153 156
	 * @param fName Nombre del fichero.
154 157
	 * @return GeoRasterWriter, o null si hay problemas.
155 158
	 */
156
	public RasterWriter getWriter(DataServerWriter dataWriter,
159
	public RasterWriter createWriter(DataServerWriter dataWriter,
157 160
												 String outFileName,
158 161
												 int nBands,
159 162
												 AffineTransform at,
......
169 172
	 * @param fName Nombre del fichero.
170 173
	 * @return GeoRasterWriter, o null si hay problemas.
171 174
	 */
172
	public RasterWriter getWriter(DataServerWriter dataWriter,
175
	public RasterWriter createWriter(DataServerWriter dataWriter,
173 176
												 String outFileName,
174 177
												 int nBands,
175 178
												 AffineTransform at,
......
179 182
												 Params params,
180 183
												 IProjection proj,
181 184
												 boolean geo) throws NotSupportedExtensionException, RasterDriverException;
185
	
186
	/**
187
	 * Obtiene los par?metros del driver de escritura a partir del nombre de fichero de salida.
188
	 * @return WriterParams
189
	 */
190
	public Params createWriterParams(String fileName);
191
	
192
	/**
193
	 * Gets an object which vectorize a raster
194
	 * @param dataSource
195
	 * @return
196
	 * @throws RasterDriverException
197
	 * @throws InterruptedException
198
	 *         When the object Vectorization is built the raster data buffer is loaded. 
199
	 *         This operation can be interrupted
200
	 */
201
	public Vectorization createVectorizeObject(RasterDataSource dataSource) throws RasterDriverException, InterruptedException;
202
	
203
	/**
204
	 * Gets an instance of the overview builder registered
205
	 * @return OverviewBuilder
206
	 */
207
	public OverviewBuilder createOverviewBuilder();
208
	
209
	/**
210
	 * Gets a new instance of a ColorInterpretation object
211
	 * @param A list of color interpretation strings
212
	 * @return
213
	 */
214
	public ColorInterpretation createColorInterpretation(String[] colorInterp);
182 215
}
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/process/vector/Vectorization.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.fmap.dal.coverage.process.vector;
23

  
24
/**
25
 * Este interfaz se usa para poder vectorizar una capa raster.<p>
26
 * 
27
 * La entrada es una capa raster, ya sea en un fichero, RasterDastaSource o un
28
 * RasterDataset.<p>
29
 * 
30
 * El uso de comunicacion con la libreria jpotrace es como funciona el comando
31
 * potrace, de hecho, se pueden a?adir mas opciones si potrace los admite por
32
 * linea de comandos.<p>
33
 * 
34
 * Una vez creada una instancia de Vectorization se definen todos los
35
 * parametros deseables o en caso de no definirlos se usaran los valores por
36
 * defecto y se invoca al metodo VectorizeBuffer()<p>
37
 * 
38
 * Este ultimo metodo, devuelve un array de doubles indicando si lo que se ha
39
 * devuelto son operaciones tipicas de shapes... MoveTo, LineTo, CurveTo, etc...<p>
40
 * 
41
 * En la primera posicion se devuelve el tama?o del array.<p>
42
 * 
43
 * @author Nacho Brodin (nachobrodin@gmail.com)
44
 */
45
public interface Vectorization {
46
	public final static int POLICY_BLACK          = 0;
47
	public final static int POLICY_WHITE          = 1;
48
	public final static int POLICY_RIGHT          = 2;
49
	public final static int POLICY_LEFT           = 3;
50
	public final static int POLICY_MINORITY       = 4;
51
	public final static int POLICY_MAJORITY       = 5;
52
	public final static int POLICY_RANDOM         = 6;
53
	
54
	/**
55
	 * Set the corner threshold parameter (default 1)
56
	 * @param value
57
	 */
58
	public void setCornerThreshold(double value);
59

  
60
	/**
61
	 * Quantize output to 1/unit pixels (default 10)
62
	 * @param value
63
	 */
64
	public void setOutputQuantization(int value);
65

  
66
	/**
67
	 * Suppress speckles of up to this size (default 2)
68
	 * @param value
69
	 */
70
	public void setDespeckle(int value);
71

  
72
	/**
73
	 * Set how to resolve ambiguities in path decomposition<p>
74
	 * 
75
	 * Use:<br><b>
76
	 * 	 POLICY_BLACK<br>
77
	 *   POLICY_LEFT<br>
78
	 *   POLICY_MAJORITY<br>
79
	 *   POLICY_MINORITY<br>
80
	 *   POLICY_RANDOM<br>
81
	 *   POLICY_RIGHT<br>
82
	 *   POLICY_WHITE</b>
83
	 *  
84
	 * @param value
85
	 */
86
	public void setPolicy(int value);
87
	
88
	/**
89
	 * Set the curve optimization tolerance (default 0.2)
90
	 * @param value
91
	 */
92
	public void setOptimizationTolerance(double value);
93

  
94
	/**
95
	 * Return if the curve optimization is enabled or disabled
96
	 * @param value
97
	 */
98
	public boolean isEnabledCurveOptimization();
99

  
100
	/**
101
	 * Enable/Disable the curve optimization (default enabled)
102
	 * @param value
103
	 */
104
	public void setEnabledCurveOptimization(boolean value);
105

  
106
	/**
107
	 * Hace el proeso de Vectorizacion de un Raster
108
	 * @return
109
	 * @throws PotraceException
110
	 */
111
	public double[] VectorizeBuffer();
112
}
0 113

  
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/.classpath
9 9
  <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
10 10
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.i18n/2.0-SNAPSHOT/org.gvsig.i18n-2.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.i18n/2.0-SNAPSHOT/org.gvsig.i18n-2.0-SNAPSHOT-sources.jar"/>
11 11
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.jgdal/2.0.1-SNAPSHOT/org.gvsig.jgdal-2.0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.jgdal/2.0.1-SNAPSHOT/org.gvsig.jgdal-2.0.1-SNAPSHOT-sources.jar"/>
12
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.jpotrace/2.0.0-SNAPSHOT/org.gvsig.jpotrace-2.0.0-SNAPSHOT.jar"/>
12 13
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.maven.base.tools/1.0.6-SNAPSHOT/org.gvsig.maven.base.tools-1.0.6-SNAPSHOT.jar"/>
13 14
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.projection/2.0-SNAPSHOT/org.gvsig.projection-2.0-SNAPSHOT-cresques-impl.jar"/>
14 15
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.projection/2.0-SNAPSHOT/org.gvsig.projection-2.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.projection/2.0-SNAPSHOT/org.gvsig.projection-2.0-SNAPSHOT-sources.jar"/>
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/test/java/org/gvsig/raster/impl/DefaultRasterServiceTest.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.raster.impl;
23

  
24
import org.gvsig.fmap.dal.coverage.RasterService;
25
import org.gvsig.raster.RasterServiceTest;
26

  
27
/**
28
 * {@link RasterService} API compatibility tests for the
29
 * {@link DefaultRasterService} implementation.
30
 * 
31
 * @author gvSIG Team
32
 * @version $Id$
33
 */
34
public class DefaultRasterServiceTest extends RasterServiceTest {
35

  
36
    // Nothing to add
37
}
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/test/java/org/gvsig/raster/impl/DefaultRasterManagerTest.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.raster.impl;
23

  
24
import org.gvsig.fmap.dal.coverage.RasterManager;
25
import org.gvsig.raster.RasterManagerTest;
26

  
27
/**
28
 * {@link RasterManager} API compatibility tests for the
29
 * {@link DefaultRasterManager} implementation.
30
 * 
31
 * @author gvSIG Team
32
 * @version $Id$
33
 */
34
public class DefaultRasterManagerTest extends RasterManagerTest {
35

  
36
    // Nothing to add
37
}
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/test/java/org/gvsig/raster/impl/TestTemplate.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.raster.impl;
23

  
24
import junit.framework.TestCase;
25
/**
26
 * 
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 */
29
public class TestTemplate extends TestCase {
30
	
31
	public void start() {
32
		this.setUp();
33
		this.testStack();
34
	}
35
	
36
	public void setUp() {
37
		System.err.println("TestHistogramSerializer running...");
38
		
39
	}
40
	
41
	public void testStack(){
42
		
43
	}
44
}
0 45

  
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/test/java/org/gvsig/raster/impl/BaseTestCase.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.raster.impl;
23

  
24
import java.awt.geom.Point2D;
25
import java.io.File;
26

  
27
import org.gvsig.fmap.dal.coverage.RasterLocator;
28
import org.gvsig.fmap.dal.coverage.RasterManager;
29
import org.gvsig.fmap.dal.coverage.buffer.Buffer;
30
import org.gvsig.fmap.dal.coverage.buffer.RasterDataSource;
31
import org.gvsig.fmap.dal.coverage.buffer.RasterQuery;
32
import org.gvsig.fmap.dal.coverage.dataset.ColorInterpretation;
33
import org.gvsig.fmap.dal.coverage.dataset.MultiRasterDataSet;
34
import org.gvsig.fmap.dal.coverage.exception.FileNotFoundInListException;
35
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
36
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
37
import org.gvsig.fmap.dal.coverage.exception.OperationNotSupportedException;
38
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
39
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase;
40
/**
41
 * Clase base para todos los tests. Contiene m?todos de uso com?n.
42
 * Los errores no se capturan. Se lanzan en una traza por consola.
43
 *
44
 * 07/05/2008
45
 * @author Nacho Brodin nachobrodin@gmail.com
46
 */
47
public abstract class BaseTestCase extends AbstractLibraryAutoInitTestCase {
48
	/**
49
	 * Directorio donde est?n las imagenes de pruebas
50
	 */
51
	protected String               baseDir       = "./test-images/";
52
	/**
53
	 * Directorio para la generaci?n de imagenes temporales en los tests
54
	 */
55
	protected String               tempDir       = "/tmp";
56

  
57
	protected RasterDataSource     dataset       = null;
58
	protected String               out           = null;
59
	protected long                 t1, t2;
60
	protected RasterManager        manager       = null;
61

  
62
	protected void doSetUp() throws Exception {
63
		//Implementation registry
64
		DefaultRasterLibrary lib = new DefaultRasterLibrary();		
65
		lib.initialize();
66
		lib.postInitialize();
67
		
68
		//Gets the manager
69
		manager = RasterLocator.getManager();
70
	}
71

  
72
	/**
73
	 * Resetea el contador de tiempo
74
	 */
75
	protected void resetTime() {
76
		t1 = System.currentTimeMillis();
77
	}
78

  
79
	/**
80
	 * Obtiene el tiempo transcurrido desde que se reseteo el tiempo
81
	 * @return
82
	 */
83
	protected double getTime() {
84
		t2 = System.currentTimeMillis();
85
		return ((t2 - t1) / 1000D);
86
	}
87

  
88
	/**
89
	 * Abre el dataset
90
	 * @param s
91
	 */
92
	protected RasterDataSource open(String s) {
93
		try {
94
			dataset = manager.open(null, s);
95
			return dataset;
96
		} catch (NotSupportedExtensionException e1) {
97
			e1.printStackTrace();
98
		} catch (RasterDriverException e1) {
99
			e1.printStackTrace();
100
		}
101
		return null;
102
	}
103

  
104
	/**
105
	 * Abre el dataset
106
	 * @param s
107
	 */
108
	protected RasterDataSource open(String[] s) {
109
		try {
110
			if(s == null)
111
				return null;
112
			for (int i = 0; i < s.length; i++)
113
				if(i == 0)
114
					dataset = manager.open(null, s[0]);
115
				else
116
					((MultiRasterDataSet)dataset).addDataset(new String[]{s[i]});
117
			return dataset;
118
		} catch (NotSupportedExtensionException e1) {
119
			e1.printStackTrace();
120
		} catch (RasterDriverException e1) {
121
			e1.printStackTrace();
122
		} catch (FileNotFoundInListException e2) {
123
			e2.printStackTrace();
124
		} catch (OperationNotSupportedException e) {
125
			e.printStackTrace();
126
		}
127
		return null;
128
	}
129

  
130
	/**
131
	 * Borra el RMF de un fichero raster
132
	 * @param file
133
	 */
134
	protected void deleteRMF(String file) {
135
		int last = file.lastIndexOf(".");
136
		if (last == -1)
137
			last = file.length();
138

  
139
		File fichero = new File(file.substring(0, last) + ".rmf");
140
		fichero.delete();
141
	}
142

  
143
	/**
144
	 * Obtiene un nombre aleatorio para fichero temporal
145
	 * @return
146
	 */
147
	public String getFileTemp() {
148
		out = tempDir + "/test-" + System.currentTimeMillis();
149
		return out;
150
	}
151

  
152
	/**
153
	 * Crea un objeto de interpretaci?n de color
154
	 * @param nBands
155
	 * @return
156
	 */
157
	protected ColorInterpretation getColorInterpretation(int nBands) {
158
		String[] ci = new String[nBands];
159
		if(nBands == 1)
160
			ci[0] = ColorInterpretation.GRAY_BAND;
161
		else
162
			for (int j = 0; j < ci.length; j++)
163
				switch (j) {
164
				case 0: ci[j] = ColorInterpretation.RED_BAND; break;
165
				case 1: ci[j] = ColorInterpretation.GREEN_BAND; break;
166
				case 2: ci[j] = ColorInterpretation.BLUE_BAND; break;
167
				default: ci[j] = ColorInterpretation.UNDEF_BAND; break;
168
				}
169
		return manager.createColorInterpretation(ci);
170
	}
171

  
172
	/**
173
	 * Compara un dataset completo (ds2) con una parte de otro dataset (ds1)
174
	 * @param ds1
175
	 * @param ds2
176
	 * @param coordsDs1 Coordenada x, y del dataset 1 a partir de la cual empieza la comparaci?n
177
	 * @param step Proporci?n de tama?o del dataset 2 con respecto al 1. Si el step es 2 quiere decir que el
178
	 * dataset 2 es el doble que el 1
179
	 * @param drawableBands
180
	 * @param dataType
181
	 */
182
	protected void compareDatasets(RasterDataSource ds1, RasterDataSource ds2, Point2D coordsDs1, int step, int[] drawableBands, int dataType) {
183
		RasterQuery query1 = manager.createQuery();
184
		query1.setDrawableBands(drawableBands);
185
		RasterQuery query2 = manager.createQuery();
186
		query2.setDrawableBands(drawableBands);
187
		try {
188
			query1.setAreaOfInterest((int)coordsDs1.getX(), (int)coordsDs1.getY(), (int)(ds2.getDataset().getWidth() / step), (int)(ds2.getDataset().getHeight() / step));
189
			Buffer buf1 = ds1.query(query1);
190
			query2.setAreaOfInterest();
191
			Buffer buf2 = ds2.query(query2);
192
			for (int band = 0; band < buf1.getBandCount(); band++)
193
				for (int row = 0; row < (buf2.getHeight() / step); row++)
194
					for (int col = 0; col < (buf2.getWidth() / step); col++)
195
						switch (dataType) {
196
						case Buffer.TYPE_BYTE: assertEquals(buf1.getElemByte(row, col, band), buf2.getElemByte(row * step, col * step, band)); break;
197
						case Buffer.TYPE_SHORT: assertEquals(buf1.getElemShort(row, col, band), buf2.getElemShort(row * step, col * step, band)); break;
198
						case Buffer.TYPE_INT: assertEquals(buf1.getElemInt(row, col, band), buf2.getElemInt(row * step, col * step, band)); break;
199
						case Buffer.TYPE_FLOAT: assertEquals((int)buf1.getElemFloat(row, col, band), (int)buf2.getElemFloat(row * step, col * step, band)); break;
200
						case Buffer.TYPE_DOUBLE: assertEquals((int)buf1.getElemDouble(row, col, band), (int)buf2.getElemDouble(row * step, col * step, band)); break;
201
						}
202
		} catch (RasterDriverException e) {
203
			e.printStackTrace();
204
		} catch (InvalidSetViewException e) {
205
			e.printStackTrace();
206
		} catch (InterruptedException e) {
207
			e.printStackTrace();
208
		}
209
	}
210

  
211
	/**
212
	 * Compara la banda de un dataset completo (ds2) con una parte de otro dataset (ds1)
213
	 * @param banda del dataset 1 que corresponde con el dataset 2
214
	 * @param ds1
215
	 * @param ds2
216
	 * @param coordsDs1 Coordenada x, y del dataset 1 a partir de la cual empieza la comparaci?n
217
	 * @param step Proporci?n de tama?o del dataset 2 con respecto al 1. Si el step es 2 quiere decir que el
218
	 * dataset 2 es el
219
	 * @param drawableBands
220
	 * @param dataType
221
	 */
222
	protected void compareDatasets(int band, RasterDataSource ds1, RasterDataSource ds2, Point2D coordsDs1, int step, int[] drawableBands, int dataType) {
223
		RasterQuery query1 = manager.createQuery();
224
		query1.setDrawableBands(drawableBands);
225
		RasterQuery query2 = manager.createQuery();
226
		query2.setDrawableBands(drawableBands);
227

  
228
		try {
229
			query1.setAreaOfInterest((int)coordsDs1.getX(), (int)coordsDs1.getY(), (int)(ds2.getDataset().getWidth() / step), (int)(ds2.getDataset().getHeight() / step));
230
			Buffer buf1 = ds1.query(query1);
231
			query2.setAreaOfInterest();
232
			Buffer buf2 = ds2.query(query2);
233
			for (int row = 0; row < buf2.getHeight(); row++)
234
				for (int col = 0; col < buf2.getWidth(); col++)
235
					switch (dataType) {
236
					case Buffer.TYPE_BYTE: assertEquals(buf1.getElemByte(row, col, band), buf2.getElemByte(row * step, col * step, 0)); break;
237
					case Buffer.TYPE_SHORT: assertEquals(buf1.getElemShort(row, col, band), buf2.getElemShort(row * step, col * step, 0)); break;
238
					case Buffer.TYPE_INT: assertEquals(buf1.getElemInt(row, col, band), buf2.getElemInt(row * step, col * step, 0)); break;
239
					case Buffer.TYPE_FLOAT: assertEquals((int)buf1.getElemFloat(row, col, band), (int)buf2.getElemFloat(row * step, col * step, 0)); break;
240
					case Buffer.TYPE_DOUBLE: assertEquals((int)buf1.getElemDouble(row, col, band), (int)buf2.getElemDouble(row * step, col * step, 0)); break;
241
					}
242
		} catch (RasterDriverException e) {
243
			e.printStackTrace();
244
		} catch (InvalidSetViewException e) {
245
			e.printStackTrace();
246
		} catch (InterruptedException e) {
247
			e.printStackTrace();
248
		}
249
	}
250

  
251
	/**
252
	 * Detiene la ejecuci?n del thread actual durante n milisegundos
253
	 * @param n Numero de milisegundos detenido
254
	 */
255
	protected void pause(int n) {
256
		try {
257
			Thread.sleep(n);
258
		} catch (InterruptedException e) {
259
			e.printStackTrace();
260
		}
261
	}
262
}
0 263

  
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/test/java/org/gvsig/raster/impl/buffer/TestBufferInterpolation.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.raster.impl.buffer;
23

  
24
import java.awt.geom.AffineTransform;
25
import java.io.File;
26
import java.io.IOException;
27

  
28
import junit.framework.TestCase;
29

  
30
import org.gvsig.fmap.dal.coverage.RasterLocator;
31
import org.gvsig.fmap.dal.coverage.RasterManager;
32
import org.gvsig.fmap.dal.coverage.buffer.Buffer;
33
import org.gvsig.fmap.dal.coverage.buffer.RasterDataSource;
34
import org.gvsig.fmap.dal.coverage.buffer.RasterQuery;
35
import org.gvsig.fmap.dal.coverage.dataset.DataServerWriter;
36
import org.gvsig.fmap.dal.coverage.dataset.RasterWriter;
37
import org.gvsig.fmap.dal.coverage.datastruct.Params;
38
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
39
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
40
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
41

  
42
/**
43
 * Test para probar las interpolaciones de un buffer de datos completo. El test crear? un 
44
 * buffer a partir de una imagen de 870x870 y aplicar? una reducci?n usando los m?todos
45
 * de interpolaci?n implementados. Despu?s comparar? el resultado con imagenes ya generadas
46
 * y correctas que se encuentran en el directorio de test-images. 
47
 * @author Nacho Brodin (nachobrodin@gmail.com)
48
 *
49
 */
50
public class TestBufferInterpolation extends TestCase {
51
	private String baseDir = "./test-images/";
52
	private String path = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg";
53
	private RasterDataSource       f              = null;	
54
	private RasterQuery            query          = null;
55
	protected Buffer               buf            = null;
56
	private RasterManager          manager        = null;
57
	private int size = 50;
58
	
59
	private String fileNeighbour1 = baseDir + "neighbour50x50.tif";
60
	private String fileBilinear1 = baseDir + "bilinear50x50.tif";
61
	private String fileInverseDistance1 = baseDir + "inverseDistance50x50.tif";
62
	private String fileBSpline1 = baseDir + "bspline50x50.tif";
63
	//private String fileBicubicSpline1 = baseDir + "bicubicspline50x50.tif";
64
	
65
	private String fileNeighbour = "/tmp/neighbour.tif";
66
	private String fileBilinear = "/tmp/bilinear.tif";
67
	private String fileInverseDistance = "/tmp/invdistance.tif";
68
	private String fileBSpline = "/tmp/bspline.tif";
69
	private String fileBicubicSpline = "/tmp/bicubicspline.tif";
70
	
71
	public void start() {
72
		this.setUp();
73
		this.testStack();
74
	}
75
	
76
	public void setUp() {
77
		System.err.println("TestBufferInterpolation running...");
78
		int[] drawableBands = {0, 1, 2};
79
		manager = RasterLocator.getManager();
80
		try {
81
			f = manager.open(null, path);
82
		} catch (NotSupportedExtensionException e) {
83
			return;
84
		} catch (RasterDriverException e) {
85
			return;
86
		}
87
		query = manager.createQuery();
88
		query.setDrawableBands(drawableBands);
89
		try {
90
			query.setAreaOfInterest(0, 0, f.getDataset().getWidth(), f.getDataset().getHeight());
91
			buf = f.query(query);
92
		} catch (InvalidSetViewException e1) {
93
			e1.printStackTrace();
94
		} catch (InterruptedException e) {
95
			e.printStackTrace();
96
		} catch (RasterDriverException e) {
97
			e.printStackTrace();
98
		}
99
		
100
		try {
101
			Buffer b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_NearestNeighbour);
102
			convertBufferToTif(fileNeighbour, f.getDataset().getAffineTransform(), b1);
103
			b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_Bilinear);
104
			convertBufferToTif(fileBilinear, f.getDataset().getAffineTransform(), b1);
105
			b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_InverseDistance);
106
			convertBufferToTif(fileInverseDistance, f.getDataset().getAffineTransform(), b1);
107
			b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_BSpline);
108
			convertBufferToTif(fileBSpline, f.getDataset().getAffineTransform(), b1);
109
			b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_BicubicSpline);
110
			convertBufferToTif(fileBicubicSpline, f.getDataset().getAffineTransform(), b1);
111
		} catch (IOException e) {
112
			e.printStackTrace();
113
		} catch (InterruptedException e) {
114
			e.printStackTrace();
115
		} catch (RasterDriverException e) {
116
			e.printStackTrace();
117
		}  
118
		
119
	}
120
	
121
	public void testStack(){
122
		compareResult(fileNeighbour, fileNeighbour1);
123
		compareResult(fileBilinear, fileBilinear1);
124
		compareResult(fileInverseDistance, fileInverseDistance1);
125
		compareResult(fileBSpline, fileBSpline1);
126
		//compareResult(fileBicubicSpline, fileBicubicSpline1);
127
		File file1 = new File(fileNeighbour);
128
		File file2 = new File(fileBilinear);
129
		File file3 = new File(fileInverseDistance);
130
		File file4 = new File(fileBSpline);
131
		//File file5 = new File(fileBicubicSpline);
132
		if(file1.exists())
133
			file1.delete();
134
		if(file2.exists())
135
			file2.delete();
136
		if(file3.exists())
137
			file3.delete();
138
		if(file4.exists())
139
			file4.delete();
140
		//if(file5.exists())
141
		//	file5.delete();
142
	}
143
	
144
	/**
145
	 * Compara dos ficheros raster
146
	 * @param f1
147
	 * @param f2
148
	 */
149
	private void compareResult(String f1, String f2) {
150
		int[] drawableBands = {0, 1, 2};
151
		RasterDataSource d1 = null;
152
		RasterDataSource d2 = null;
153
		try {
154
			d1 = manager.open(null, f1);
155
			d2 = manager.open(null, f2);
156
		} catch (NotSupportedExtensionException e) {
157
			e.printStackTrace();
158
			return;
159
		} catch (RasterDriverException e) {
160
			e.printStackTrace();
161
			return;
162
		}
163
		RasterQuery query = manager.createQuery();
164
		query.setDrawableBands(drawableBands);
165
		Buffer b1 = null;
166
		try {
167
			query.setAreaOfInterest(0, 0, d1.getDataset().getWidth(), d1.getDataset().getHeight());
168
			b1 = d1.query(query);
169
		} catch (InvalidSetViewException e) {
170
			e.printStackTrace();
171
		} catch (InterruptedException e) {
172
			e.printStackTrace();
173
		} catch (RasterDriverException e) {
174
			e.printStackTrace();
175
		}
176
		
177
		Buffer b2 = null;
178
		query.setDrawableBands(drawableBands);
179
		try {
180
			query.setAreaOfInterest(0, 0, d1.getDataset().getWidth(), d1.getDataset().getHeight());
181
			b2 = d2.query(query);
182
		} catch (InvalidSetViewException e) {
183
			e.printStackTrace();
184
		} catch (InterruptedException e) {
185
			e.printStackTrace();
186
		} catch (RasterDriverException e) {
187
			e.printStackTrace();
188
		}
189
		for (int k = 0; k < b1.getBandCount(); k++) {
190
			for (int i = 0; i < b1.getHeight(); i++) {
191
				for (int j = 0; j < b1.getWidth(); j++) {
192
					switch(b1.getDataType()) {
193
					case Buffer.TYPE_BYTE:
194
						assertEquals(b1.getElemByte(i, j, k), b2.getElemByte(i, j, k));
195
						break;
196
					case Buffer.TYPE_SHORT:
197
						assertEquals(b1.getElemShort(i, j, k), b2.getElemShort(i, j, k));
198
						break;
199
						
200
					case Buffer.TYPE_INT:
201
						assertEquals(b1.getElemInt(i, j, k), b2.getElemInt(i, j, k));
202
						break;
203
						
204
					case Buffer.TYPE_FLOAT:
205
						assertEquals((int)b1.getElemFloat(i, j, k), (int)b2.getElemFloat(i, j, k));
206
						break;
207
						
208
					case Buffer.TYPE_DOUBLE:
209
						assertEquals((int)b1.getElemDouble(i, j, k), (int)b2.getElemDouble(i, j, k));
210
						break;
211
					}
212
				}
213
			}
214
		}
215
	}
216
	
217
	/**
218
	 * Funci?n para pruebas.
219
	 * Convierte los ficheros generados por la funci?n cachear en ficheros tif para comprobar que est?n
220
	 * bien generados.
221
	 * @param grf
222
	 * @param pageBuffer
223
	 * @param pageLines
224
	 * @throws IOException
225
	 */
226
	private void convertBufferToTif(String fileName, AffineTransform at, Buffer buffer)throws IOException, InterruptedException, RasterDriverException {
227
		DataServerWriter dataWriter1 = new WriterBufferServer(buffer);
228
		RasterWriter grw = null;
229
		try {
230
			Params params = manager.createWriter(fileName).getParams();
231
			params.changeParamValue("blocksize", "7"); //posici?n 7 del array -> 512
232
			params.changeParamValue("tfw", "false");
233
			params.changeParamValue("interleave", new Integer(1));//posici?n 1 del array -> PIXEL
234
			grw = manager.createWriter(dataWriter1, 
235
											fileName,
236
											buffer.getBandCount(),
237
											at,
238
											buffer.getWidth(), 
239
											buffer.getHeight(), 
240
											buffer.getDataType(),
241
											params,
242
											null);
243
			
244
		} catch (NotSupportedExtensionException e) {
245
			throw new RasterDriverException("");
246
		}
247
		grw.dataWrite();
248
		grw.writeClose();
249
	}
250

  
251
}
0 252

  
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/test/java/org/gvsig/raster/impl/buffer/TDSDoubleAdjustToExtentGdal.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.raster.impl.buffer;
23

  
24
import junit.framework.TestCase;
25

  
26
import org.gvsig.fmap.dal.coverage.RasterLocator;
27
import org.gvsig.fmap.dal.coverage.RasterManager;
28
import org.gvsig.fmap.dal.coverage.buffer.Buffer;
29
import org.gvsig.fmap.dal.coverage.buffer.RasterDataSource;
30
import org.gvsig.fmap.dal.coverage.buffer.RasterQuery;
31
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
32
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
33
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
34

  
35
/**
36
 * Este test prueba el acceso a datos a traves de un DataSource sin resampleo
37
 * para un raster leido con Gdal con coordenadas pixel. 
38
 * 
39
 * Lee el raster completo y comprueba que los datos leidos sean correctos 
40
 * comparando los valores de las cuatro esquinas y algunos valores dentro de la imagen.
41
 * Despu?s hace selecciona un ?rea dentro de la imagen de 2x2 y compara que los valores
42
 * leidos sean correctos.
43
 * 
44
 * @author Nacho Brodin (nachobrodin@gmail.com)
45
 *
46
 */
47
public class TDSDoubleAdjustToExtentGdal extends TestCase{
48

  
49
	private String baseDir = "./test-images/";
50
	private String path = baseDir + "miniRaster25x24.tif";	
51
	private RasterDataSource       f              = null;	
52
	private RasterQuery            query          = null;
53
	protected Buffer               raster         = null;
54
	
55
	public void start(){
56
		this.setUp();
57
		this.testStack();
58
	}
59
	
60
	public void setUp() {
61
		System.err.println("TDSDoubleAdjustToExtentGdal running...");
62
		//System.out.println("TestDataSource (Real Coord) Adjust To Extent [Gdal] running...");
63
	}
64
	
65
	public void testStack(){
66
		int[] drawableBands = {0, 1, 2};
67
		RasterManager manager = RasterLocator.getManager();
68
		try {
69
			f = manager.open(null, path);
70
		} catch (NotSupportedExtensionException e) {
71
			return;
72
		} catch (RasterDriverException e) {
73
			return;
74
		}
75
		query = manager.createQuery();
76
		query.setDrawableBands(drawableBands);
77
		try {
78
			query.setAreaOfInterest(645817.0, 4923851.0, 40, 40);
79
			raster = f.query(query);
80
		} catch (RasterDriverException e) {
81
			e.printStackTrace();
82
		} catch (InvalidSetViewException e) {
83
			e.printStackTrace();
84
		} catch (InterruptedException e) {
85
			e.printStackTrace();
86
		}
87
		dataTest1();
88
		//print();
89
		
90
		try {
91
			query.setAreaOfInterest(645829.8, 4923840.4, 2, 2);
92
			raster = f.query(query);
93
		} catch (RasterDriverException e) {
94
			e.printStackTrace();
95
		} catch (InvalidSetViewException e) {
96
			e.printStackTrace();
97
		} catch (InterruptedException e) {
98
			e.printStackTrace();
99
		}
100
		dataTest2();
101
		//print();
102
	}
103
	
104
	private void dataTest2(){
105
		//Upper Left
106
		assertEquals((int)(raster.getElemByte(0, 0, 0) & 0xff), 64);
107
		assertEquals((int)(raster.getElemByte(0, 0, 1) & 0xff), 81);
108
		assertEquals((int)(raster.getElemByte(0, 0, 2) & 0xff), 39);
109
		//Upper Right
110
		assertEquals((int)(raster.getElemByte(0, 1, 0) & 0xff), 64);
111
		assertEquals((int)(raster.getElemByte(0, 1, 1) & 0xff), 81);
112
		assertEquals((int)(raster.getElemByte(0, 1, 2) & 0xff), 39);
113
		//Lower Left
114
		assertEquals((int)(raster.getElemByte(1, 0, 0) & 0xff), 64);
115
		assertEquals((int)(raster.getElemByte(1, 0, 1) & 0xff), 81);
116
		assertEquals((int)(raster.getElemByte(1, 0, 2) & 0xff), 39);
117
		//Lower Right
118
		assertEquals((int)(raster.getElemByte(1, 1, 0) & 0xff), 64);
119
		assertEquals((int)(raster.getElemByte(1, 1, 1) & 0xff), 81);
120
		assertEquals((int)(raster.getElemByte(1, 1, 2) & 0xff), 39);
121
	}
122
	
123
	private void dataTest1(){
124
		//Upper Left
125
		assertEquals((int)(raster.getElemByte(0, 0, 0) & 0xff), 14);
126
		assertEquals((int)(raster.getElemByte(0, 0, 1) & 0xff), 14);
127
		assertEquals((int)(raster.getElemByte(0, 0, 2) & 0xff), 0);
128
		//Upper Right
129
		assertEquals((int)(raster.getElemByte(0, 24, 0) & 0xff), 68);
130
		assertEquals((int)(raster.getElemByte(0, 24, 1) & 0xff), 90);
131
		assertEquals((int)(raster.getElemByte(0, 24, 2) & 0xff), 52);
132
		//Lower Left
133
		assertEquals((int)(raster.getElemByte(23, 0, 0) & 0xff), 129);
134
		assertEquals((int)(raster.getElemByte(23, 0, 1) & 0xff), 122);
135
		assertEquals((int)(raster.getElemByte(23, 0, 2) & 0xff), 106);
136
		//Lower Right
137
		assertEquals((int)(raster.getElemByte(23, 24, 0) & 0xff), 145);
138
		assertEquals((int)(raster.getElemByte(23, 24, 1) & 0xff), 140);
139
		assertEquals((int)(raster.getElemByte(23, 24, 2) & 0xff), 134);
140
		
141
		assertEquals((int)(raster.getElemByte(6, 6, 0) & 0xff), 21);
142
		assertEquals((int)(raster.getElemByte(6, 6, 1) & 0xff), 37);
143
		assertEquals((int)(raster.getElemByte(6, 6, 2) & 0xff), 10);
144
		
145
		assertEquals((int)(raster.getElemByte(6, 23, 0) & 0xff), 91);
146
		assertEquals((int)(raster.getElemByte(6, 23, 1) & 0xff), 105);
147
		assertEquals((int)(raster.getElemByte(6, 23, 2) & 0xff), 92);
148
		
149
		assertEquals((int)(raster.getElemByte(23, 6, 0) & 0xff), 153);
150
		assertEquals((int)(raster.getElemByte(23, 6, 1) & 0xff), 133);
151
		assertEquals((int)(raster.getElemByte(23, 6, 2) & 0xff), 122);
152
		
153
		assertEquals((int)(raster.getElemByte(9, 14, 0) & 0xff), 63);
154
		assertEquals((int)(raster.getElemByte(9, 14, 1) & 0xff), 69);
155
		assertEquals((int)(raster.getElemByte(9, 14, 2) & 0xff), 55);
156
		
157
		assertEquals((int)(raster.getElemByte(6, 13, 0) & 0xff), 70);
158
		assertEquals((int)(raster.getElemByte(6, 13, 1) & 0xff), 78);
159
		assertEquals((int)(raster.getElemByte(6, 13, 2) & 0xff), 55);
160
	}
161
	
162
	/**
163
	 * Imprime todos los pixels de la fuente de datos en RGB
164
	 */
165
	/*private void print(){
166
		IBuffer raster = ds.getRasterBuf();
167
		for(int line = 0; line < raster.getHeight(); line++){
168
			for(int col = 0; col < raster.getWidth(); col++)
169
				System.out.print("(" + (int)(raster.getElemByte(line, col, 0) & 0xff) + " " + (int)(raster.getElemByte(line, col, 1) & 0xff) + " " + (int)(raster.getElemByte(line, col, 2) & 0xff) + ")");
170
			System.out.println();
171
		}
172
	}*/
173

  
174
}
0 175

  
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/test/java/org/gvsig/raster/impl/buffer/TDSDoubleAdjustToExtentBufferEcw.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.raster.impl.buffer;
23

  
24
import org.gvsig.fmap.dal.coverage.buffer.Buffer;
25
import org.gvsig.fmap.dal.coverage.buffer.RasterDataSource;
26
import org.gvsig.fmap.dal.coverage.buffer.RasterQuery;
27
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
28
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
29
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
30
import org.gvsig.raster.impl.BaseTestCase;
31
/**
32
 * Este test prueba el acceso a datos a traves de un DataSource sin resampleo
33
 * para un ECW con coordenadas reales.
34
 *
35
 * Lee el raster completo y comprueba que los datos leidos sean correctos
36
 * comparando los valores de las cuatro esquinas y algunos valores dentro de la imagen.
37
 * Se lee un ?rea m?s grande que el extent completo del raster para comprobar que el ajuste
38
 * al extent lo hace correctamente.
39
 *
40
 * Despu?s hace selecciona un ?rea dentro de la imagen de 2x2 y compara que los valores
41
 * leidos sean correctos.
42
 *
43
 * @author Nacho Brodin (nachobrodin@gmail.com)
44
 */
45
public class TDSDoubleAdjustToExtentBufferEcw extends BaseTestCase {
46
	private String        baseDir = "./test-images/";
47
	private String        path    = baseDir + "miniraster30x30.jp2";
48

  
49
	public void start() throws Exception {
50
		this.setUp();
51
		this.testStack();
52
	}
53

  
54
	protected void doSetUp() throws Exception {
55
		super.doSetUp();
56
		System.err.println("TDSDoubleAdjustToExtentBufferEcw running...");
57
	}
58

  
59
	public void testStack() {
60
		RasterDataSource f;
61
		int[] drawableBands = { 0, 1, 2 };
62
		try {
63
			deleteRMF(path);
64
			f = manager.open(null, path);
65
		} catch (RasterDriverException e) {
66
			return;
67
		} catch (NotSupportedExtensionException e) {
68
			return;
69
		}
70
		RasterQuery query = manager.createQuery();
71
		query.setDrawableBands(drawableBands);
72
		Buffer buf = null;
73
		//Se selecciona un ?rea mayor que el extent para probar que lo ajusta a este
74
		try {
75
			query.setAreaOfInterest(645860.0, 4923870.0, 645986.0, 4923744.0, 10, 10);
76
			buf = f.query(query);
77
		} catch (RasterDriverException e) {
78
			e.printStackTrace();
79
		} catch (InvalidSetViewException e) {
80
			e.printStackTrace();
81
		} catch (InterruptedException e) {
82
			e.printStackTrace();
83
		}
84
//		print(ds.getRasterBuf());
85
		dataTest1(buf);
86

  
87
		try {
88
			query.setAreaOfInterest(645860.0, 4923870.0, 645986.0, 4923744.0, 2, 2);
89
			buf = f.query(query);
90
		} catch (RasterDriverException e) {
91
			e.printStackTrace();
92
		} catch (InvalidSetViewException e) {
93
			e.printStackTrace();
94
		} catch (InterruptedException e) {
95
			e.printStackTrace();
96
		}
97
//		print(ds.getRasterBuf());
98
		dataTest2(buf);
99
	}
100

  
101
	private void dataTest1(Buffer raster) {
102
		int band0[] = { 43, 14, 87, 166, 174, 109, 90, 93, 190, 143, 85, 93, 103, 112, 138, 94, 138, 192, 180, 196, 99, 209, 41, 98, 168, 170, 89, 141, 158, 199, 108, 71, 67, 92, 131, 176, 243, 98, 163, 141, 157, 170, 94, 159, 233, 114, 144, 62, 147, 173, 159, 173, 184, 94, 56, 18, 69, 78, 83, 115, 95, 37, 80, 57, 68, 68, 55, 59, 58, 101, 69, 44, 24, 58, 115, 40, 58, 56, 68, 111, 84, 117, 55, 88, 170, 135, 169, 99, 74, 42, 114, 223, 171, 67, 216, 104, 167, 83, 66, 45 };
103
		int band1[] = { 53, 15, 109, 154, 164, 111, 109, 93, 189, 151, 89, 102, 107, 111, 142, 100, 143, 195, 178, 190, 100, 192, 61, 108, 154, 172, 99, 149, 160, 206, 122, 74, 81, 94, 136, 195, 248, 105, 173, 141, 158, 162, 98, 158, 226, 114, 132, 66, 150, 176, 168, 172, 175, 105, 82, 39, 85, 89, 73, 104, 92, 51, 80, 71, 88, 84, 71, 74, 68, 106, 82, 62, 37, 74, 129, 49, 78, 67, 89, 126, 100, 132, 71, 107, 164, 145, 154, 108, 85, 48, 130, 210, 164, 66, 209, 115, 160, 85, 90, 61 };
104
		int band2[] = { 26, 11, 82, 145, 165, 97, 86, 71, 191, 135, 74, 75, 85, 110, 117, 82, 115, 186, 179, 183, 91, 181, 43, 85, 139, 178, 78, 133, 152, 206, 98, 61, 71, 109, 118, 181, 244, 82, 144, 117, 144, 159, 83, 155, 231, 98, 108, 60, 136, 163, 146, 170, 162, 111, 102, 41, 62, 60, 64, 68, 97, 26, 74, 50, 64, 70, 47, 48, 56, 70, 54, 35, 19, 50, 91, 35, 48, 52, 62, 101, 73, 91, 35, 80, 140, 119, 140, 91, 58, 36, 112, 202, 146, 66, 192, 81, 131, 71, 63, 37 };
105
		compareRaster(raster, band0, band1, band2);
106
	}
107

  
108
	private void dataTest2(Buffer raster) {
109
		int band0[] = { 43, 109, 160, 18 };
110
		int band1[] = { 53, 111, 168, 39 };
111
		int band2[] = { 26, 97, 146, 41 };
112
		compareRaster(raster, band0, band1, band2);
113
	}
114

  
115
	public void compareRaster(Buffer raster, int band0[], int band1[], int band2[]) {
116
		int cont = 0;
117
		for (int line = 0; line < raster.getHeight(); line++)
118
			for (int col = 0; col < raster.getWidth(); col++) {
119
				assertEquals((raster.getElemByte(line, col, 0) & 0xff), band0[cont]);
120
				assertEquals((raster.getElemByte(line, col, 1) & 0xff), band1[cont]);
121
				assertEquals((raster.getElemByte(line, col, 2) & 0xff), band2[cont]);
122
				cont++;
123
			}
124
	}
125

  
126
	/**
127
	 * Imprime todos los pixels de la fuente de datos en RGB
128
	 */
129
	public void print(Buffer raster) {
130
		System.out.println("");
131
		for (int band = 0; band < 3; band++) {
132
			System.out.print("int band" + band + "[] = { ");
133
			int cont = 0;
134
			for (int line = 0; line < raster.getHeight(); line++)
135
				for (int col = 0; col < raster.getWidth(); col++) {
136
					if (cont != 0)
137
						System.out.print(", ");
138
					System.out.print(((raster.getElemByte(line, col, band) & 0xff)));
139
					cont++;
140
				}
141
			System.out.println("};");
142
		}
143
	}
144
}
0 145

  
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/test/java/org/gvsig/raster/impl/buffer/TDSDoubleAdjustToExtentBufferMrSID.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.raster.impl.buffer;
0 23

  
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/test/java/org/gvsig/raster/impl/buffer/TDSIntBufferGdal.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.raster.impl.buffer;
23

  
24
import junit.framework.TestCase;
25

  
26
import org.gvsig.fmap.dal.coverage.RasterLocator;
27
import org.gvsig.fmap.dal.coverage.RasterManager;
28
import org.gvsig.fmap.dal.coverage.buffer.Buffer;
29
import org.gvsig.fmap.dal.coverage.buffer.RasterDataSource;
30
import org.gvsig.fmap.dal.coverage.buffer.RasterQuery;
31
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
32
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
33
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
34

  
35
/**
36
 * Este test prueba el acceso a datos a traves de un DataSource con resampleo
37
 * para un raster leido con Gdal con coordenadas pixel. 
38
 * 
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff