Revision 1271
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.swing/org.gvsig.raster.tools.algorithm.swing.impl/src/main/java/org/gvsig/raster/tools/algorithm/swing/impl/reproject/RasterReprojectPanelImpl.java | ||
---|---|---|
76 | 76 |
init(); |
77 | 77 |
loadPanelFromDataModel(); |
78 | 78 |
getInterpolationPanel().getComboInterpolationMethod().addActionListener(this); |
79 |
getInterpolationPanel().getRadioYes().addActionListener(this); |
|
80 |
getInterpolationPanel().getRadioNo().addActionListener(this); |
|
79 | 81 |
} |
80 | 82 |
|
81 | 83 |
private void loadPanelFromDataModel() { |
... | ... | |
325 | 327 |
if(e.getSource() == getInterpolationPanel().getComboInterpolationMethod()) { |
326 | 328 |
dataModel.setInterpolationMethodSelected(getInterpolationPanel().getComboInterpolationMethod().getSelectedIndex()); |
327 | 329 |
} |
330 |
|
|
331 |
if(e.getSource() == getInterpolationPanel().getRadioYes()) { |
|
332 |
dataModel.setInterpolationMethodSelected(getInterpolationPanel().getComboInterpolationMethod().getSelectedIndex()); |
|
333 |
} |
|
334 |
|
|
335 |
if(e.getSource() == getInterpolationPanel().getRadioNo()) { |
|
336 |
dataModel.setInterpolationMethodSelected(-1); |
|
337 |
} |
|
328 | 338 |
} |
329 | 339 |
} |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.base/src/main/java/org/gvsig/raster/tools/algorithm/base/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.tools.algorithm.base.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.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.reproject/src/main/java/org/gvsig/raster/tools/algorithm/reproject/ReprojectProcess.java | ||
---|---|---|
21 | 21 |
*/ |
22 | 22 |
package org.gvsig.raster.tools.algorithm.reproject; |
23 | 23 |
|
24 |
import java.awt.geom.Point2D; |
|
25 | 24 |
import java.util.HashMap; |
26 | 25 |
|
27 | 26 |
import javax.swing.SwingUtilities; |
28 | 27 |
|
29 |
import org.cresques.cts.ICoordTrans; |
|
30 | 28 |
import org.cresques.cts.IProjection; |
31 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
32 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
33 | 29 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
34 | 30 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
35 | 31 |
import org.gvsig.i18n.Messages; |
... | ... | |
45 | 41 |
* @author Nacho Brodin nachobrodin@gmail.com |
46 | 42 |
*/ |
47 | 43 |
public class ReprojectProcess extends RasterProcess { |
48 |
public static String[] INTERP_METHODS = new String[]{"Nearest", "Bilinear", "Bicubic"};
|
|
44 |
public static String[] INTERP_METHODS = new String[]{"Nearest", "Bilinear", "InverseDistance"};
|
|
49 | 45 |
|
50 | 46 |
public static String RASTER_STORE = "RasterStore"; |
51 | 47 |
public static String PATH = "Path"; |
... | ... | |
67 | 63 |
private int w = 0; |
68 | 64 |
private int h = 0; |
69 | 65 |
private double cellSize = 0; |
70 |
private String interpolation = null;
|
|
66 |
private int interpolation = 0;
|
|
71 | 67 |
|
72 | 68 |
public static void registerParameters() { |
73 | 69 |
RASTER_STORE = RasterBaseAlgorithmLibrary.registerInputParameter(RASTER_STORE, RasterDataStore.class); |
... | ... | |
77 | 73 |
SIZEX = RasterBaseAlgorithmLibrary.registerInputParameter(SIZEX, Integer.class); |
78 | 74 |
SIZEY = RasterBaseAlgorithmLibrary.registerInputParameter(SIZEY, Integer.class); |
79 | 75 |
CELLSIZE = RasterBaseAlgorithmLibrary.registerInputParameter(CELLSIZE, Double.class); |
80 |
INTERPOLATION = RasterBaseAlgorithmLibrary.registerInputParameter(INTERPOLATION, String.class);
|
|
76 |
INTERPOLATION = RasterBaseAlgorithmLibrary.registerInputParameter(INTERPOLATION, Integer.class);
|
|
81 | 77 |
|
82 | 78 |
FILENAME = RasterBaseAlgorithmLibrary.registerOutputParameter(FILENAME, String.class); |
83 | 79 |
TIME = RasterBaseAlgorithmLibrary.registerOutputParameter(TIME, Long.class); |
... | ... | |
88 | 84 |
* @see org.gvsig.rastertools.RasterProcess#init() |
89 | 85 |
*/ |
90 | 86 |
public void init() { |
91 |
store = (RasterDataStore)getParam(RASTER_STORE);
|
|
87 |
store = getParam(RASTER_STORE) != null ? (RasterDataStore)getParam(RASTER_STORE) : null;
|
|
92 | 88 |
filename = getStringParam(PATH); |
93 |
projdst = (IProjection) getParam(DST_PROJECTION); |
|
94 |
projsrc = (IProjection) getParam(SRC_PROJECTION); |
|
95 |
w = (Integer)getParam(SIZEX); |
|
96 |
h = (Integer)getParam(SIZEY); |
|
97 |
cellSize = (Double)getParam(CELLSIZE); |
|
89 |
projdst = getParam(DST_PROJECTION) != null ? (IProjection) getParam(DST_PROJECTION) : null; |
|
90 |
projsrc = getParam(SRC_PROJECTION) != null ? (IProjection) getParam(SRC_PROJECTION) : null; |
|
91 |
w = getIntParam(SIZEX); |
|
92 |
h = getIntParam(SIZEY); |
|
93 |
cellSize = getDoubleParam(CELLSIZE); |
|
94 |
interpolation = getIntParam(INTERPOLATION); |
|
98 | 95 |
} |
99 | 96 |
|
100 | 97 |
/** |
... | ... | |
103 | 100 |
public void process() throws ProcessInterruptedException { |
104 | 101 |
long t1 = new java.util.Date().getTime(); |
105 | 102 |
insertLineLog(Messages.getText("reprojecting")); |
106 |
reproject = new Reproject(store, filename); |
|
103 |
|
|
104 |
reproject = new Reproject(store, filename, interpolation); |
|
107 | 105 |
try { |
108 | 106 |
int result = reproject.warp(projdst, projsrc, w, h, cellSize); |
109 | 107 |
if(result != 0) { |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.algorithm/org.gvsig.raster.tools.algorithm.reproject/src/main/java/org/gvsig/raster/tools/algorithm/reproject/Reproject.java | ||
---|---|---|
40 | 40 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
41 | 41 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
42 | 42 |
import org.gvsig.fmap.dal.coverage.store.RasterWriter; |
43 |
import org.gvsig.raster.tools.algorithm.base.util.Interpolation; |
|
43 | 44 |
|
44 | 45 |
|
45 | 46 |
/** |
46 |
* Clase encargada de la reproyecci?n. Se le asigna una capa raster y la ruta de |
|
47 |
* destino |
|
47 |
* Reprojects a RasterDataStore. |
|
48 | 48 |
* |
49 | 49 |
* @version 30/04/2008 |
50 | 50 |
* @author Nacho Brodin nachobrodin@gmail.com |
51 | 51 |
*/ |
52 | 52 |
public class Reproject { |
53 |
private RasterDataStore store = null; |
|
54 |
private String pathDest = null; |
|
55 |
private int percent = 0; |
|
53 |
private RasterDataStore store = null; |
|
54 |
private String pathDest = null; |
|
55 |
private int percent = 0; |
|
56 |
private int interpolationMethod = 0; |
|
57 |
private Interpolation interpolation = null; |
|
56 | 58 |
|
57 | 59 |
/** |
58 | 60 |
* Constructor de la clase. |
59 | 61 |
* @param lyr |
60 | 62 |
* @param pathDest Ruta de destino |
61 | 63 |
*/ |
62 |
public Reproject(RasterDataStore store, String pathDest) { |
|
64 |
public Reproject(RasterDataStore store, String pathDest, int inter) {
|
|
63 | 65 |
this.store = store; |
64 | 66 |
this.pathDest = pathDest; |
67 |
this.interpolationMethod = inter; |
|
65 | 68 |
} |
66 | 69 |
|
67 | 70 |
/** |
... | ... | |
109 | 112 |
try { |
110 | 113 |
ICoordTrans t = destinationSrs.getCT(sourceSrs); |
111 | 114 |
Buffer sourceBuffer = store.query(query); |
112 |
for (int row = 0; row < buf.getHeight(); row++) { |
|
113 |
for (int col = 0; col < buf.getWidth(); col++) { |
|
114 |
Point2D p = transformPoint(newBbox, col, row, cellSize, t); |
|
115 |
writePixel(dataType, sourceBuffer, buf, p, col, row, nd); |
|
115 |
if(interpolationMethod < 0) { |
|
116 |
for (int row = 0; row < buf.getHeight(); row++) { |
|
117 |
for (int col = 0; col < buf.getWidth(); col++) { |
|
118 |
Point2D p = transformPoint(newBbox, col, row, cellSize, t); |
|
119 |
writePixel(dataType, sourceBuffer, buf, p, col, row, nd); |
|
120 |
} |
|
121 |
percent = (int)((row * 100) / buf.getHeight()); |
|
116 | 122 |
} |
117 |
percent = (int)((row * 100) / buf.getHeight()); |
|
123 |
} else { |
|
124 |
interpolation = new Interpolation(sourceBuffer); |
|
125 |
for (int row = 0; row < buf.getHeight(); row++) { |
|
126 |
for (int col = 0; col < buf.getWidth(); col++) { |
|
127 |
Point2D p = transformPoint(newBbox, col, row, cellSize, t); |
|
128 |
writePixelInterpolated(dataType, sourceBuffer, buf, p, col, row, nd, interpolationMethod); |
|
129 |
} |
|
130 |
percent = (int)((row * 100) / buf.getHeight()); |
|
131 |
} |
|
118 | 132 |
} |
133 |
|
|
119 | 134 |
export(pathDest, buf, cellSize, newBbox.getULX(), newBbox.getULY()); |
120 | 135 |
} catch (RasterDriverException e) { |
121 | 136 |
new ReprojectException("", e); |
... | ... | |
176 | 191 |
} |
177 | 192 |
|
178 | 193 |
/** |
194 |
* Writes one pixel in the destination buffer |
|
195 |
* @param type |
|
196 |
* @param sourceBuffer |
|
197 |
* @param buf |
|
198 |
* @param p |
|
199 |
* @param col |
|
200 |
* @param row |
|
201 |
*/ |
|
202 |
private void writePixelInterpolated(int type, Buffer sourceBuffer, Buffer buf, Point2D p, int col, int row, NoData nd, int interpMethod) { |
|
203 |
double value = 0; |
|
204 |
if(p.getX() > 0 && p.getX() < sourceBuffer.getWidth() && p.getY() > 0 && p.getY() < sourceBuffer.getHeight()) |
|
205 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) { |
|
206 |
if(interpMethod == 0) //Nearest neighbor |
|
207 |
value = interpolation.getNearestNeighbour(p.getX(), p.getY(), iBand); |
|
208 |
if(interpMethod == 1) //Bilinear |
|
209 |
value = interpolation.getBilinearValue(p.getX(), p.getY(), iBand); |
|
210 |
if(interpMethod == 2) //Inverse distance |
|
211 |
value = interpolation.getInverseDistance(p.getX(), p.getY(), iBand); |
|
212 |
if(type == Buffer.TYPE_BYTE) |
|
213 |
buf.setElem(row, col, iBand, (byte)value); |
|
214 |
else if(type == Buffer.TYPE_DOUBLE) |
|
215 |
buf.setElem(row, col, iBand, (double)value); |
|
216 |
else if(type == Buffer.TYPE_FLOAT) |
|
217 |
buf.setElem(row, col, iBand, (float)value); |
|
218 |
else if(type == Buffer.TYPE_SHORT) |
|
219 |
buf.setElem(row, col, iBand, (short)value); |
|
220 |
else if(type == Buffer.TYPE_INT) |
|
221 |
buf.setElem(row, col, iBand, (int)value); |
|
222 |
} |
|
223 |
else |
|
224 |
for (int iBand = 0; iBand < store.getBandCount(); iBand++) { |
|
225 |
if(type == Buffer.TYPE_BYTE) |
|
226 |
buf.setElem(row, col, iBand, nd.getValue().byteValue()); |
|
227 |
else if(type == Buffer.TYPE_DOUBLE) |
|
228 |
buf.setElem(row, col, iBand, nd.getValue().doubleValue()); |
|
229 |
else if(type == Buffer.TYPE_FLOAT) |
|
230 |
buf.setElem(row, col, iBand, nd.getValue().floatValue()); |
|
231 |
else if(type == Buffer.TYPE_SHORT) |
|
232 |
buf.setElem(row, col, iBand, nd.getValue().shortValue()); |
|
233 |
else if(type == Buffer.TYPE_INT) |
|
234 |
buf.setElem(row, col, iBand, nd.getValue().intValue()); |
|
235 |
} |
|
236 |
} |
|
237 |
|
|
238 |
/** |
|
179 | 239 |
* Transforms the upper left coordinate of a pixel using the transformation |
180 | 240 |
* which is passed by parameter |
181 | 241 |
* @param p |
org.gvsig.raster.tools/trunk/org.gvsig.raster.tools/org.gvsig.raster.tools.app/org.gvsig.raster.tools.app.reproject/src/main/java/org/gvsig/raster/tools/app/reproject/ReprojectListener.java | ||
---|---|---|
105 | 105 |
process.addParam(ReprojectProcess.SRC_PROJECTION, dataModel.getSrcProjection()); |
106 | 106 |
process.addParam(ReprojectProcess.DST_PROJECTION, dataModel.getDstProjection()); |
107 | 107 |
process.addParam(ReprojectProcess.CELLSIZE, dataModel.getCellSize()); |
108 |
process.addParam(ReprojectProcess.INTERPOLATION, dataModel.getInterpolationMethodSelected()); |
|
108 | 109 |
process.start(); |
109 | 110 |
|
110 | 111 |
} |
Also available in: Unified diff