Revision 2068

View differences:

org.gvsig.raster/tags/tagdate_29082013_14_01/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.algorithm.RasterBaseAlgorithmLibrary
org.gvsig.raster/tags/tagdate_29082013_14_01/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/RasterBaseAlgorithmLibrary.java
1
/*
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2012 gvSIG Association.
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
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.raster.algorithm;
25

  
26
import org.gvsig.i18n.Messages;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.extensionpoint.ExtensionPoint;
29
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
30
import org.gvsig.tools.library.AbstractLibrary;
31
import org.gvsig.tools.library.LibraryException;
32

  
33
/**
34
 * Initialization of RasterBaseAlgorithmLibrary library.
35
 * 
36
 * @author <a href="mailto:nachobrodin@gmail.com">Nacho Brodin</a>
37
 */
38
public class RasterBaseAlgorithmLibrary extends AbstractLibrary {
39
	public static final String         REGISTER_PROCESS_LABEL             = "RasterProcess";
40
	public static final String         REGISTER_INPUT_PARAMETERS_LABEL    = "RasterProcessInputParameters";
41
	public static final String         REGISTER_OUTPUT_PARAMETERS_LABEL   = "RasterProcessOutputParameters";
42
	
43
	/**
44
	 * Registers a raster process
45
	 */
46
	@SuppressWarnings("unchecked")
47
	public static void register(String processLabel, Class process) {
48
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
49
		ExtensionPoint point = extensionPoints.add(REGISTER_PROCESS_LABEL);
50
		point.append(processLabel, "", process);
51
	}
52
	
53
	/**
54
	 *  Registers input parameters of a raster process
55
	 */
56
	@SuppressWarnings("unchecked")
57
	public static String registerInputParameter(String parameterLabel, Class parameterClass) {
58
		return registerParameter(parameterLabel, parameterClass, REGISTER_INPUT_PARAMETERS_LABEL);
59
	}
60
	
61
	/**
62
	 *  Registers output parameters of a raster process
63
	 */
64
	@SuppressWarnings("unchecked")
65
	public static String registerOutputParameter(String parameterLabel, Class parameterClass) {
66
		return registerParameter(parameterLabel, parameterClass, REGISTER_OUTPUT_PARAMETERS_LABEL);
67
	}
68
	
69
	/**
70
	 * Registers a raster process
71
	 */
72
	@SuppressWarnings("unchecked")
73
	private static String registerParameter(String parameterLabel, Class parameterClass, String type) {
74
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
75
		ExtensionPoint point = extensionPoints.add(type);
76
		int i = 0;
77
		
78
		//Si no hay un par?metro registrado con ese nombre se registra
79
		if(point.get(parameterLabel) == null) {
80
			point.append(parameterLabel, "", parameterClass);
81
			return parameterLabel;
82
		} else {
83
			//Si hay un par?metro registrado con ese nombre pero los tipos son iguales no se hace nada
84
			if(point.get(parameterLabel).getExtension() == parameterClass)
85
				return parameterLabel;
86
			
87
			//Buscamos un nombre no registrado para el par?metro a?adiendo sufijos
88
			String newName = parameterLabel + "_" + i;
89
			while (point.get(newName) != null && point.get(newName).getExtension() != parameterClass) {
90
				i++;
91
				newName = parameterLabel + "_" + i;
92
			}
93
			point.append(parameterLabel + "_" + i, "", parameterClass);
94
		}
95
		return parameterLabel + "_" + i;
96
	}
97
	
98
    @Override
99
    protected void doInitialize() throws LibraryException {
100
        // Nothing to do
101
    }
102

  
103
    @Override
104
    protected void doPostInitialize() throws LibraryException {
105
        Messages.addResourceFamily(
106
            "org.gvsig.raster.tools.algorithm.base", 
107
            RasterBaseAlgorithmLibrary.class.getClassLoader(), 
108
            RasterBaseAlgorithmLibrary.class.getClass().getName());
109
        //registerGeoProcess(new RasterReprojectAlgorithmLibrary());
110
    }
111

  
112
    /**
113
     * Returns the instance of the manager
114
     * @return
115
     */
116
    public static RasterBaseAlgorithmManager getManager() {
117
    	return RasterBaseAlgorithmManager.getInstance();
118
    }
119
}
0 120

  
org.gvsig.raster/tags/tagdate_29082013_14_01/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/RasterBaseAlgorithmManager.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.algorithm;
23

  
24
import org.gvsig.fmap.dal.coverage.RasterManager;
25
import org.gvsig.raster.algorithm.process.ProcessException;
26
import org.gvsig.raster.algorithm.process.RasterProcess;
27
import org.gvsig.tools.ToolsLocator;
28
import org.gvsig.tools.extensionpoint.ExtensionPoint;
29
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
30

  
31
/**
32
 * Default {@link RasterManager} implementation.
33
 * 
34
 * @author Nacho Brodin (nachobrodin@gmail.com)
35
 * @version $Id$
36
 */
37
public class RasterBaseAlgorithmManager {
38
	private static RasterBaseAlgorithmManager internalInstance  = new RasterBaseAlgorithmManager();
39
	   
40
	/**
41
	 * Gets an instance of this object for internal use.
42
	 * @return DefaultRasterManager
43
	 */
44
	public static RasterBaseAlgorithmManager getInstance() {
45
		return internalInstance;
46
	}
47
	
48
	/**
49
	 * Returns a new instance of a process.
50
	 * @param processLabel
51
	 *        Label to identify the process
52
	 * @return
53
	 */
54
	public RasterProcess createRasterTask(String processLabel) throws ProcessException {
55
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
56
		ExtensionPoint point = extensionPoints.add(RasterBaseAlgorithmLibrary.REGISTER_PROCESS_LABEL);
57
		try {
58
			return (RasterProcess)point.create(processLabel);
59
		} catch (InstantiationException e) {
60
			throw new ProcessException("", e);
61
		} catch (IllegalAccessException e) {
62
			throw new ProcessException("", e);
63
		}
64
	}
65

  
66
}
0 67

  
org.gvsig.raster/tags/tagdate_29082013_14_01/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/util/Operation.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.algorithm.util;
23

  
24
/**
25
 * Interface for operations
26
 * @author Nacho Brodin nachobrodin@gmail.com
27
 */
