Revision 5135

View differences:

org.gvsig.raster.reproject/trunk/org.gvsig.raster.reproject/org.gvsig.raster.reproject.algorithm/src/main/java/org/gvsig/raster/reproject/algorithm/Reproject.java
62 62

  
63 63
	/**
64 64
	 * Constructor de la clase.
65
	 * @param store
65 66
	 * @param lyr
66 67
	 * @param pathDest Ruta de destino
68
	 * @param inter
69
	 * @param process
67 70
	 */
68 71
	public Reproject(RasterDataStore store, String pathDest, int inter, DataProcess process) {
69 72
		this.store = store;
......
75 78
	/**
76 79
	 * M?todo para la transformaci?n del raster.
77 80
	 * @param destinationSrs Proyecci?n destino
81
	 * @param sourceSrs
82
	 * @param w
83
	 * @param h
84
	 * @param cellSize
85
	 * @return
86
	 * @throws ReprojectException
78 87
	 */
79 88
	public int warp(IProjection destinationSrs, IProjection sourceSrs, int w, int h, double cellSize) throws ReprojectException {
80 89
		if (store == null)
......
145 154

  
146 155
			boolean exported = process.exportRaster(pathDest, buf, cellSize, newBbox.getULX(), newBbox.getULY());
147 156
			if(exported){
148
			    File prjFile = getPrjFile(file);
149
			    try {
150
                    FileUtils.writeStringToFile(prjFile,
151
                        destinationSrs.export(ICRSFactory.FORMAT_WKT_ESRI));
152
                } catch (Exception e) {
153
                    logger.info("Can't write prj file '" + prjFile.getAbsolutePath() + "'.");
154
                }
157
			    savePrjFile(file, destinationSrs);
155 158
			}
156 159
		} catch (ProcessInterruptedException e) {
157 160
		} catch (QueryException e) {
......
161 164
		return 0;
162 165
	}
163 166

  
164
	private File getPrjFile(File file){
165
	    File prjFile = new File(FilenameUtils.removeExtension(file.getAbsolutePath())+".prj");
166
	    return prjFile;
167
	}
167
    private void savePrjFile(File dataFile, IProjection proj){
168
        File file = new File(FilenameUtils.removeExtension(dataFile.getAbsolutePath())+".prj");
169
        try {
170
            String export = proj.export(ICRSFactory.FORMAT_WKT_ESRI);
171
            if(export!=null){
172
                FileUtils.writeStringToFile(file, export);
173
            }
174
        } catch (Exception e) {
175
            logger.info("Can't write prj file '" + file.getAbsolutePath() + "'.");
176
        }
177
    }
168 178

  
169 179
	/**
170 180
	 * Writes one pixel in the destination buffer
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/DefaultRasterStore.java
1115 1115
				return providerParams;
1116 1116
			}
1117 1117
		} catch (Exception e) {
1118
		    logger.warn("Error initializing persistent parameters", e);
1118 1119
			return null;
1119 1120
		}
1120 1121
		return null;
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/writer/DefaultRasterWriter.java
22 22
package org.gvsig.raster.impl.store.writer;
23 23

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

  
28
import org.apache.commons.io.FilenameUtils;
29
import org.cresques.cts.ICRSFactory;
27 30
import org.cresques.cts.IProjection;
31
import org.slf4j.Logger;
32
import org.slf4j.LoggerFactory;
33

  
28 34
import org.gvsig.fmap.dal.coverage.RasterLocator;
29 35
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
30 36
import org.gvsig.fmap.dal.coverage.datastruct.Params;
......
70 76
	protected FileUtils                  fileUtil       = RasterLocator.getManager().getFileUtils();
71 77
	protected RasterUtils                rasterUtil     = RasterLocator.getManager().getRasterUtils();
72 78
	protected DefaultProviderServices    pInfo          = (DefaultProviderServices)RasterLocator.getManager().getProviderServices();
73
	
74 79

  
80
    private static final Logger logger = LoggerFactory.getLogger(DefaultRasterWriter.class);
81

  
82

  
75 83
	/**
76 84
	 * Devuelve el identificador del driver
77 85
	 * @return Identificador del driver
......
180 188
	public void setCancellableRasterDriver(ExternalCancellable cancellable) {
181 189
		this.extCancellable = cancellable;
182 190
	}
191

  
192
    protected void savePrjFile(File dataFile, IProjection proj){
193
        File file = new File(FilenameUtils.removeExtension(dataFile.getAbsolutePath())+".prj");
194
        try {
195
            String export = proj.export(ICRSFactory.FORMAT_WKT_ESRI);
196
            if(export!=null){
197
                org.apache.commons.io.FileUtils.writeStringToFile(file, export);
198
            }
199
        } catch (Exception e) {
200
            logger.info("Can't write prj file '" + file.getAbsolutePath() + "'.");
201
        }
202
    }
183 203
}
org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/store/AbstractRasterDataParameters.java
52 52

  
53 53
	protected IProjection          crs                    = null;
54 54

  
55

  
55
	/**
56
	 * @param definition
57
	 */
56 58
	public static void registerDynClass(DynStruct definition) {
57 59
		definition.addDynFieldString(FIELD_URI)
58 60
		.setDescription("Uniform Resource Identifier (File name or URL)")
......
104 106
		setURI(par.getURI());
105 107
	}
106 108

  
109
	/**
110
	 *
111
	 */
107 112
	public AbstractRasterDataParameters() {
108 113
		super();
109 114
	}
org.gvsig.raster.gdal/trunk/org.gvsig.raster.gdal/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalWriter.java
25 25
import java.awt.geom.Point2D;
26 26
import java.io.File;
27 27
import java.io.IOException;
28
import java.sql.Savepoint;
28 29
import java.util.ArrayList;
29 30

  
31
import org.apache.commons.io.FileUtils;
32
import org.apache.commons.io.FilenameUtils;
33
import org.cresques.cts.ICRSFactory;
30 34
import org.cresques.cts.IProjection;
35
import org.slf4j.Logger;
36
import org.slf4j.LoggerFactory;
37

  
31 38
import org.gvsig.fmap.dal.coverage.RasterLibrary;
32 39
import org.gvsig.fmap.dal.coverage.RasterLocator;
33 40
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
......
36 43
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
37 44
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException;
38 45
import org.gvsig.fmap.dal.coverage.store.DataServerWriter;
46
import org.gvsig.jgdal.GdalBuffer;
39 47
import org.gvsig.jgdal.GdalDataset;
40
import org.gvsig.jgdal.GdalBuffer;
41 48
import org.gvsig.jgdal.GdalDriver;
42 49
import org.gvsig.jgdal.GdalException;
43 50
import org.gvsig.jgdal.GdalRasterBand;
......
50 57
import org.gvsig.raster.gdal.io.features.Jpeg2000Features;
51 58
import org.gvsig.raster.gdal.io.features.PNM_PgmFeatures;
52 59
import org.gvsig.raster.gdal.io.features.PNM_PpmFeatures;
53
import org.gvsig.raster.gdal.io.features.RMFFeatures;
54 60
import org.gvsig.raster.impl.buffer.DefaultDataServerWriter;
55 61
import org.gvsig.raster.impl.buffer.RasterBuffer;
56 62
import org.gvsig.raster.impl.process.RasterTask;
......
83 89
 */
84 90
public class GdalWriter extends DefaultRasterWriter {
85 91

  
92
    private static final Logger logger = LoggerFactory.getLogger(GdalWriter.class);
93

  
94
	/**
95
	 *
96
	 */
86 97
	public static void register() {
87 98
		DefaultProviderServices pInfo = (DefaultProviderServices)RasterLocator.getManager().getProviderServices();
88 99
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
......
108 119

  
109 120
		point.append("rst", "", GdalWriter.class);
110 121
		pInfo.getFileFeature().put("rst", new IDRISIFeatures());
111
		
122

  
112 123
		point.append("jp2", "", GdalWriter.class);
113 124
		pInfo.getFileFeature().put("jp2", new Jpeg2000Features());
114 125

  
......
134 145

  
135 146
	/**
136 147
	 * Carga los par?metros de este driver.
148
	 * @param ident
137 149
	 */
138 150
	public void loadParams(String ident) {
139 151
		WriteFileFormatFeatures wfff = (WriteFileFormatFeatures)pInfo.getFileFeature().get(ident);
140 152
		wfff.loadParams();
141 153
		driverParams = (ParamsImpl)wfff.getParams();
142 154
	}
143
	
155

  
144 156
	public String getProviderName() {
145 157
		return GdalProvider.NAME;
146 158
	}
147 159

  
148 160
	/**
149 161
	 * Constructor para la obtenci?n de par?metros del driver
150
	 * @param drvType        Tipo de driver
162
	 * @param fileName
151 163
	 */
152 164
	public GdalWriter(String fileName) {
153 165
		ident = fileUtil.getExtensionFromFileName(fileName);
......
159 171
	/**
160 172
	 * Constructor para salvar datos servidos por el cliente
161 173
	 * @param dataWriter       	Objeto servidor de datos para el driver de escritura
162
	 * @param outFilename      	Fichero de salida
163
	 * @param blockSize        	Tama?o de bloque
164
	 * @param Extent           	extent
165
	 * @param compresion	   	Compresi?n si la tiene
174
	 * @param outFileName      	Fichero de salida
175
	 * @param nBands            N?mero de bandas
176
	 * @param at                Transformaci?n afin
166 177
	 * @param outSizeX		  	Tama?o de salida en X
167 178
	 * @param outSizeY			Tama?o de salida en Y
168 179
	 * @param dataType			Tipo de dato
180
	 * @param params
181
	 * @param proj
169 182
	 * @throws GdalException
170 183
	 * @throws IOException
171 184
	 */
......
184 197
	/**
185 198
	 * Constructor para salvar datos servidos por el cliente
186 199
	 * @param dataWriter       	Objeto servidor de datos para el driver de escritura
200
	 * @param outFileName
201
	 * @param nBands
202
	 * @param at
187 203
	 * @param outFilename      	Fichero de salida
188
	 * @param blockSize        	Tama?o de bloque
189
	 * @param Extent           	extent
190
	 * @param compresion	   	Compresi?n si la tiene
191 204
	 * @param outSizeX		  	Tama?o de salida en X
192 205
	 * @param outSizeY			Tama?o de salida en Y
193 206
	 * @param dataType			Tipo de dato
207
	 * @param params
208
	 * @param proj
194 209
	 * @param geo				Flag que dice si se salva con georreferenciaci?n o sin ella
195 210
	 * @throws GdalException
196 211
	 * @throws IOException
......
310 325
		anchoResto = sizeWindowY - (nBlocks * blockSize);
311 326
	}
312 327

  
313
	public void anotherFile(String fileName)throws GdalException {
328
	/**
329
	 * @param fileName
330
	 * @throws GdalException
331
	 */
332
	public void anotherFile(String fileName) throws GdalException {
314 333
		dstDataset = drv.create(fileName, sizeWindowX, sizeWindowY,
315 334
				nBands, GdalDataSource.getGdalTypeFromRasterBufType(dataType), gdalParamsFromRasterParams(driverParams));
316 335
	}
......
389 408
				//No se est? escribiendo ...
390 409
			}
391 410
		buftmp = null;
392
		
411

  
393 412
	}
394 413

  
395 414
	/**
......
499 518
	 * Escritura para tipo de dato ARGB.
500 519
	 * @param sizeY Alto del bloque que se escribe.
501 520
	 * @param posicionY Posici?ny a partir desde donde se comienza.
521
	 * @throws ProcessInterruptedException
522
	 * @throws OutOfMemoryError
502 523
	 */
503 524
	public void writeARGBBand(int sizeY, int posicionY)
504 525
			throws ProcessInterruptedException, OutOfMemoryError {
......
527 548
		} catch (GdalException e) {
528 549
			e.printStackTrace();
529 550
		}
530
		
551

  
531 552
		bufBands[0].buffByte = null;
532 553
		bufBands[1].buffByte = null;
533 554
		bufBands[2].buffByte = null;
......
623 644

  
624 645
	/**
625 646
	 * Realiza una copia en el formato especificado.
647
	 * @param driverDst
648
	 * @param dst
649
	 * @param src
650
	 * @param bstrict
651
	 * @param params
626 652
	 * @throws IOException
653
	 * @throws GdalException
627 654
	 */
628 655
	public static void createCopy(GdalDriver driverDst, String dst, String src,
629 656
			boolean bstrict, String[] params) throws IOException, GdalException {
......
667 694

  
668 695
		if (colorInterp != null)
669 696
			try {
670
				RasterLocator.getManager().getProviderServices().saveObjectToRmfFile(outFileName, DataStoreColorInterpretation.class, colorInterp);
697
                RasterLocator.getManager().getProviderServices()
698
                    .saveObjectToRmfFile(outFileName, DataStoreColorInterpretation.class, colorInterp);
671 699
			} catch (RmfSerializerException e) {
672 700
				throw new IOException("No se ha podido guardar la interpretacion de color");
673 701
			}
702

  
703
		this.savePrjFile(new File(this.outFileName), proj);
674 704
	}
675 705

  
676
	/**
677
	 * Cancela el salvado de datos.
678
	 * @throws GdalException
679
	 */
680 706
	public void writeClose() {
681 707
		try {
682 708
			if(bufBands != null) {
......
690 716
					bufBands[i].buffDouble = null;
691 717
				}
692 718
			}
693
				
719

  
694 720
			if(dstDataset != null)
695 721
				dstDataset.close();
696 722
		} catch (GdalException e) {
697 723
			e.printStackTrace();
698 724
		}
699 725
	}
700
	
726

  
701 727
	/**
702 728
	 * Cancela el salvado de datos.
703 729
	 */
......
734 760
	public void setParams(Params params) {
735 761
		if(params instanceof ParamsImpl)
736 762
			this.driverParams = (ParamsImpl)params;
737
		else 
763
		else
738 764
			return;
739 765

  
740 766
		int blockSize = 256;
......
747 773
			//Se queda con el valor de inicializaci?n
748 774
		}
749 775
	}
750
	
776

  
751 777
	/*
752 778
	 * (non-Javadoc)
753 779
	 * @see java.lang.Object#finalize()
......
756 782
		drv        = null;
757 783
		dstDataset = null;
758 784
		rband      = null;
759
		geot       = null; 
785
		geot       = null;
760 786
		if(bufBands != null) {
761 787
			for (int i = 0; i < bufBands.length; i++) {
762 788
				bufBands[i].buffAPalette = null;

Also available in: Unified diff