root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / mosaic / process / MosaicProcess.java @ 27740
History | View | Annotate | Download (22.2 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Iba?ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.remotesensing.mosaic.process; |
42 |
|
43 |
import java.awt.geom.AffineTransform; |
44 |
import java.awt.geom.Point2D; |
45 |
import java.awt.image.DataBuffer; |
46 |
import java.io.File; |
47 |
import java.io.IOException; |
48 |
|
49 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
50 |
import org.gvsig.raster.RasterProcess; |
51 |
import org.gvsig.raster.buffer.BufferFactory; |
52 |
import org.gvsig.raster.buffer.BufferInterpolation; |
53 |
import org.gvsig.raster.buffer.RasterBuffer; |
54 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
55 |
import org.gvsig.raster.buffer.WriterBufferServer; |
56 |
import org.gvsig.raster.dataset.FileNotOpenException; |
57 |
import org.gvsig.raster.dataset.GeoRasterWriter; |
58 |
import org.gvsig.raster.dataset.IBuffer; |
59 |
import org.gvsig.raster.dataset.IRasterDataSource; |
60 |
import org.gvsig.raster.dataset.InvalidSetViewException; |
61 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
62 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
63 |
import org.gvsig.raster.grid.Grid; |
64 |
import org.gvsig.raster.grid.GridCell; |
65 |
import org.gvsig.raster.grid.GridExtent; |
66 |
import org.gvsig.raster.grid.OutOfGridException; |
67 |
import org.gvsig.raster.grid.filter.RasterFilter; |
68 |
import org.gvsig.raster.grid.filter.enhancement.EnhancementStretchListManager; |
69 |
import org.gvsig.raster.grid.filter.enhancement.LinearStretchParams; |
70 |
import org.gvsig.raster.util.RasterToolsUtil; |
71 |
import org.gvsig.remotesensing.RemoteSensingUtils; |
72 |
|
73 |
import com.iver.andami.PluginServices; |
74 |
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException; |
75 |
|
76 |
/**
|
77 |
* Clase que implementa el proceso de construccion de un mosaico mediante los m?todos b?sicos.
|
78 |
*
|
79 |
* @params
|
80 |
* <LI>FLyrRasterSE[] "inputRasterLayers": Capas raster de entrada</LI>
|
81 |
* <LI>int "methodCode": M?todo de construcci?n (0:Valor m?ximo, 1:Valor m?nimo, 2: Valor Medio,
|
82 |
* 3: Valor del pixel de la capa superior, 4:Valor del pixel de la capa inferior)</LI>
|
83 |
* <LI>String "outputPath": Ruta completa al fichero de salida del proceso</LI>
|
84 |
*
|
85 |
* @result
|
86 |
* <LI>outputRassterLayers[]: Capas raster resultantes</LI>
|
87 |
*
|
88 |
*
|
89 |
* @author aMu?oz (alejandro.mu?oz@uclm.es)
|
90 |
* @version 30/4/2008
|
91 |
* */
|
92 |
|
93 |
/**
|
94 |
* @author root
|
95 |
*
|
96 |
*/
|
97 |
public class MosaicProcess extends RasterProcess { |
98 |
|
99 |
public static final int MAX = 0; |
100 |
public static final int MIN = 1; |
101 |
public static final int AVERAGE = 2; |
102 |
public static final int FRONT = 3; |
103 |
public static final int BACK = 4; |
104 |
|
105 |
// Layers que intervienen en el proceso
|
106 |
private FLyrRasterSE inputRasterLayers[] = null; |
107 |
|
108 |
//Layer de salida
|
109 |
private FLyrRasterSE outputRasterLayer = null; |
110 |
|
111 |
// Extend completo del mosaico
|
112 |
private GridExtent fullExtend= null; |
113 |
|
114 |
// Grid resultante
|
115 |
Grid mosaicGrid = null;
|
116 |
|
117 |
// Buffers con las imagenes
|
118 |
IBuffer buffers[]= null; |
119 |
|
120 |
// Codigo operacion mayor, menor,media valor de la situada encima.
|
121 |
int codOp= 0; |
122 |
|
123 |
// indicador de proceso
|
124 |
int percent=0, proceso=0; |
125 |
|
126 |
// writer para escritura en fichero
|
127 |
private WriterBufferServer writerBufferServer =null; |
128 |
|
129 |
// Numero de bandas 3 o 1 dependiendo de si es RGB o Nivel de gris
|
130 |
int resultbandCount=0; |
131 |
|
132 |
// Fichero de salida
|
133 |
private String fileName=null; |
134 |
|
135 |
private int lastY=-1; |
136 |
|
137 |
private Grid layersGrid[]= null; |
138 |
|
139 |
private GridExtent extendS[] = null; |
140 |
|
141 |
private GridCell cell = null; |
142 |
|
143 |
/** Inicializaci?n de los par?metros
|
144 |
* layers - FLayers con los layers seleccionados para el mosaico.
|
145 |
*
|
146 |
* En la inicializacion se calcula el grid resultante.
|
147 |
* */
|
148 |
public void init() { |
149 |
|
150 |
inputRasterLayers= (FLyrRasterSE[])getParam("inputRasterLayers"); |
151 |
codOp= getIntParam("methodCode");
|
152 |
resultbandCount= getIntParam("numbands");
|
153 |
fileName = getStringParam("outputPath");
|
154 |
|
155 |
IRasterDataSource dsetCopy = null;
|
156 |
buffers= new RasterBuffer[inputRasterLayers.length];
|
157 |
extendS= new GridExtent[inputRasterLayers.length];
|
158 |
|
159 |
// Calculo del extend resultante
|
160 |
fullExtend= calculateExtend(inputRasterLayers); |
161 |
extendS=new GridExtent[inputRasterLayers.length];
|
162 |
|
163 |
for(int i=0; i< inputRasterLayers.length;i++) |
164 |
{ |
165 |
dsetCopy = ((FLyrRasterSE)inputRasterLayers[i]).getDataSource().newDataset(); |
166 |
BufferFactory bufferFactory = new BufferFactory(dsetCopy);
|
167 |
bufferFactory.setAdjustToExtent(false);
|
168 |
bufferFactory.setDrawableBands(inputRasterLayers[i].getRenderBands()); |
169 |
if (!RasterBuffer.loadInMemory(dsetCopy))
|
170 |
bufferFactory.setReadOnly(true);
|
171 |
|
172 |
try {
|
173 |
extendS[i]= new GridExtent(inputRasterLayers[i].getFullExtent().getMinX(),
|
174 |
inputRasterLayers[i].getFullExtent().getMinY(), |
175 |
inputRasterLayers[i].getFullExtent().getMaxX(), |
176 |
inputRasterLayers[i].getFullExtent().getMaxY(), |
177 |
inputRasterLayers[i].getAffineTransform().getScaleX(), |
178 |
inputRasterLayers[i].getAffineTransform().getScaleY()); |
179 |
|
180 |
bufferFactory.setAreaOfInterest(extendS[i].getMin().getX(), extendS[i].getMax().getY(), |
181 |
extendS[i].getMax().getX(), extendS[i].getMin().getY(), extendS[i].getNX(),extendS[i].getNY()); |
182 |
buffers[i]= bufferFactory.getRasterBuf(); |
183 |
buffers[i]= ((RasterBuffer)buffers[i]).getAdjustedWindow(extendS[i].getNX(), extendS[i].getNY(), BufferInterpolation.INTERPOLATION_Bilinear); |
184 |
|
185 |
// Aplicar filtro de realce si es necesario:
|
186 |
if(buffers[i].getDataType()!=DataBuffer.TYPE_BYTE){ |
187 |
LinearStretchParams leParams = null;
|
188 |
leParams = LinearStretchParams.createStandardParam(inputRasterLayers[i].getRenderBands(), 0.0, bufferFactory.getDataSource().getStatistics(), false); |
189 |
|
190 |
RasterFilter linearStretchEnhancementFilter = EnhancementStretchListManager.createEnhancedFilter(leParams, bufferFactory.getDataSource().getStatistics(), |
191 |
inputRasterLayers[i].getRenderBands(), false);
|
192 |
linearStretchEnhancementFilter.addParam("raster", buffers[i]);
|
193 |
linearStretchEnhancementFilter.execute(); |
194 |
buffers[i] = (IBuffer)linearStretchEnhancementFilter.getResult("raster");
|
195 |
} |
196 |
|
197 |
} catch (FileNotOpenException e) {
|
198 |
return;
|
199 |
} catch (RasterDriverException e) {
|
200 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e); |
201 |
} catch (InterruptedException e) { |
202 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e); |
203 |
} catch (InvalidSetViewException e) {
|
204 |
e.printStackTrace(); |
205 |
} |
206 |
} |
207 |
try {
|
208 |
mosaicGrid= new Grid(fullExtend,fullExtend,IBuffer.TYPE_BYTE,new int[] { 0, 1, 2 }); |
209 |
resultbandCount = mosaicGrid.getBandCount(); |
210 |
} catch (RasterBufferInvalidException e) {
|
211 |
RasterToolsUtil.messageBoxError("buffer_incorrecto", this, e); |
212 |
} |
213 |
} |
214 |
|
215 |
|
216 |
/**
|
217 |
* Proceso
|
218 |
* */
|
219 |
public void process() throws InterruptedException { |
220 |
|
221 |
// Construccion del mosaico: Operaci?n M?ximo
|
222 |
if(codOp==MAX){
|
223 |
int progress = 0; |
224 |
for(int i=0;i<buffers.length;i++){ |
225 |
for(int band=0; band<resultbandCount; band++){ |
226 |
mosaicGrid.setBandToOperate(band); |
227 |
for(int row=0; row<buffers[i].getHeight(); row++){ |
228 |
progress++; |
229 |
calculateCoords(-1,row,i);
|
230 |
for(int col=0; col<buffers[i].getWidth();col++){ |
231 |
setValueMax(col,row,band,i); |
232 |
} |
233 |
percent=(int)( progress*100/((mosaicGrid.getLayerNY()*resultbandCount)))/buffers.length; |
234 |
} |
235 |
} |
236 |
} |
237 |
} |
238 |
|
239 |
// Construccion del mosaico: Operaci?n M?nimo
|
240 |
if(codOp==MIN){
|
241 |
int progress = 0; |
242 |
for(int i=0;i<buffers.length;i++){ |
243 |
for(int band=0; band<resultbandCount; band++){ |
244 |
mosaicGrid.setBandToOperate(band); |
245 |
for(int row=0; row<buffers[i].getHeight(); row++){ |
246 |
progress++; |
247 |
calculateCoords(-1,row,i);
|
248 |
for(int col=0; col<buffers[i].getWidth();col++){ |
249 |
setValueMin(col,row,band,i); |
250 |
} |
251 |
percent=(int)( progress*100/((mosaicGrid.getLayerNY()*resultbandCount)))/buffers.length; |
252 |
} |
253 |
} |
254 |
} |
255 |
} |
256 |
|
257 |
// Construccion del mosaico: Operaci?n Media
|
258 |
if(codOp==AVERAGE){
|
259 |
int progress = 0; |
260 |
for(int i=0;i<buffers.length;i++){ |
261 |
for(int band=0; band<resultbandCount; band++){ |
262 |
mosaicGrid.setBandToOperate(band); |
263 |
for(int row=0; row<buffers[i].getHeight(); row++){ |
264 |
progress++; |
265 |
calculateCoords(-1,row,i);
|
266 |
for(int col=0; col<buffers[i].getWidth();col++){ |
267 |
setValueMean(col,row,band,i); |
268 |
} |
269 |
percent=(int)( progress*100/((mosaicGrid.getLayerNY()*resultbandCount)))/buffers.length; |
270 |
} |
271 |
} |
272 |
} |
273 |
} |
274 |
|
275 |
// Construccion del mosaico: Operacion valor de capa de delantera
|
276 |
if(codOp==FRONT){
|
277 |
int progress = 0; |
278 |
for(int i=0;i<buffers.length;i++){ |
279 |
for(int band=0; band<resultbandCount; band++){ |
280 |
mosaicGrid.setBandToOperate(band); |
281 |
for(int row=0; row<buffers[i].getHeight(); row++){ |
282 |
progress++; |
283 |
calculateCoords(-1,row,i);
|
284 |
for(int col=0; col<buffers[i].getWidth();col++){ |
285 |
setValueFront(col,row,band,i); |
286 |
} |
287 |
percent=(int)( progress*100/((mosaicGrid.getLayerNY()*resultbandCount)))/buffers.length; |
288 |
} |
289 |
} |
290 |
} |
291 |
} |
292 |
|
293 |
|
294 |
// Construccion del mosaico: Operaci?n Valor de capa de trasera
|
295 |
if(codOp==BACK){
|
296 |
int progress = 0; |
297 |
for(int i=0;i<buffers.length;i++){ |
298 |
for(int band=0; band<resultbandCount; band++){ |
299 |
mosaicGrid.setBandToOperate(band); |
300 |
for(int row=0; row<buffers[i].getHeight(); row++){ |
301 |
progress++; |
302 |
calculateCoords(-1,row,i);
|
303 |
for(int col=0; col<buffers[i].getWidth();col++){ |
304 |
setValueBack(col,row,band,i); |
305 |
} |
306 |
percent=(int)( progress*100/((mosaicGrid.getLayerNY()*resultbandCount)))/buffers.length; |
307 |
} |
308 |
} |
309 |
} |
310 |
} |
311 |
|
312 |
// Escritura en fichero
|
313 |
proceso=2;
|
314 |
createLayer(); |
315 |
if (externalActions != null) |
316 |
externalActions.end(outputRasterLayer); |
317 |
} |
318 |
|
319 |
|
320 |
/**
|
321 |
* M?todo que establece para la coordenada x,y el valor m?ximo
|
322 |
* de todos los valores para ese p?xel en cualquiera de las imagenes.
|
323 |
* @param cordenada x
|
324 |
* @param coordenada y
|
325 |
* @throws InterruptedException
|
326 |
* */
|
327 |
public void setValueMax(int x, int y, int band,int layer) throws InterruptedException{ |
328 |
|
329 |
byte result=Byte.MIN_VALUE; |
330 |
byte data=Byte.MIN_VALUE; |
331 |
Point2D worldPoint=(Point2D) extendS[layer].getWorldCoordsFromGridCoords(new GridCell(x,y,(double)0));; |
332 |
int numLayers= buffers.length;
|
333 |
|
334 |
for(int i=0; i<numLayers;i++){ |
335 |
if(extendS[i].isAt(worldPoint))
|
336 |
{ |
337 |
GridCell cell=extendS[i].getGridCoordsFromWorldCoords(worldPoint); |
338 |
if(!(cell.getX()>=buffers[i].getWidth()||cell.getY()>=buffers[i].getHeight()))
|
339 |
data = (byte)RemoteSensingUtils.getCellValueInLayerCoords(buffers[i], cell.getX(), cell.getY(), band);
|
340 |
result=(byte) Math.max((byte)result,(byte)data); |
341 |
} |
342 |
} |
343 |
try {
|
344 |
cell.setX(cell.getX()+1);
|
345 |
mosaicGrid.setCellValue(cell.getX(),cell.getY(),(byte)result);
|
346 |
} catch (OutOfGridException e) {
|
347 |
//e.printStackTrace();
|
348 |
} |
349 |
} |
350 |
|
351 |
|
352 |
/**
|
353 |
* M?todo que establece para la coordenada x,y el valor m?ximo
|
354 |
* de todos los valores para ese p?xel en cualquiera de las imagenes.
|
355 |
* @param cordenada x
|
356 |
* @param coordenada y
|
357 |
* @throws InterruptedException
|
358 |
* */
|
359 |
public void setValueMin(int x, int y,int band,int layer) throws InterruptedException{ |
360 |
byte result=Byte.MAX_VALUE; |
361 |
byte data=Byte.MAX_VALUE; |
362 |
Point2D worldPoint=(Point2D) extendS[layer].getWorldCoordsFromGridCoords(new GridCell(x,y,(double)0));; |
363 |
int numLayers= buffers.length;
|
364 |
|
365 |
for(int i=0; i<numLayers;i++){ |
366 |
if(extendS[i].isAt(worldPoint))
|
367 |
{ |
368 |
GridCell cell=extendS[i].getGridCoordsFromWorldCoords(worldPoint); |
369 |
if(!(cell.getX()>=buffers[i].getWidth()||cell.getY()>=buffers[i].getHeight()))
|
370 |
data = (byte)RemoteSensingUtils.getCellValueInLayerCoords(buffers[i], cell.getX(), cell.getY(), band);
|
371 |
result=(byte) Math.min((byte)result,(byte)data); |
372 |
} |
373 |
} |
374 |
try {
|
375 |
cell.setX(cell.getX()+1);
|
376 |
mosaicGrid.setCellValue(cell.getX(),cell.getY(),(byte)result);
|
377 |
} catch (OutOfGridException e) {
|
378 |
//e.printStackTrace();
|
379 |
} |
380 |
} |
381 |
|
382 |
|
383 |
/**
|
384 |
* M?todo que establece para la coordenada x,y el valor medio
|
385 |
* de todos los valores para ese p?xel en cualquiera de las imagenes.
|
386 |
* Si el valor en cualquiera de las imagenes es noData no es tenido en cuenta
|
387 |
* @param cordenada x
|
388 |
* @param coordenada y
|
389 |
* @throws InterruptedException
|
390 |
* */
|
391 |
public void setValueMean(int x, int y, int band,int layer) throws InterruptedException{ |
392 |
|
393 |
double result=0; int buffTotales=0; |
394 |
Point2D worldPoint=(Point2D) extendS[layer].getWorldCoordsFromGridCoords(new GridCell(x,y,(double)0));; |
395 |
int numLayers= buffers.length;
|
396 |
|
397 |
for(int i=0; i<numLayers;i++){ |
398 |
if(extendS[i].isAt(worldPoint))
|
399 |
{ |
400 |
GridCell cell=extendS[i].getGridCoordsFromWorldCoords(worldPoint); |
401 |
if(!(cell.getX()>=buffers[i].getWidth()||cell.getY()>=buffers[i].getHeight()))
|
402 |
result+= RemoteSensingUtils.getCellValueInLayerCoords(buffers[i], cell.getX(), cell.getY(), band); |
403 |
buffTotales++; |
404 |
} |
405 |
} |
406 |
try {
|
407 |
if(buffTotales==0) |
408 |
buffTotales=1;
|
409 |
result=result/(buffTotales); |
410 |
cell.setX(cell.getX()+1);
|
411 |
mosaicGrid.setCellValue(cell.getX(),cell.getY(),(byte)result);
|
412 |
} catch (OutOfGridException e) {
|
413 |
//e.printStackTrace();
|
414 |
} |
415 |
|
416 |
} |
417 |
|
418 |
|
419 |
/**
|
420 |
* M?todo que establece para la coordenada x,y el valor de la capa superior
|
421 |
* en caso de solape. Se parte de un array de buffer ordenados, de tal manera que
|
422 |
* el primer elemento corresponde a la capa situada mas al frente. El ?ltimo por
|
423 |
* contra es el situado al fondo.
|
424 |
|
425 |
* @param cordenada x
|
426 |
* @param coordenada y
|
427 |
* @throws InterruptedException
|
428 |
* */
|
429 |
public void setValueFront(int x, int y, int band,int layer) throws InterruptedException{ |
430 |
Point2D worldPoint=(Point2D) extendS[layer].getWorldCoordsFromGridCoords(new GridCell(x,y,(double)0));; |
431 |
int numLayers= buffers.length;
|
432 |
byte result=0; |
433 |
for(int i=0; i<numLayers;i++){ |
434 |
if(extendS[i].isAt(worldPoint))
|
435 |
{ |
436 |
GridCell cell=extendS[i].getGridCoordsFromWorldCoords(worldPoint); |
437 |
if(!(cell.getX()>=buffers[i].getWidth()||cell.getY()>=buffers[i].getHeight()))
|
438 |
result = (byte)RemoteSensingUtils.getCellValueInLayerCoords(buffers[i], cell.getX(), cell.getY(), band);
|
439 |
break;
|
440 |
} |
441 |
} |
442 |
try {
|
443 |
cell.setX(cell.getX()+1);
|
444 |
mosaicGrid.setCellValue(cell.getX(),cell.getY(),(byte)result);
|
445 |
} catch (OutOfGridException e) {
|
446 |
//e.printStackTrace();
|
447 |
} |
448 |
} |
449 |
|
450 |
|
451 |
/**
|
452 |
* M?todo que establece para la coordenada x,y el valor de la capa inferior
|
453 |
* en caso de solape. Se parte de un array de buffer ordenados, de tal manera que
|
454 |
* el primer elemento corresponde a la capa situada mas al frente. El ?ltimo por
|
455 |
* contra es el situado al fondo.
|
456 |
|
457 |
* @param cordenada x
|
458 |
* @param coordenada y
|
459 |
* @throws InterruptedException
|
460 |
* */
|
461 |
public void setValueBack(int x, int y, int band,int layer) throws InterruptedException{ |
462 |
Point2D worldPoint=(Point2D) extendS[layer].getWorldCoordsFromGridCoords(new GridCell(x,y,(double)0));; |
463 |
int numLayers= buffers.length;
|
464 |
byte result=0; |
465 |
for(int i=0; i<numLayers;i++){ |
466 |
if(extendS[i].isAt(worldPoint))
|
467 |
{ |
468 |
GridCell cell=extendS[i].getGridCoordsFromWorldCoords(worldPoint); |
469 |
if(!(cell.getX()>=buffers[i].getWidth()||cell.getY()>=buffers[i].getHeight()))
|
470 |
result = (byte)RemoteSensingUtils.getCellValueInLayerCoords(buffers[i], cell.getX(), cell.getY(), band);
|
471 |
} |
472 |
} |
473 |
try {
|
474 |
cell.setX(cell.getX()+1);
|
475 |
mosaicGrid.setCellValue(cell.getX(),cell.getY(),(byte)result);
|
476 |
} catch (OutOfGridException e) {
|
477 |
//e.printStackTrace();
|
478 |
} |
479 |
} |
480 |
|
481 |
/**
|
482 |
* M?todo que calcula la cordenadas iniciales de una fila
|
483 |
* @param cordenada x
|
484 |
* @param coordenada y
|
485 |
* @param layer
|
486 |
* */
|
487 |
private void calculateCoords(int x, int y, int layer){ |
488 |
|
489 |
Point2D worldPoint=(Point2D) extendS[layer].getWorldCoordsFromGridCoords(new GridCell(x,y,(double)0));; |
490 |
// Se obtiene la coordenada correspondiente a la fila
|
491 |
cell=mosaicGrid.getGridExtent().getGridCoordsFromWorldCoords(worldPoint); |
492 |
if(lastY==cell.getY())
|
493 |
cell.setY(cell.getY()+1);
|
494 |
lastY= cell.getY(); |
495 |
} |
496 |
|
497 |
|
498 |
|
499 |
/**
|
500 |
* M?todo que calcula el extend resultante para la operaci?n de mosaico
|
501 |
*
|
502 |
* @param layers que intervienen en la operacion.
|
503 |
* @return GridExtend del mosaico
|
504 |
* */
|
505 |
|
506 |
private GridExtent calculateExtend (FLyrRasterSE layers[]){ |
507 |
|
508 |
GridExtent result= null;
|
509 |
IRasterDataSource dsetCopy = null;
|
510 |
double cellSizeX=java.lang.Double.MAX_VALUE;
|
511 |
double cellSizeY=java.lang.Double.MAX_VALUE;
|
512 |
double minX=0,maxX=0,minY=0,maxY=0; |
513 |
|
514 |
// Se obtiene el menor tama?o de celda mayor
|
515 |
|
516 |
for(int i=0; i< layers.length;i++) { |
517 |
double csX = ((FLyrRasterSE)layers[i]).getCellSize();
|
518 |
double csY = ((FLyrRasterSE)layers[i]).getWCHeight() / ((FLyrRasterSE)layers[i]).getPxHeight();
|
519 |
cellSizeX = Math.min(cellSizeX, csX);
|
520 |
cellSizeY = Math.min(cellSizeY, csY);
|
521 |
} |
522 |
|
523 |
minX = layers[0].getFullExtent().getMinX();
|
524 |
minY = layers[0].getFullExtent().getMinY();
|
525 |
maxX = layers[0].getFullExtent().getMaxX();
|
526 |
maxY = layers[0].getFullExtent().getMaxY();
|
527 |
|
528 |
for(int i=1; i<layers.length;i++){ |
529 |
|
530 |
minX= Math.min(minX,layers[i].getFullExtent().getMinX());
|
531 |
minY= Math.min(minY,layers[i].getFullExtent().getMinY());
|
532 |
maxX= Math.max(maxX,layers[i].getFullExtent().getMaxX());
|
533 |
maxY= Math.max(maxY,layers[i].getFullExtent().getMaxY());
|
534 |
} |
535 |
|
536 |
result = new GridExtent(minX,minY,maxX,maxY,cellSizeX,cellSizeY);
|
537 |
return result;
|
538 |
} |
539 |
|
540 |
/**
|
541 |
* Escritura del resultado en disco y carga en la vista
|
542 |
*/
|
543 |
public void createLayer(){ |
544 |
try{
|
545 |
// Escritura de los datos a fichero temporal
|
546 |
int endIndex = fileName.lastIndexOf("."); |
547 |
if (endIndex < 0) |
548 |
endIndex = fileName.length(); |
549 |
GeoRasterWriter grw = null;
|
550 |
writerBufferServer = new WriterBufferServer(mosaicGrid.getRasterBuf());
|
551 |
AffineTransform aTransform = new AffineTransform(fullExtend.getCellSize(),0.0,0.0,-fullExtend.getCellSize(),fullExtend.getMin().getX(),fullExtend.getMax().getY()); |
552 |
grw = GeoRasterWriter.getWriter(writerBufferServer, fileName, mosaicGrid.getBandCount(),aTransform, mosaicGrid.getRasterBuf().getWidth(), mosaicGrid.getRasterBuf().getHeight(), mosaicGrid.getRasterBuf().getDataType(), GeoRasterWriter.getWriter(fileName).getParams(), inputRasterLayers[0].getProjection());
|
553 |
grw.dataWrite(); |
554 |
grw.setWkt((String)((FLyrRasterSE)inputRasterLayers[0]).getWktProjection()); |
555 |
grw.writeClose(); |
556 |
mosaicGrid.getRasterBuf().free(); |
557 |
outputRasterLayer = FLyrRasterSE.createLayer(fileName.substring(fileName.lastIndexOf(File.separator) + 1, endIndex), |
558 |
fileName, null);
|
559 |
|
560 |
} catch (NotSupportedExtensionException e) {
|
561 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer_notsupportedextension"), this, e); |
562 |
} catch (IOException e) { |
563 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e); |
564 |
} catch (InterruptedException e) { |
565 |
Thread.currentThread().interrupt();
|
566 |
} catch (RasterDriverException e) {
|
567 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "raster_buffer_invalid_extension"), this, e); |
568 |
} catch (LoadLayerException e) {
|
569 |
RasterToolsUtil.messageBoxError("error_cargar_capa", this, e); |
570 |
} |
571 |
|
572 |
} |
573 |
|
574 |
public Object getResult() { |
575 |
return outputRasterLayer;
|
576 |
|
577 |
} |
578 |
|
579 |
|
580 |
/**
|
581 |
* @return descripcion
|
582 |
* */
|
583 |
public String getTitle() { |
584 |
return PluginServices.getText(this,"mosaic_process"); |
585 |
} |
586 |
|
587 |
|
588 |
/**
|
589 |
* @return String con el log en cada parte del proceso
|
590 |
* */
|
591 |
public String getLog() |
592 |
{ |
593 |
if(proceso==0) |
594 |
return PluginServices.getText(this,"load_buffer_data"); |
595 |
else if (proceso==1) |
596 |
return PluginServices.getText(this,"generate_mosaic"); |
597 |
else
|
598 |
return PluginServices.getText(this,"write_to_file"); |
599 |
} |
600 |
|
601 |
/**
|
602 |
* @return indicador de progreso
|
603 |
* */
|
604 |
public int getPercent() { |
605 |
if(writerBufferServer==null) |
606 |
return percent;
|
607 |
else
|
608 |
return writerBufferServer.getPercent();
|
609 |
} |
610 |
|
611 |
|
612 |
/*
|
613 |
// Identificaci?n de zonas de solapamiento
|
614 |
public boolean getSolapes(FLyrRasterSE raster1, FLyrRasterSE raster2){
|
615 |
|
616 |
Grid grid1=null, grid2=null, aux=null;;
|
617 |
IRasterDataSource dsetCopy = null;
|
618 |
dsetCopy =raster1.getDataSource().newDataset();
|
619 |
BufferFactory bufferFactory = new BufferFactory(dsetCopy);
|
620 |
|
621 |
IRasterDataSource dsetCopy2 = null;
|
622 |
dsetCopy2 =raster2.getDataSource().newDataset();
|
623 |
BufferFactory bufferFactory2 = new BufferFactory(dsetCopy2);
|
624 |
|
625 |
|
626 |
if (!RasterBuffer.loadInMemory(dsetCopy))
|
627 |
bufferFactory.setReadOnly(true);
|
628 |
|
629 |
try {
|
630 |
grid1 = new Grid(bufferFactory,raster1.getRenderBands());
|
631 |
grid2= new Grid(bufferFactory2,raster2.getRenderBands());
|
632 |
} catch (RasterBufferInvalidException e) {
|
633 |
e.printStackTrace();
|
634 |
}
|
635 |
|
636 |
// En grid1 la imagen con la cordenada x menor.
|
637 |
if(grid2.getGridExtent().getMin().getX()< grid1.getGridExtent().getMin().getX())
|
638 |
{
|
639 |
try {
|
640 |
grid1 = new Grid(bufferFactory2,raster2.getRenderBands());
|
641 |
grid2= new Grid(bufferFactory,raster1.getRenderBands());
|
642 |
} catch (RasterBufferInvalidException e) {
|
643 |
e.printStackTrace();
|
644 |
}
|
645 |
|
646 |
}
|
647 |
|
648 |
double xmin= grid1.getGridExtent().getMin().getX();
|
649 |
double xmax= grid1.getGridExtent().getMax().getX();
|
650 |
double ymin= grid1.getGridExtent().getMin().getY();
|
651 |
double ymax= grid1.getGridExtent().getMax().getY();
|
652 |
|
653 |
double xmin2= grid2.getGridExtent().getMin().getX();
|
654 |
double ymin2= grid2.getGridExtent().getMin().getY();
|
655 |
|
656 |
if(!(xmin2>xmin && xmin2<xmax)){
|
657 |
System.out.print("Las imagenes no se solapan en las X");
|
658 |
return false;
|
659 |
}
|
660 |
|
661 |
if(!(ymin2>ymin && ymin2<ymax)){
|
662 |
System.out.print("Las imagenes no se solapan en las Y");
|
663 |
return false;
|
664 |
}
|
665 |
|
666 |
// Detectado el solapamiento
|
667 |
System.out.print("Rango x["+ xmin2 + ","+ Math.min(xmax,grid2.getGridExtent().getMax().getX())+"].");
|
668 |
System.out.print("Rango y["+ ymin2 + ","+ Math.min(ymax,grid2.getGridExtent().getMax().getY())+"].");
|
669 |
|
670 |
return true;
|
671 |
}*/
|
672 |
|
673 |
|
674 |
} |