28
public interface Operation {
29
	public boolean compare(double a, double b);
30
	
31
	public void invoke();
32
}
0 33

  
org.gvsig.raster/tags/tagdate_29082013_14_01/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/util/AbstractOperation.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.algorithm.util;
23

  
24
/**
25
 * Interface for operations
26
 * @author Nacho Brodin nachobrodin@gmail.com
27
 */
28
public abstract class AbstractOperation implements Operation {
29
	public boolean compare(double a, double b) {
30
		return false;
31
	}
32
	
33
	public void invoke() {
34
		//do nothing
35
	}
36
}
0 37

  
org.gvsig.raster/tags/tagdate_29082013_14_01/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/util/Interpolation.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.algorithm.util;
23

  
24
import org.gvsig.fmap.dal.coverage.RasterLocator;
25
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
26
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
27

  
28
/**
29
 * Calculates a pixel value using a interpolation method
30
 * @author Nacho Brodin nachobrodin@gmail.com
31
 * @author Victor Olaya
32
 */
33
public class Interpolation {
34
	private Buffer        buffer    = null;
35
	private double        nodata    = 0;
36
	
37
	public Interpolation(Buffer buf) {
38
		this.buffer = buf;
39
		NoData nodata = RasterLocator.getManager().getDataStructFactory().createDefaultNoData(
40
				1, Buffer.TYPE_DOUBLE);
41
		this.nodata = nodata.getValue().doubleValue();
42
	}
43
	
44
	private double[] getKernel(int x, int y, int band) {
45
		if(buffer.getDataType() == Buffer.TYPE_BYTE) {
46
			return getKernelByte(x, y, band);
47
		}
48
		if(buffer.getDataType() == Buffer.TYPE_DOUBLE) {
49
			return getKernelByte(x, y, band);
50
		}
51
		if(buffer.getDataType() == Buffer.TYPE_FLOAT) {
52
			return getKernelByte(x, y, band);
53
		}
54
		if(buffer.getDataType() == Buffer.TYPE_SHORT) {
55
			return getKernelByte(x, y, band);
56
		}
57
		if(buffer.getDataType() == Buffer.TYPE_INT) {
58
			return getKernelByte(x, y, band);
59
		}
60
		return null;
61
	}
62

  
63
	public double getNearestNeighbour(double x, double y, int band) {
64
		int dy = (int)Math.round(y);
65
		int dx = (int)Math.round(x);
66
		dy = dy < buffer.getHeight() ? dy : buffer.getHeight() - 1;
67
		dx = dx < buffer.getWidth() ? dx : buffer.getWidth() - 1;
68
		if(buffer.getDataType() == Buffer.TYPE_BYTE) {
69
			return (double)buffer.getElemByte(dy, dx, band);
70
		}
71
		if(buffer.getDataType() == Buffer.TYPE_DOUBLE) {
72
			return (double)buffer.getElemDouble(dy, dx, band);
73
		}
74
		if(buffer.getDataType() == Buffer.TYPE_FLOAT) {
75
			return (double)buffer.getElemFloat(dy, dx, band);
76
		}
77
		if(buffer.getDataType() == Buffer.TYPE_SHORT) {
78
			return (double)buffer.getElemShort(dy, dx, band);
79
		}
80
		if(buffer.getDataType() == Buffer.TYPE_INT) {
81
			return (double)buffer.getElemInt(dy, dx, band);
82
		}
83
		return nodata;
84
	}
85

  
86
	/**
87
	 * Calcula los valores N y Z para el m?todo bilinear y obtiene el valor del pixel como
88
	 * Z / N
89
	 * @param dx distancia en X desde el centro del pixel hasta el punto. Es un valor entre 0 y 1
90
	 * @param dy distancia en Y desde el centro del pixel hasta el punto. Es un valor entre 0 y 1
91
	 * @param kernel valor del pixel y alrededor 
92
	 * @return valor del pixel
93
	 */
94
	public double getBilinearValue(double x, double y, int band) {
95
		double[] kernel = getKernel((int)x, (int)y, band);
96
		double dx = x - ((int) x);
97
		double dy = y - ((int) y);
98
		
99
		double z = 0.0, n = 0.0, d;
100
		d = (1.0 - dx) * (1.0 - dy);
101
		z += d * kernel[0];
102
		n += d;
103

  
104
		d = dx * (1.0 - dy);
105
		z += d * kernel[1]; 
106
		n += d;
107

  
108
		d = (1.0 - dx) * dy;
109
		z += d * kernel[2]; 
110
		n += d;
111

  
112
		d = dx * dy;
113
		z += d * kernel[3]; 
114
		n += d;
115

  
116
		double b = 0;
117
		if(n > 0.0)
118
			b = (z / n);
119
		return b;
120
	}
121
	
122
	/**
123
	 * Calcula los valores N y Z para el m?todo de distancia inversa y calcula el valor del
124
	 * pixel como Z / N.
125
	 * @param dx distancia en X desde el centro del pixel hasta el punto. Es un valor entre 0 y 1
126
	 * @param dy distancia en Y desde el centro del pixel hasta el punto. Es un valor entre 0 y 1
127
	 * @param kernel valor del pixel y alrededor 
128
	 * @return valor del pixel
129
	 */
130
	public double getInverseDistance(double x, double y, int band) {
131
		double[] kernel = getKernel((int)x, (int)y, band);
132
		double dx = x - ((int) x);
133
		double dy = y - ((int) y);
134
		
135
		double z = 0.0, n = 0.0, d;
136
		d = 1.0 / Math.sqrt(dx * dx + dy * dy);
137
		z += d * kernel[0];
138
		n += d;
139

  
140
		d = 1.0 / Math.sqrt((1.0 - dx) * ( 1.0 - dx) + dy * dy);
141
		z += d * kernel[1]; 
142
		n += d;
143

  
144
		d = 1.0 / Math.sqrt(dx*dx + (1.0-dy)*(1.0-dy));
145
		z += d * kernel[2]; 
146
		n += d;
147

  
148
		d = 1.0 / Math.sqrt((1.0 - dx) *( 1.0 - dx) + (1.0 - dy) * (1.0 - dy));
149
		z += d * kernel[3]; 
150
		n += d;
151

  
152
		double b = 0;
153
		if(n > 0.0)
154
			b = (z / n);
155
		return b;
156
	}
157
	
158
	/**
159
	 * Obtiene un kernel de cuatro elemento que corresponden a los pixeles (x, y), (x + 1, y),
160
	 * (x, y + 1), (x + 1, y + 1). Si los pixeles x + 1 o y + 1 se salen del raster de origen
161
	 * se tomar? x e y. 
162
	 * @param x Coordenada X del pixel inicial
163
	 * @param y Coordenada Y del pixel inicial
164
	 * @param band N?mero de banda.
165
	 * @return Kernel solicitado en forma de array.
166
	 */
167
	private double[] getKernelByte(int x, int y, int band) {
168
		double[] d = new double[4];
169
		d[0] = (buffer.getElemByte(y, x, band) & 0xff);
170
		int nextX = ((x + 1) >= buffer.getWidth()) ? x : (x + 1);
171
		int nextY = ((y + 1) >= buffer.getHeight()) ? y : (y + 1);
172
		d[1] = (buffer.getElemByte(y, nextX, band) & 0xff);
173
		d[2] = (buffer.getElemByte(nextY, x, band) & 0xff);
174
		d[3] = (buffer.getElemByte(nextY, nextX, band) & 0xff);
175
		return d;
176
	}
177

  
178
	/**
179
	 * Obtiene un kernel de cuatro elemento que corresponden a los pixeles (x, y), (x + 1, y),
180
	 * (x, y + 1), (x + 1, y + 1). Si los pixeles x + 1 o y + 1 se salen del raster de origen
181
	 * se tomar? x e y. 
182
	 * @param x Coordenada X del pixel inicial
183
	 * @param y Coordenada Y del pixel inicial
184
	 * @param band N?mero de banda.
185
	 * @return Kernel solicitado en forma de array.
186
	 */
187
	@SuppressWarnings("unused")
188
	private double[] getKernelShort(int x, int y, int band) {
189
		double[] d = new double[4];
190
		d[0] = (buffer.getElemShort(y, x, band) & 0xffff);
191
		int nextX = ((x + 1) >= buffer.getWidth()) ? x : (x + 1);
192
		int nextY = ((y + 1) >= buffer.getHeight()) ? y : (y + 1);
193
		d[1] = (buffer.getElemShort(y, nextX, band) & 0xffff);
194
		d[2] = (buffer.getElemShort(nextY, x, band) & 0xffff);
195
		d[3] = (buffer.getElemShort(nextY, nextX, band) & 0xffff);
196
		return d;
197
	}
198

  
199
	/**
200
	 * Obtiene un kernel de cuatro elemento que corresponden a los pixeles (x, y), (x + 1, y),
201
	 * (x, y + 1), (x + 1, y + 1). Si los pixeles x + 1 o y + 1 se salen del raster de origen
202
	 * se tomar? x e y. 
203
	 * @param x Coordenada X del pixel inicial
204
	 * @param y Coordenada Y del pixel inicial
205
	 * @param band N?mero de banda.
206
	 * @return Kernel solicitado en forma de array.
207
	 */
208
	@SuppressWarnings("unused")
209
	private double[] getKernelInt(int x, int y, int band) {
210
		double[] d = new double[4];
211
		d[0] = (buffer.getElemInt(y, x, band) & 0xffffffff);
212
		int nextX = ((x + 1) >= buffer.getWidth()) ? x : (x + 1);
213
		int nextY = ((y + 1) >= buffer.getHeight()) ? y : (y + 1);
214
		d[1] = (buffer.getElemInt(y, nextX, band) & 0xffffffff);
215
		d[2] = (buffer.getElemInt(nextY, x, band) & 0xffffffff);
216
		d[3] = (buffer.getElemInt(nextY, nextX, band) & 0xffffffff);
217
		return d;
218
	}
219

  
220
	/**
221
	 * Obtiene un kernel de cuatro elemento que corresponden a los pixeles (x, y), (x + 1, y),
222
	 * (x, y + 1), (x + 1, y + 1). Si los pixeles x + 1 o y + 1 se salen del raster de origen
223
	 * se tomar? x e y. 
224
	 * @param x Coordenada X del pixel inicial
225
	 * @param y Coordenada Y del pixel inicial
226
	 * @param band N?mero de banda.
227
	 * @return Kernel solicitado en forma de array.
228
	 */
229
	@SuppressWarnings("unused")
230
	private double[] getKernelFloat(int x, int y, int band) {
231
		double[] d = new double[4];
232
		d[0] = buffer.getElemFloat(y, x, band);
233
		int nextX = ((x + 1) >= buffer.getWidth()) ? x : (x + 1);
234
		int nextY = ((y + 1) >= buffer.getHeight()) ? y : (y + 1);
235
		d[1] = buffer.getElemFloat(y, nextX, band);
236
		d[2] = buffer.getElemFloat(nextY, x, band);
237
		d[3] = buffer.getElemFloat(nextY, nextX, band);
238
		return d;
239
	}
240

  
241
	/**
242
	 * Obtiene un kernel de cuatro elemento que corresponden a los pixeles (x, y), (x + 1, y),
243
	 * (x, y + 1), (x + 1, y + 1). Si los pixeles x + 1 o y + 1 se salen del raster de origen
244
	 * se tomar? x e y. 
245
	 * @param x Coordenada X del pixel inicial
246
	 * @param y Coordenada Y del pixel inicial
247
	 * @param band N?mero de banda.
248
	 * @return Kernel solicitado en forma de array.
249
	 */
250
	@SuppressWarnings("unused")
251
	private double[] getKernelDouble(int x, int y, int band) {
252
		double[] d = new double[4];
253
		d[0] = buffer.getElemDouble(y, x, band);
254
		int nextX = ((x + 1) >= buffer.getWidth()) ? x : (x + 1);
255
		int nextY = ((y + 1) >= buffer.getHeight()) ? y : (y + 1);
256
		d[1] = buffer.getElemDouble(y, nextX, band);
257
		d[2] = buffer.getElemDouble(nextY, x, band);
258
		d[3] = buffer.getElemDouble(nextY, nextX, band);
259
		return d;
260
	}
261
}
0 262

  
org.gvsig.raster/tags/tagdate_29082013_14_01/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/process/IProcessActions.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.algorithm.process;
23

  
24
/**
25
 * Acciones que puede ejecutar un proceso sobre un objeto externo. Un proceso
26
 * debe ser independiente de objetos que sean dependientes de su funcionalidad. Es
27
 * decir, cualquier extensi?n debe poder usar un proceso y este ejecutar metodos
28
 * de la funcionalidad. Esto se hace ha trav?s de este interfaz.
29
 * 
30
 * @version 26/09/2007
31
 * @author Nacho Brodin (nachobrodin@gmail.com)
32
 *
33
 */
