Revision 4532 trunk/libraries/libCq CMS for java.old/src/org/cresques/io/GdalWriter.java

View differences:

GdalWriter.java
88 88
    private String[] 				params = null; //Par?metros de creaci?n del dataset.
89 89
    private GdalSupportOptions 		support = null;
90 90
    private boolean 				consulta = false;
91
    private	boolean					write = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido
91 92

  
92 93
    /**
93 94
     * Constructor para la obtenci?n de par?metros del driver
......
441 442
                    rband = dset_destino.getRasterBand(iBand + 1);
442 443

  
443 444
                    for (int iBlock = 0; iBlock < nBlocks; iBlock++) {
444
                        //leemos el bloque origen
445
                        buf.buffByte = currentRaster.getGeoFile().getWindow(0,
446
                                                                            iBlock * this.support.getBlockSize(),
447
                                                                            sizeWindowX,
448
                                                                            this.support.getBlockSize(),
449
                                                                            iBand +
450
                                                                            1);
451

  
452
                        //Escribimos el bloque destino
453
                        rband.writeRaster(0,
454
                                          iBlock * this.support.getBlockSize(),
455
                                          sizeWindowX,
456
                                          this.support.getBlockSize(), buf,
457
                                          Gdal.GDT_Byte);
445
                    	if(write){
446
	                        //leemos el bloque origen
447
	                        buf.buffByte = currentRaster.getGeoFile().getWindow(0,
448
	                                                                            iBlock * this.support.getBlockSize(),
449
	                                                                            sizeWindowX,
450
	                                                                            this.support.getBlockSize(),
451
	                                                                            iBand +
452
	                                                                            1);
453
	
454
	                        //Escribimos el bloque destino
455
	                        rband.writeRaster(0,
456
	                                          iBlock * this.support.getBlockSize(),
457
	                                          sizeWindowX,
458
	                                          this.support.getBlockSize(), buf,
459
	                                          Gdal.GDT_Byte);
460
                    	}else
461
                    		this.writeClose();
458 462
                    }
459 463
                }
460 464
            } else if (mode == Mode.dataWrite) {
461 465
                //for(int iBlock=1;iBlock<=nBlocks;iBlock++){
462 466
                for (int iBlock = 0; iBlock < nBlocks; iBlock++) {
463 467
                    int posicionY = iBlock * this.support.getBlockSize();
464
                    writeBands(buftmp, this.support.getBlockSize(), posicionY);
468
                    if(write)
469
                    	writeBands(buftmp, this.support.getBlockSize(), posicionY);
470
                    else
471
                    	this.writeClose();
465 472
                }
466 473
            }
467 474

  
......
469 476
                if (mode == Mode.fileWrite) {
470 477
                    for (int iBand = 0; iBand < this.nBands; iBand++) {
471 478
                        rband = dset_destino.getRasterBand(iBand + 1);
472

  
473
                        //leemos el bloque origen
474
                        buf.buffByte = currentRaster.getGeoFile().getWindow(0,
475
                                                                            nBlocks * this.support.getBlockSize(),
476
                                                                            sizeWindowX,
477
                                                                            anchoResto,
478
                                                                            iBand +
479
                                                                            1);
480

  
481
                        //Escribimos el bloque destino
482
                        rband.writeRaster(0,
483
                                          nBlocks * this.support.getBlockSize(),
484
                                          sizeWindowX, anchoResto, buf,
485
                                          Gdal.GDT_Byte);
479
                        if(write){
480
	                        //leemos el bloque origen
481
	                        buf.buffByte = currentRaster.getGeoFile().getWindow(0,
482
	                                                                            nBlocks * this.support.getBlockSize(),
483
	                                                                            sizeWindowX,
484
	                                                                            anchoResto,
485
	                                                                            iBand +
486
	                                                                            1);
487
	
488
	                        //Escribimos el bloque destino
489
	                        rband.writeRaster(0,
490
	                                          nBlocks * this.support.getBlockSize(),
491
	                                          sizeWindowX, anchoResto, buf,
492
	                                          Gdal.GDT_Byte);
493
                        }else
494
                        	this.writeClose();
486 495
                    }
487 496
                } else if (mode == Mode.dataWrite) {
488 497
                    int posicionY = nBlocks * this.support.getBlockSize();
489
                    writeBands(buftmp, anchoResto, posicionY);
498
                    if(write)
499
                    	writeBands(buftmp, anchoResto, posicionY);
500
                    else
501
                    	this.writeClose();
490 502
                }
491 503
            }
492 504
        } catch (GdalException e) {
......
571 583
     */
572 584
    public void writeClose() {
573 585
        try {
574
            dset_destino.close();
586
        	if(dset_destino != null)
587
        		dset_destino.close();
575 588
            oSRS = null;
576 589
        } catch (GdalException e) {
577 590
            e.printStackTrace();
......
582 595
     * Cancela el salvado de datos.
583 596
     */
584 597
    public void writeCancel() {
585
        this.writeClose();
598
       write = false; 
586 599
    }
587 600
    
588 601
    /**
......
676 689
    }
677 690

  
678 691
    /**
692
     * Obtiene el valor a la variable write que estar? a true cuando se est? escribiendo
693
     *  o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
694
     * pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
695
     * de salida. 
696
     * @return True si puede escribirse y false si no puede
697
     */
698
    public boolean isWrite() {
699
		return write;
700
	}
701

  
702
    /**
703
     * Asigna el valor a la variable write que estar? a true cuando se est? escribiendo
704
     *  o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
705
     * pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
706
     * de salida. 
707
     * @param write Variable booleana. True si puede escribirse y false si no puede
708
     */
709
	public void setWrite(boolean write) {
710
		this.write = write;
711
	}
712
	
713
    /**
679 714
     *
680 715
     * @author Nacho Brodin (brodin_ign@gva.es)
681 716
     *

Also available in: Unified diff