34
public interface IProcessActions {
35
	
36
	/**
37
	 * El proceso comunica que ha sido interrumpido
38
	 *
39
	 */
40
	public void interrupted();
41

  
42
	/**
43
	 * Acciones de finalizaci?n del proceso
44
	 */
45
	public void end(Object param);
46
}
0 47

  
org.gvsig.raster/tags/tagdate_29082013_14_01/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/process/ProcessException.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.algorithm.process;
23
/**
24
 * This exception is thrown when a problem inside a raster process
25
 * is detected. 
26
 * 
27
 * @author Nacho Brodin (nachobrodin@gmail.com)
28
 */
29
public class ProcessException extends Exception {
30
	private static final long serialVersionUID = 666908550965442025L;
31

  
32
	public ProcessException(String msg, Throwable e) {
33
		super(msg, e);
34
	}
35
	
36
	public ProcessException(String msg){
37
		super(msg);
38
	}
39
}
0 40

  
org.gvsig.raster/tags/tagdate_29082013_14_01/org.gvsig.raster/org.gvsig.raster.algorithm/src/main/java/org/gvsig/raster/algorithm/process/RasterProcess.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.algorithm.process;
23

  
24
import java.awt.Component;
25
import java.awt.geom.AffineTransform;
26
import java.awt.geom.Point2D;
27
import java.awt.geom.Rectangle2D;
28
import java.util.ArrayList;
29
import java.util.Hashtable;
30

  
31
import javax.swing.JOptionPane;
32

  
33
import org.gvsig.fmap.dal.coverage.RasterLocator;
34
import org.gvsig.fmap.dal.coverage.RasterManager;
35
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
36
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
37
import org.gvsig.fmap.dal.coverage.datastruct.Params;
38
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
39
import org.gvsig.fmap.dal.coverage.process.CancelEvent;
40
import org.gvsig.fmap.dal.coverage.process.TaskEventManager;
41
import org.gvsig.fmap.dal.coverage.store.DataServerWriter;
42
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
43
import org.gvsig.fmap.dal.coverage.store.RasterWriter;
44
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
45
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
46
import org.gvsig.gui.beans.incrementabletask.IIncrementable;
47
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent;
48
import org.gvsig.gui.beans.incrementabletask.IncrementableListener;
49
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
50
import org.gvsig.i18n.Messages;
51
import org.gvsig.tools.dispose.Disposable;
52
import org.slf4j.Logger;
53
import org.slf4j.LoggerFactory;
54
/**
55
 * Clase base de todos los procesos raster. En ella se genstionan todas las
56
 * funciones comunes como incremento de la tarea, gesti?n de eventos a la tarea, 
57
 * par?metros de la tarea, etc ...
58
 * 
59
 * 18/12/2007
60
 * @author Nacho Brodin nachobrodin@gmail.com
61
 */
62
public abstract class RasterProcess implements IIncrementable, IncrementableListener, Runnable, Disposable {
63
	protected IncrementableTask incrementableTask = null;
64
	protected volatile Thread   blinker           = null;
65
	protected TaskEventManager  taskEventManager  = null;
66
	protected IProcessActions   externalActions   = null;
67
	protected Hashtable<String, Object>
68
	                            taskParams        = new Hashtable<String, Object>();
69

  
70
	private String              log               = "";
71
	private String              lastLine          = "";
72
	private long                time              = 0;
73
	private boolean             progressActive    = true;
74
	private IProcessActions     queueActions      = null;
75
	private Logger              logger            = LoggerFactory.getLogger(RasterProcess.class.toString());
76
	protected int               percent           = 0;
77
	
78
	/**
79
	 * Crea la ventana de IncrementableTask
80
	 */
81
	public IncrementableTask getIncrementableTask() {
82
		if (incrementableTask == null) {
83
			incrementableTask = new IncrementableTask(this);
84
			incrementableTask.addIncrementableListener(this);
85
		}
86
		return incrementableTask;
87
	}
88
	
89
	/**
90
	 * Define si se puede cancelar el proceso. Por defecto es true.
91
	 * @param enabled
92
	 */
93
	public void setCancelable(boolean enabled) {
94
		getIncrementableTask().getButtonsPanel().setEnabled(ButtonsPanel.BUTTON_CANCEL, enabled);
95
	}
96
	
97
	/**
98
	 * Muestra la ventana de IncrementableTask
99
	 */
100
	public void showIncrementableWindow() {
101
		if (progressActive) {
102
			getIncrementableTask().showWindow();
103
			getIncrementableTask().start();
104
		}
105
	}
106

  
107
	/**
108
	 * Arranca el proceso de recorte de un layer
109
	 */
110
	public void start() {
111
		showIncrementableWindow();
112
		if(blinker == null)
113
			blinker = new Thread(this);
114
		blinker.start();
115
	}
116
		
117
	/**
118
	 * Proceso de carga de par?metros. Puede no hacerse una carga de par?metros 
119
	 * explicita y obtenerlos directamente de la tabla Hash cuando vayan a usarse. 
120
	 * Esto queda a elecci?n del programador. En caso de hacerse una carga de par?metros
121
	 * explicita esta llamada deber?a hacerse justo despues del constructor de la clase
122
	 * que contendr? el proceso.
123
	 */
124
	public abstract void init();
125
	
126
	/**
127
	 * Proceso
128
	 * @throws InterruptedException
129
	 */
130
	public abstract void process() throws ProcessInterruptedException, ProcessException;
131
	
132
	/**
133
	 * Obtenci?n de un objeto de resultado. Este objeto deber? ser el mismo que el que se
134
	 * pasa por par?metro en el "end" de IProcessActions. Este m?todo es util cuando la tarea no se
135
	 * lanza en un Thread (ejecutamos process directamente) y queremos recoger el resultado
136
	 * sin registrarnos al evento de finalizaci?n de tarea.
137
	 * @return objeto resultado de la tarea
138
	 */
139
	public Object getResult() {
140
		return null;
141
	}
142
	
143
	/**
144
	 * Proceso
145
	 * @throws ProcessException 
146
	 */
147
	public void execute() throws ProcessInterruptedException, ProcessException {
148
		init();
149
		process();
150
	}
151
	
152
	/**
153
	 * M?todo donde se ejecutar? el Thread. Este har? las acciones globales para 
154
	 * cualquier tarea y llamar? al m?todo execute especifico de una tarea.
155
	 */
156
	public void run() {
157
		long t1 = new java.util.Date().getTime();
158

  
159
		try {
160
			taskEventManager = RasterLocator.getManager().createRasterTask(this);
161
			execute();
162
		} catch (ProcessInterruptedException e) {
163
			if (externalActions != null)
164
				externalActions.interrupted();
165
			Thread.currentThread().interrupt();
166
		} catch (ProcessException e) {
167
			if (progressActive) {
168
				if (incrementableTask != null) {
169
					getIncrementableTask().processFinalize();
170
					incrementableTask = null;
171
				}
172
			}
173
			logger.warn(RasterLocator.getManager().getRasterUtils().getTrace(e));
174
			if(e.getMessage() != null && e.getMessage().compareTo("") != 0)
175
				messageBoxError(e.getMessage(), this);
176
			else
177
				messageBoxError("error_processing", this);
178
			queueActions = null;
179

  
180
		} catch (Exception e) {
181
			if (progressActive) {
182
				if (incrementableTask != null) {
183
					getIncrementableTask().processFinalize();
184
					incrementableTask = null;
185
				}
186
			}
187
			logger.warn(RasterLocator.getManager().getRasterUtils().getTrace(e));
188
			if(e.getMessage() != null && e.getMessage().compareTo("") != 0)
189
				messageBoxError(e.getMessage(), null);
190
			else
191
				messageBoxError("error_processing", null);
192
			queueActions = null;
193
		} finally {
194
			taskEventManager.removeTask();
195
			if (progressActive) {
196
				if (incrementableTask != null)
197
					getIncrementableTask().processFinalize();
198
			}
199
			if (queueActions != null)
200
				queueActions.end(this);
201
			time = new java.util.Date().getTime() - t1;
202
			blinker = null;
203
		}
204
	}
205
	
206
	/**
207
	 * Activa o desactiva el interfaz de progreso en el lanzamiento de la tarea como un thread.
208
	 * @param active true para activarlo o false para desactivarlo
209
	 */
210
	public void setProgressActive(boolean active) {
211
		this.progressActive = active;
212
	}
213
	
214
	/**
215
	 * Obtiene el tiempo que tard? en ejecutarse la tarea 
216
	 * la ?ltima vez que se proces?
217
	 */
218
	public long getTime() {
219
		return time;
220
	}
221
	
222
	/**
223
	 * Obtiene el objeto para ejecutar acciones externar.
224
	 * @param IProcessActions
225
	 */
226
	public IProcessActions getActions() {
227
		return externalActions;
228
	}
229

  
230
	/**
231
	 * Asigna el objeto para ejecutar acciones externar.
232
	 * @param IProcessActions
233
	 */
234
	public void setActions(IProcessActions actions) {
235
		this.externalActions = actions;
236
	}
237
	
238
	/**
239
	 * Obtiene el objeto para ejecutar acciones de la cola de procesos de ejecuci?n exclusiva.
240
	 * @param IProcessActions
241
	 */
242
	public IProcessActions getUniqueProcessActions() {
243
		return queueActions;
244
	}
245

  
246
	/**
247
	 * Asigna el objeto para ejecutar acciones externar.
248
	 * @param IProcessActions
249
	 */
250
	public void setUniqueProcessActions(IProcessActions actions) {
251
		this.queueActions = actions;
252
	}
253
	
254
	/**
255
	 * Inserta una nueva l?nea en el log del cuadro de incremento de tarea
256
	 * @param line
257
	 */
258
	protected void insertLineLog(String line) {
259
		lastLine = line;
260
		log = log + line + "\n";
261
	}
262
	
263
	/**
264
	 * Obtiene la ?ltima l?nea introducida en el log del cuadro de incremento.
265
	 */
266
	public String getLabel() {
267
		return lastLine;
268
	}
269
	
270
	/**
271
	 * Obtiene el texto de log del cuadro de incremento completo.
272
	 */
273
	public String getLog() {
274
		return log;
275
	}
276
	
277
	/**
278
	 * Un evento de cancelado es enviado a la tarea cuando actionCanceled es activado. Para
279
	 * ello se crear? un objeto CancelEvent y se asignar? a la tarea en ejecuci?n. Esta lo
280
	 * procesar? cuando pueda e interrumpir? el proceso.
281
	 */
282
	public void actionCanceled(IncrementableEvent e) {
283
		taskEventManager.setEvent(new CancelEvent(this));
284
	}
285
	
286
	/**
287
	 * A?ade un par?metro a la tarea
288
	 * @param name Clave del par?metro
289
	 * @param param Objeto pasado como par?metro
290
	 */
291
	public void addParam(String name, Object param) {
292
		if (param != null)
293
			taskParams.put(name, param);
294
		else
295
			taskParams.remove(name);
296
	}
297

  
298
	/**
299
	 * Elimina un par?metro de la tarea
300
	 * @param name Clave del par?metro a eliminar
301
	 */
302
	public void removeParam(String name) {
303
		taskParams.remove(name);
304
	}
305

  
306
	/**
307
	 * Obtiene un par?metro a partir de la clave
308
	 * @param name Par?metro
309
	 * @return Par?metro
310
	 */
311
	public Object getParam(String name) {
312
		return taskParams.get(name);
313
	}
314
	
315
	/**
316
	 * Obtiene un par?metro String a partir de la clave
317
	 * @param name Par?metro
318
	 * @return Par?metro
319
	 */
320
	public String getStringParam(String name) {
321
		Object value = taskParams.get(name);
322
		return (value != null && value instanceof String) ? (String)value : null;
323
	}
324
	
325
	/**
326
	 * Obtiene un par?metro byte a partir de la clave
327
	 * @param name Par?metro
328
	 * @return Par?metro
329
	 */
330
	public byte getByteParam(String name) {
331
		Object value = taskParams.get(name);
332
		return (value != null && value instanceof Byte) ? ((Byte)value).byteValue() : 0;
333
	}
334
	
335
	/**
336
	 * Obtiene un par?metro float a partir de la clave
337
	 * @param name Par?metro
338
	 * @return Par?metro
339
	 */
340
	public float getFloatParam(String name) {
341
		Object value = taskParams.get(name);
342
		return (value != null && value instanceof Float) ? ((Float)value).floatValue() : 0F;
343
	}
344
	
345
	/**
346
	 * Obtiene un par?metro double a partir de la clave
347
	 * @param name Par?metro
348
	 * @return Par?metro
349
	 */
350
	public double getDoubleParam(String name) {
351
		Object value = taskParams.get(name);
352
		return (value != null && value instanceof Double) ? ((Double)value).doubleValue() : 0D;
353
	}
354
	
355
	/**
356
	 * Obtiene un par?metro entero a partir de la clave
357
	 * @param name Par?metro
358
	 * @return Par?metro
359
	 */
360
	public int getIntParam(String name) {
361
		Object value = taskParams.get(name);
362
		return (value != null && value instanceof Integer) ? ((Integer)value).intValue() : 0;
363
	}
364
	
365
	/**
366
	 * Obtiene un par?metro boolean a partir de la clave
367
	 * @param name Par?metro
368
	 * @return Par?metro
369
	 */
370
	public boolean getBooleanParam(String name) {
371
		Object value = taskParams.get(name);
372
		return (value != null && value instanceof Boolean) ? ((Boolean)value).booleanValue() : false;
373
	}
374
	
375
	/**
376
	 * Obtiene un par?metro int[] a partir de la clave
377
	 * @param name Par?metro
378
	 * @return Par?metro
379
	 */
380
	public int[] getIntArrayParam(String name) {
381
		Object value = taskParams.get(name);
382
		return (value != null && value instanceof int[]) ? ((int[])value) : null;
383
	}
384
	
385
	/**
386
	 * Obtiene un par?metro double[] a partir de la clave
387
	 * @param name Par?metro
388
	 * @return Par?metro
389
	 */
390
	public double[] getDoubleArrayParam(String name) {
391
		Object value = taskParams.get(name);
392
		return (value != null && value instanceof double[]) ? ((double[])value) : null;
393
	}
394
	
395
	/**
396
	 * Obtiene un par?metro extent a partir de la clave
397
	 * @param name Par?metro
398
	 * @return Par?metro
399
	 */
400
	public Extent getExtentParam(String name) {
401
		Object value = taskParams.get(name);
402
		return (value != null && value instanceof Extent) ? ((Extent)value) : null;
403
	}
404
	
405
	/**
406
	 * Updates the percentaje of progress and manages the cancelation
407
	 * @param parcial
408
	 * @param total
409
	 * @throws ProcessInterruptedException
410
	 */
411
	public void updatePercent(int parcial, int total) throws ProcessInterruptedException {
412
		if (taskEventManager != null && taskEventManager.getEvent() != null)
413
			taskEventManager.manageEvent(taskEventManager.getEvent());
414
		percent = (int)((parcial * 100) / total);
415
	}
416
	
417
	/*
418
	 * (non-Javadoc)
419
	 * @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionResumed(org.gvsig.gui.beans.incrementabletask.IncrementableEvent)
420
	 */
421
	public void actionResumed(IncrementableEvent e) {	
422
	}
423
	
424
	/*
425
	 * (non-Javadoc)
426
	 * @see org.gvsig.gui.beans.incrementabletask.IncrementableListener#actionSuspended(org.gvsig.gui.beans.incrementabletask.IncrementableEvent)
427
	 */
428
	public void actionSuspended(IncrementableEvent e) {
429
	}
430
	
431
	/*
432
	 * (non-Javadoc)
433
	 * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#isCancelable()
434
	 */
435
	public boolean isCancelable() {
436
		return true;
437
	}
438

  
439
	/*
440
	 * (non-Javadoc)
441
	 * @see org.gvsig.gui.beans.incrementabletask.IIncrementable#isPausable()
442
	 */
443
	public boolean isPausable() {
444
		return false;
445
	}
446
	
447
	/**
448
	 * Registra un mensaje de error en el log de gvSIG
449
	 * @param msg Mensaje a guardar en el log
450
	 * @param parent Objeto que hizo disparar el mensaje
451
	 * @param exception Excepcion que ha sido recogida
452
	 */
453
	public static void debug(String msg, Object parent, Exception exception) {
454
		if(parent != null)
455
		    LoggerFactory
456
            .getLogger(parent.getClass()).debug(Messages.getText(msg), exception);
457
	}
458
	
459
	public void dispose() {
460
		try {
461
			finalize();
462
		} catch (Throwable e) {
463
		}
464
	}
465
	
466
	/*
467
	 * (non-Javadoc)
468
	 * @see java.lang.Object#finalize()
469
	 */
470
	@Override
471
	protected void finalize() throws Throwable {
472
		incrementableTask           = null;
473
		blinker                     = null;
474
		externalActions             = null;
475
		if(taskParams != null) {
476
			taskParams.clear();
477
			taskParams = null;
478
		}
479
		log                         = null;
480
		lastLine                    = null;
481
		queueActions                = null;
482
		logger                      = null;
483
		super.finalize();
484
	}
485
	
486
	/**
487
	 * Shows a error dialog with a text and a accept button 
488
	 * @param msg Message to show in the dialog
489
	 * @param parentWindow Parent window
490
	 */
491
	public static void messageBoxError(String msg, Object parentWindow){
492
		String string = Messages.getText("accept");
493
		Object[] options = {string};
494
		JOptionPane.showOptionDialog((Component)parentWindow,
495
					"<html>" + Messages.getText(msg).replaceAll("\n", "<br>") + "</html>",
496
					Messages.getText("confirmacion"),
497
					JOptionPane.OK_OPTION,
498
					JOptionPane.ERROR_MESSAGE,
499
					null,
500
					options,
501
					string);
502
	}
503
	
504
	/**
505
	 * Muestra un dialogo de error con un texto y un bot?n de aceptar. El error es
506
	 * registrado en el log de gvSIG con la excepcion que se le pase por parametro
507
	 * @param msg Mensaje a mostrar en el dialogo.
508
	 * @param parentWindow Ventana desde la que se lanza el dialogo
509
	 * @param exception Excepcion que ha sido recogida
510
	 */
511
	public static void messageBoxError(String msg, Object parentWindow, Exception exception) {
512
		debug(msg, parentWindow, exception);
513
		messageBoxError(msg, parentWindow);
514
	}
515
	
516
	/**
517
	 * Muestra un dialogo de error con un texto y un bot?n de aceptar. Se le pasa como ?ltimo par?metros
518
	 * una lista de excepciones que ser?n guardadas en el log
519
	 * @param msg Mensaje a mostrar en el dialogo.
520
	 * @param parentWindow Ventana desde la que se lanza el dialogo
521
	 * @param exception Excepcion que ha sido recogida
522
	 */
523
	public static void messageBoxError(String msg, Object parentWindow, ArrayList<Exception> exception) {
524
		for (int i = 0; i < exception.size(); i++) 
525
			debug(msg, parentWindow, exception.get(i));
526
		messageBoxError(msg, parentWindow);
527
	}
528
	
529
	/**
530
	 * Exports a raster buffer to disk
531
	 * @param sFilename
532
	 * @param buf
533
	 * @param cellsize
534
	 * @param minX
535
	 * @param minY
536
	 * @return
537
	 */
538
	public boolean exportRaster(final String sFilename, 
539
			Buffer buf, 
540
			Buffer alphaBuffer, 
541
			double cellsize, 
542
			double minX, 
543
			double minY) {
544
		try {
545
			RasterManager manager = RasterLocator.getManager();
546
			final DataServerWriter writerBufferServer = manager.createDataServerWriter();
547
			writerBufferServer.setBuffer(buf, -1);
548
			int nBands = buf.getBandCount();
549
			ColorInterpretation colorInterpretation = null;
550
			if(alphaBuffer != null) {
551
				writerBufferServer.setAlphaBuffer(alphaBuffer);
552
				nBands ++;
553
				colorInterpretation = RasterLocator.getManager().getDataStructFactory().createColorInterpretation(
554
						new String[] { 
555
								ColorInterpretation.RED_BAND, 
556
								ColorInterpretation.GREEN_BAND, 
557
								ColorInterpretation.BLUE_BAND,
558
								ColorInterpretation.ALPHA_BAND});
559
			} else {
560
				if(nBands == 1)
561
					colorInterpretation = RasterLocator.getManager().getDataStructFactory().createColorInterpretation(
562
							new String[] { ColorInterpretation.GRAY_BAND });
563
			}
564
			final Params params = manager.createWriterParams(sFilename);
565
			final AffineTransform affineTransform =
566
				new AffineTransform(cellsize, 0, 0,
567
						-cellsize, minX, minY);
568

  
569
			final RasterWriter writer = manager.createWriter(
570
						writerBufferServer, 
571
						sFilename,
572
						nBands, 
573
						affineTransform, 
574
						buf.getWidth(),
575
						buf.getHeight(), 
576
						buf.getDataType(), 
577
						params, 
578
						null);
579
			if(colorInterpretation != null)
580
				writer.setColorBandsInterpretation(colorInterpretation.getValues());
581
			writer.dataWrite();
582
			writer.writeClose();
583
		} catch (final Exception e) {
584
			e.printStackTrace();
585
			return false;
586
		}
587
		return true;
588
	}
589
	
590
	/**
591
	 * Exports a raster buffer to disk
592
	 * @param sFilename
593
	 * @param buf
594
	 * @param cellsize
595
	 * @param minX
596
	 * @param minY
597
	 * @return
598
	 */
599
	public boolean exportRaster(final String sFilename, 
600
			Buffer buf, 
601
			double cellsize, 
602
			double minX, 
603
			double minY) {
604
        return exportRaster(sFilename, buf, null, cellsize, minX, minY);
605
    }
606
	
607
	/**
608
	 * Gets a list of rectangles which represents the pixel coordinates of each DataStore.
609
	 * This rectangle is the area that intersects with the other DataStores in the 	list.
610
	 * @param dataStoreList
611
	 * @return
612
	 */
613
	protected Rectangle2D[] getIntersectionInPxCoords(RasterDataStore[] dataStoreList) {
614
		Extent extentIntersect = null;
615
		int nRectangles = 0;
616
		for (int i = 0; i < dataStoreList.length; i++) {
617
			if(dataStoreList[i] != null) {
618
				if(extentIntersect == null)
619
					extentIntersect = dataStoreList[i].getExtent();
620
				else
621
					extentIntersect = extentIntersect.intersection(dataStoreList[i].getExtent());
622
				nRectangles ++;
623
			}
624
		}
625
		Rectangle2D[] result = new Rectangle2D[nRectangles];
626
		
627
		Point2D p1 = new Point2D.Double(extentIntersect.getULX(), extentIntersect.getULY());
628
		Point2D p2 = new Point2D.Double(extentIntersect.getLRX(), extentIntersect.getLRY());
629
		
630
		int cont = 0;
631
		for (int i = 0; i < dataStoreList.length; i++) {
632
			if(dataStoreList[i] != null) {
633
				Point2D init = dataStoreList[i].worldToRaster(p1);
634
				Point2D end = dataStoreList[i].worldToRaster(p2);
635
				result[cont] = new Rectangle2D.Double(
636
						init.getX(), 
637
						init.getY(), 
638
						Math.abs(end.getX() - init.getX()), 
639
						Math.abs(end.getY() - init.getY()));
640
				cont++;
641
			}
642
		}
643
		return result;
644
	}
645
}
0 646

  
org.gvsig.raster/tags/tagdate_29082013_14_01/org.gvsig.raster/org.gvsig.raster.algorithm/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.algorithm</artifactId>
5
	<packaging>jar</packaging>
6
	<name>org.gvsig.raster.algorithm</name>
7
	<parent>
8
		<groupId>org.gvsig</groupId>
9
		<artifactId>org.gvsig.raster</artifactId>
10
		<version>2.1.0-SNAPSHOT</version>
11
	</parent>
12
	<dependencies>
13
		<dependency>
14
			<groupId>org.gvsig</groupId>
15
			<artifactId>org.gvsig.raster.lib.api</artifactId>
16
            <scope>compile</scope>
17
		</dependency>
18
        <dependency>
19
            <groupId>org.gvsig</groupId>
20
            <artifactId>org.gvsig.raster.lib.impl</artifactId>
21
            <scope>compile</scope>
22
        </dependency>
23
     	 <dependency>
24
          <groupId>org.gvsig</groupId>
25
          <artifactId>org.gvsig.metadata.lib.basic.impl</artifactId>
26
          <scope>runtime</scope>
27
      	</dependency>
28
      	<dependency>
29
          <groupId>org.gvsig</groupId>
30
          <artifactId>org.gvsig.metadata.swing.basic.impl</artifactId>
31
          <scope>runtime</scope>
32
      	</dependency>
33
        <dependency>
34
			<groupId>org.gvsig</groupId>
35
			<artifactId>org.gvsig.raster.cache.lib.api</artifactId>
36
            <scope>compile</scope>
37
		</dependency>
38
		<dependency>
39
            <groupId>org.gvsig</groupId>
40
            <artifactId>org.gvsig.tools.lib</artifactId>
41
            <scope>compile</scope>
42
        </dependency>
43
        <dependency>
44
            <groupId>org.gvsig</groupId>
45
            <artifactId>org.gvsig.i18n</artifactId>
46
            <scope>compile</scope>
47
        </dependency>
48
        <dependency>
49
            <groupId>org.gvsig</groupId>
50
            <artifactId>org.gvsig.ui</artifactId>
51
            <scope>compile</scope>
52
        </dependency>
53
        <dependency>
54
            <groupId>org.gvsig</groupId>
55
            <artifactId>org.gvsig.projection.api</artifactId>
56
            <scope>compile</scope>
57
        </dependency>
58
        <dependency>
59
            <groupId>org.gvsig</groupId>
60
            <artifactId>org.gvsig.projection.cresques.impl</artifactId>
61
            <scope>runtime</scope>
62
        </dependency>
63
         <dependency>
64
            <groupId>org.gvsig</groupId>
65
            <artifactId>org.gvsig.compat.api</artifactId>
66
            <scope>compile</scope>
67
        </dependency>
68
        <dependency>
69
            <groupId>org.gvsig</groupId>
70
            <artifactId>org.gvsig.compat.se</artifactId>
71
            <scope>compile</scope>
72
        </dependency>
73
        <dependency>
74
            <groupId>org.gvsig</groupId>
75
            <artifactId>org.gvsig.fmap.dal.api</artifactId>
76
            <scope>compile</scope>
77
        </dependency>
78
        <dependency>
79
            <groupId>org.gvsig</groupId>
80
            <artifactId>org.gvsig.fmap.dal.impl</artifactId>
81
            <scope>compile</scope>
82
        </dependency>
83
        <dependency>
84
            <groupId>org.gvsig</groupId>
85
            <artifactId>org.gvsig.fmap.dal.file.lib</artifactId>
86
            <scope>compile</scope>
87
        </dependency>
88
        <dependency>
89
            <groupId>org.gvsig</groupId>
90
            <artifactId>org.gvsig.fmap.dal.spi</artifactId>
91
            <scope>compile</scope>
92
        </dependency>
93
        <dependency>
94
            <groupId>org.gvsig</groupId>
95
            <artifactId>org.gvsig.fmap.geometry.api</artifactId>
96
            <scope>compile</scope>
97
        </dependency>
98
        <dependency>
99
            <groupId>org.gvsig</groupId>
100
            <artifactId>org.gvsig.fmap.geometry.impl</artifactId>
101
            <scope>runtime</scope>
102
        </dependency>
103
        <dependency>
104
            <groupId>org.gvsig</groupId>
105
            <artifactId>org.gvsig.fmap.geometry.operation</artifactId>
106
            <scope>runtime</scope>
107
        </dependency>
108
	</dependencies>
109
    <properties>
110
        <build-dir>${basedir}/../../build</build-dir>
111
    </properties>
112
</project>
0 113

  
org.gvsig.raster/tags/tagdate_29082013_14_01/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.fmap.dal.coverage.RasterLibrary
org.gvsig.raster/tags/tagdate_29082013_14_01/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.api/src/main/java/org/gvsig/fmap/dal/coverage/RasterManager.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
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff