Revision 3255

View differences:

org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.8/org.gvsig.raster.gdal.io/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.gdal.io.DefaultGdalIOLibrary
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.8/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/overview/GdalOverviewBuilder.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.gdal.overview;
23

  
24
import org.gvsig.addo.BuildingOverviewsException;
25
import org.gvsig.addo.IOverviewIncrement;
26
import org.gvsig.addo.Jaddo;
27
import org.gvsig.addo.WritingException;
28
import org.gvsig.fmap.dal.coverage.exception.OverviewException;
29
import org.gvsig.fmap.dal.coverage.process.BaseIncrementableTask;
30
import org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder;
31

  
32
/**
33
 * Servicios ofrecidos por el proceso de construcci?n de overviews. Esta
34
 * implementaci?n usa gdal para construir las overviews.
35
 * 
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class GdalOverviewBuilder implements OverviewBuilder {
39
	private Jaddo        build         = new Jaddo();
40
	private int          value         = 0;
41

  
42
	/**
43
	 * Bindings between an IOverviewIncrement and a BaseIncrementableTask
44
	 * @author Nacho Brodin (nachobrodin@gmail.com)
45
	 */
46
	class ProcessBinding implements IOverviewIncrement {
47
		private BaseIncrementableTask  task = null;
48
		
49
		public ProcessBinding(BaseIncrementableTask task) {
50
			this.task = task;	
51
		}
52
		
53
		public int getPercent() {
54
			return task.getPercent();
55
		}
56

  
57
		public void setPercent(int value) {
58
			task.setPercent(value);
59
		}
60
	}
61
	
62
	/*
63
	 * (non-Javadoc)
64
	 * @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#buildOverviews(int, java.lang.String, int[])
65
	 */
66
	public void buildOverviews(int resamplingAlg, String file, int[] overviews)
67
			throws OverviewException {
68
		try {
69
			build.buildOverviews(resamplingAlg, file, overviews);
70
		} catch (BuildingOverviewsException e) {
71
			throw new OverviewException("Error building overviews", e);
72
		} catch (WritingException e) {
73
			throw new OverviewException("Error writing overviews", e);
74
		}
75
	}
76

  
77
	/*
78
	 * (non-Javadoc)
79
	 * @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#getPercent()
80
	 */
81
	public int getPercent() {
82
		return value;
83
	}
84

  
85
	/*
86
	 * (non-Javadoc)
87
	 * @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#setIncrementListener(org.gvsig.addo.IOverviewIncrement)
88
	 */
89
	public void setIncrementListener(BaseIncrementableTask incr) {
90
		build.setIncrementListener(new ProcessBinding(incr));
91
	}
92

  
93
	/*
94
	 * (non-Javadoc)
95
	 * @see org.gvsig.fmap.dal.coverage.process.overview.OverviewBuilder#setPercent(int)
96
	 */
97
	public void setPercent(int value) {
98
		this.value = value;
99
	}
100
}
0 101

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.8/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/PngWriter.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.gdal.io;
23

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

  
28
import org.cresques.cts.IProjection;
29
import org.gvsig.fmap.dal.coverage.RasterLocator;
30
import org.gvsig.fmap.dal.coverage.datastruct.Params;
31
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
32
import org.gvsig.fmap.dal.coverage.store.DataServerWriter;
33
import org.gvsig.jgdal.Gdal;
34
import org.gvsig.jgdal.GdalDriver;
35
import org.gvsig.jgdal.GdalException;
36
import org.gvsig.raster.gdal.io.features.PngFeatures;
37
import org.gvsig.raster.impl.store.WriteFileFormatFeatures;
38
import org.gvsig.raster.impl.store.writer.DefaultRasterWriter;
39
import org.gvsig.raster.util.DefaultProviderServices;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.extensionpoint.ExtensionPoint;
42
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
43
/**
44
 * Driver para la escritura de Png.
45
 * Este driver utiliza GdalWriter para salvar Png.
46
 * La escritura de un png no es posible utilizando un servidor de datos
47
 * como el que usan los drivers comunes por lo que ser? necesario salvar antes
48
 * a Tif con el driver de Gdal para posteriormente convertir la imagen completa
49
 * a png. El problema que tiene es el mismo del jpg y es que el dataset solo soporta la
50
 * escritura rw y no rw+.
51
 *
52
 * @version 22/07/2008
53
 * @author Nacho Brodin (nachobrodin@gmail.com)
54
 */
55
public class PngWriter extends DefaultRasterWriter {
56

  
57
	// Datos de registro de drivers
58
	public static void register() {
59
		DefaultProviderServices pInfo = (DefaultProviderServices)RasterLocator.getManager().getProviderServices();
60
		ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager();
61
		ExtensionPoint point=extensionPoints.get("RasterWriter");
62
		point.append("png", "", PngWriter.class);
63
		pInfo.getFileFeature().put("png", new PngFeatures());
64
	}
65

  
66
	private GdalWriter gdalWriter = null;
67
	private String     outTif     = null;
68
	private String     outPng     = null;
69

  
70
	/**
71
	 * Carga los par?metros de este driver.
72
	 */
73
	public void loadParams(String ident) {
74
		WriteFileFormatFeatures wfff = (WriteFileFormatFeatures) pInfo.getFileFeature().get(ident);
75
		wfff.loadParams();
76
		driverParams = wfff.getParams();
77
	}
78
	
79
	/*
80
	 * (non-Javadoc)
81
	 * @see org.gvsig.fmap.dal.coverage.store.RasterWriter#getProviderName()
82
	 */
83
	public String getProviderName() {
84
		return GdalProvider.NAME;
85
	}
86

  
87
	/**
88
	 * Constructor para la obtenci?n de par?metros del driver
89
	 * @param drvType Tipo de driver
90
	 */
91
	public PngWriter(String fileName) {
92
		ident = fileUtil.getExtensionFromFileName(fileName);
93
		driver = ((WriteFileFormatFeatures) pInfo.getFileFeature().get(ident)).getDriverName();
94
		gdalWriter = new GdalWriter(fileName);
95

  
96
		loadParams(ident);
97
	}
98

  
99
	/**
100
	 * Constructor para salvar datos servidos por el cliente
101
	 * @param dataWriter Objeto servidor de datos para el driver de escritura
102
	 * @param outSizeX N?mero de pixels en X de la imagen de salida
103
	 * @param outSizeY N?mero de pixels en Y de la imagen de salida
104
	 * @param outFilename Fichero de salida
105
	 * @param extentMaxX Posici?n en X m?xima del extent
106
	 * @param extentMinX Posici?n en X m?nima del extent
107
	 * @param extentMaxY Posici?n en Y m?xima del extent
108
	 * @param extentMinY Posici?n en Y m?nima del extent
109
	 * @param nBands N?mero de bandas
110
	 * @param drvType Tipo de driver
111
	 * @throws GdalException
112
	 * @throws IOException
113
	 */
114
	public PngWriter(DataServerWriter dataWriter,
115
							String outFileName,
116
							Integer nBands,
117
							AffineTransform at,
118
							Integer outSizeX,
119
							Integer outSizeY,
120
							Integer dataType,
121
							Params params,
122
							IProjection proj,
123
							Boolean geo)throws GdalException, IOException  {
124
		ident = fileUtil.getExtensionFromFileName(outFileName);
125
		driver = ((WriteFileFormatFeatures) pInfo.getFileFeature().get(ident)).getDriverName();
126
		outPng = outFileName;
127
		outTif = outFileName.substring(0, outFileName.lastIndexOf("."));
128
		outTif += ".tif";
129
		this.at = at;
130

  
131
		gdalWriter = new GdalWriter(dataWriter, outTif, nBands, at, outSizeX, outSizeY, dataType, params, proj, geo);
132
		if (params == null)
133
			loadParams(ident);
134
		else
135
			this.driverParams = params;
136
	}
137

  
138
	/**
139
	 * Asigna el tipo de driver con el que se salvar? la imagen
140
	 * @param drvType Tipo de driver
141
	 */
142
	public void setDriverType(String drvType) {
143
		gdalWriter.setDriverType(drvType);
144
	}
145

  
146
		/**
147
	 * Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
148
	 * @throws IOException
149
	 */
150
	public void fileWrite() throws IOException, ProcessInterruptedException {
151
		gdalWriter.fileWrite();
152
	}
153

  
154
	/**
155
	 * Realiza una copia en el formato especificado.
156
	 * @throws IOException
157
	 */
158
	public static void createCopy(GdalDriver driverDst, String dst, String src,
159
			boolean bstrict, String[] params) throws IOException, GdalException {
160
		GdalWriter.createCopy(driverDst, dst, src, bstrict, params);
161
	}
162

  
163
	/**
164
	 * Realiza la escritura de datos con los datos que le pasa el cliente.
165
	 * @throws IOException
166
	 */
167
	public void dataWrite() throws IOException, ProcessInterruptedException {
168
		if(colorInterp != null)
169
			gdalWriter.setColorBandsInterpretation(colorInterp.getValues());
170
		gdalWriter.dataWrite();
171
		if (gdalWriter.isWrite()) {
172
			gdalWriter.writeClose();
173
			if (outTif != null) {
174
				GdalDriver driver = null;
175
				try {
176
					driver = Gdal.getDriverByName("PNG");
177
					GdalWriter.createCopy(driver, outPng, outTif, false, gdalWriter.gdalParamsFromRasterParams(driverParams));
178
				} catch (GdalException exc) {
179
					throw new IOException("No se ha podido obtener el driver.");
180
				}
181
				File file = new File(outTif);
182
				file.delete();
183
			}
184
		}
185
	}
186

  
187
	/**
188
	 * Cancela el salvado de datos.
189
	 */
190
	public void writeCancel() {
191
		gdalWriter.setWrite(false);
192
	}
193

  
194
	/*
195
	 * (non-Javadoc)
196
	 * @see org.gvsig.raster.dataset.GeoRasterWriter#setParams(org.gvsig.raster.dataset.Params)
197
	 */
198
	public void setParams(Params params) {
199
		driverParams = params;
200
		if (gdalWriter != null)
201
			gdalWriter.setParams(params);
202
	}
203

  
204
	/**
205
	 * Cierra el compresor ecw.
206
	 * @throws GdalException
207
	 */
208
	public void writeClose() {
209
	// El close del tif se hizo en dataWrite
210
	}
211

  
212
	public void setWkt(String wkt) {}
213
}
0 214

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.8/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalProvider.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.gdal.io;
23

  
24
import java.awt.geom.AffineTransform;
25
import java.io.BufferedReader;
26
import java.io.File;
27
import java.io.FileNotFoundException;
28
import java.io.FileReader;
29
import java.io.IOException;
30

  
31
import org.gvsig.fmap.dal.DALFileLocator;
32
import org.gvsig.fmap.dal.DALLocator;
33
import org.gvsig.fmap.dal.DataStore;
34
import org.gvsig.fmap.dal.coverage.RasterLocator;
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.exception.BandAccessException;
38
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
39
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
40
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
41
import org.gvsig.fmap.dal.coverage.exception.ParsingException;
42
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
43
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
44
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
45
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
46
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
47
import org.gvsig.jgdal.GdalException;
48
import org.gvsig.metadata.MetadataLocator;
49
import org.gvsig.raster.cache.tile.provider.TileServer;
50
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
51
import org.gvsig.raster.impl.datastruct.ExtentImpl;
52
import org.gvsig.raster.impl.provider.AbstractRasterProvider;
53
import org.gvsig.raster.impl.provider.RasterProvider;
54
import org.gvsig.raster.impl.provider.tile.FileTileServer;
55
import org.gvsig.raster.impl.store.AbstractRasterDataParameters;
56
import org.gvsig.raster.impl.store.DefaultRasterStore;
57
import org.gvsig.raster.impl.store.DefaultStoreFactory;
58
import org.gvsig.raster.impl.store.properties.DataStoreMetadata;
59
import org.gvsig.tools.ToolsLocator;
60
import org.gvsig.tools.dynobject.DynObject;
61
import org.gvsig.tools.extensionpoint.ExtensionPoint;
62
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
63
import org.slf4j.Logger;
64
import org.slf4j.LoggerFactory;
65
/**
66
 * This class represents the data access for gdal formats.
67
 *
68
 * @author Nacho Brodin (nachobrodin@gmail.com)
69
 */
70
public class GdalProvider extends AbstractRasterProvider {
71
	public static String        NAME                     = "Gdal Store";
72
	public static String        DESCRIPTION              = "Gdal Raster file";
73
	public static final String  METADATA_DEFINITION_NAME = "GdalStore";
74
	private static final Logger logger                   = LoggerFactory.getLogger(GdalProvider.class);
75
	
76
	public static final String  FORMAT_GTiff    = "GTiff";
77
	public static final String  FORMAT_VRT      = "VRT";
78
	public static final String  FORMAT_NITF     = "NITF";
79
	public static final String  FORMAT_HFA      = "HFA";
80
	public static final String  FORMAT_ELAS     = "ELAS";
81
	public static final String  FORMAT_MEM      = "MEM";
82
	public static final String  FORMAT_BMP      = "BMP";
83
	public static final String  FORMAT_PCIDSK   = "PCIDSK";
84
	public static final String  FORMAT_ILWIS    = "ILWIS";
85
	public static final String  FORMAT_HDF4     = "HDF4Image";
86
	public static final String  FORMAT_PNM      = "PNM";
87
	public static final String  FORMAT_ENVI     = "ENVI";
88
	public static final String  FORMAT_EHDR     = "EHdr";
89
	public static final String  FORMAT_PAUX     = "PAux";
90
	public static final String  FORMAT_MFF      = "MFF";
91
	public static final String  FORMAT_MFF2     = "MFF2";
92
	public static final String  FORMAT_BT       = "BT";
93
	public static final String  FORMAT_IDA      = "IDA";
94
	public static final String  FORMAT_RMF      = "RMF";
95
	public static final String  FORMAT_RST      = "RST";
96
	public static final String  FORMAT_LEVELLER = "Leveller";
97
	public static final String  FORMAT_TERRAGEN = "Terragen";
98
	public static final String  FORMAT_ERS      = "ERS";
99
	public static final String  FORMAT_INGR     = "INGR";
100
	public static final String  FORMAT_GSAG     = "GSAG";
101
	public static final String  FORMAT_GSBG     = "GSBG";
102
	public static final String  FORMAT_ADRG     = "ADRG";
103
	public static final String  FORMAT_JP2      = "JPEG2000";
104
	public static final String  FORMAT_GRD      = "GRD";
105
	public static final int     BAND_HEIGHT     = 64;
106
	protected GdalNative        file            = null;
107
	private Extent              viewRequest     = null;
108
	protected static String[]   formatList      = null;
109
	
110
	public static void register() {
111
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
112
		registerFormats();
113
		
114
		ExtensionPoint point = extensionPoints.get("DefaultRasterProvider");
115
		point.append("reader", GdalProvider.NAME, GdalProvider.class);
116
		
117
		RasterLocator.getManager().getProviderServices().registerFileProvidersTiled(GdalProvider.class);
118
		
119
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
120
		if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
121
			dataman.registerStoreProvider(NAME,
122
					GdalProvider.class, GdalDataParameters.class);
123
		}
124
		
125
		if(DALFileLocator.getFilesystemServerExplorerManager() != null)
126
			DALFileLocator.getFilesystemServerExplorerManager().registerProvider(
127
					NAME, DESCRIPTION,
128
					GdalFilesystemServerExplorer.class);
129
		
130
		dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
131
	}
132
	
133
	private static void registerFormats() {
134
		formatList      = new String[] {
135
				"bmp", 
136
				"gif",
137
				"tif",
138
				"tiff",
139
				"jpg",
140
				"jpeg",
141
				"png",
142
				"vrt",
143
				"dat", // Envi
144
				"lan", // Erdas
145
				"gis", // Erdas
146
				"img", // Erdas
147
				"pix", // PCI Geomatics
148
				"aux", // PCI Geomatics
149
				"adf", // ESRI Grids
150
				"mpr", // Ilwis
151
				"mpl", // Ilwis
152
				"map", // PC Raster
153
				"asc",
154
				"pgm", //Ficheros PNM en escala de grises
155
				"ppm", //Ficheros PNM en RGB
156
				"rst", //IDRISIS
157
				"rmf", //Raster Matrix Format
158
				"nos",
159
				"kap",
160
				"hdr",
161
				"raw",
162
				"ers",
163
				"xml",
164
				"grd",
165
				"txt"/*,
166
				"jp2"*/};
167
		for (int i = 0; i < formatList.length; i++) 
168
			RasterLocator.getManager().getProviderServices().addFormat(formatList[i], GdalProvider.class);
169
	}
170
	
171
	public String[] getFormatList() {
172
		return formatList;
173
	}
174
	
175
	/**
176
	 * Returns true if the extension is supported and false if doesn't
177
	 * @param ext
178
	 * @return
179
	 */
180
	public boolean isExtensionSupported(String ext) {
181
		if(ext.indexOf(".") != -1)
182
			ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length());
183
		for (int i = 0; i < formatList.length; i++) {
184
			if(formatList[i].compareTo(ext) == 0)
185
				return true;
186
		}
187
		return false;
188
	}
189
	
190
	/**
191
	 * Mandatory constructor to instantiate an empty provider
192
	 */
193
	public GdalProvider() {
194
	}
195
	
196
	/**
197
	 * Constructor. Abre el dataset.
198
	 * @param proj Proyecci?n
199
	 * @param fName Nombre del fichero
200
	 * @throws NotSupportedExtensionException
201
	 */
202
	public GdalProvider(String params) throws NotSupportedExtensionException {
203
		super(params);
204
		if(params instanceof String) {
205
			GdalDataParameters p = new GdalDataParameters();
206
			p.setURI((String)params);
207
			super.init(p, null, ToolsLocator.getDynObjectManager()
208
					.createDynObject(
209
							MetadataLocator.getMetadataManager().getDefinition(
210
									DataStore.METADATA_DEFINITION_NAME)));
211
			init(p, null);
212
		}
213
	}
214
	
215
	public GdalProvider (GdalDataParameters params,
216
			DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
217
		super(params, storeServices, ToolsLocator.getDynObjectManager()
218
				.createDynObject(
219
						MetadataLocator.getMetadataManager().getDefinition(
220
								DataStore.METADATA_DEFINITION_NAME)));
221
		init(params, storeServices);
222
	}
223
	
224
	public GdalProvider(AbstractRasterDataParameters params,
225
			DataStoreProviderServices storeServices, DynObject metadata) {
226
		super(params, storeServices, metadata);
227
	}
228
	
229
	/**
230
	 * Creates file references and loads structures with the information and metadata
231
	 * @param params load parameters
232
	 * @throws NotSupportedExtensionException
233
	 */
234
	public void init (AbstractRasterDataParameters params,
235
			DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
236
		try {
237
			setParam(storeServices, params);
238
			validRmf(params.getURI());
239
			setFName(translateFileName(params.getURI()));
240
			file = new GdalNative(translateFileName(params.getURI()));
241
			setColorInterpretation(file.colorInterpr);
242
			setColorTable(file.palette);
243
			noData = file.getNoDataValue();
244
			String wktProjection = file.getProjectionRef();
245
			if(wktProjection != null && wktProjection != "") {
246
				try {
247
					if(RasterLocator.getManager().isCRSUtilSupported())
248
						proj = RasterLocator.getManager().getCRSUtils().convertWktToIProjection(wktProjection);
249
				} catch (Exception e) {
250
					logger.info("Error reading WKT from the raster provider", e);
251
				}
252
			}
253
			//CrsWkt crs = new CrsWkt(wktProjection);
254
			//IProjection proj = CRSFactory.getCRS("EPSG:23030");
255
			ownTransformation = file.getOwnTransformation();
256
			externalTransformation = (AffineTransform)ownTransformation.clone();
257
			load();
258

  
259
			if(file != null)
260
				bandCount = file.getRasterCount();
261
		} catch (GdalException e) {
262
			throw new NotSupportedExtensionException("Extension not supported", e);
263
		} catch(Exception e) {
264
			System.out.println("Error en GdalOpen");
265
			e.printStackTrace();
266
			file = null;
267
		}
268

  
269
		//Obtenemos el tipo de dato de gdal y lo convertimos el de RasterBuf
270
		int[] dt = new int[file.getDataType().length];
271
		for (int i = 0; i < dt.length; i++)
272
			dt[i] = GdalNative.getRasterBufTypeFromGdalType(file.getDataType()[i]);
273
		setDataType(dt);
274

  
275
		super.init();
276

  
277
		try {
278
			loadFromRmf(getRmfBlocksManager());
279
		} catch (ParsingException e) {
280
			//No lee desde rmf
281
			logger.debug("Problems reading from the RMF file", e);
282
		}
283
	}
284

  
285
	/**
286
	 * Comprueba si el fichero abierto es un RasterMetaFile o una imagen
287
	 * raster.
288
	 * @throws GdalException
289
	 */
290
	private void validRmf(String file) throws GdalException {
291
		if(file.endsWith(".rmf")) {
292
			File f = new File(file);
293
			try {
294
				FileReader fr = new FileReader(f);
295
				BufferedReader br = new BufferedReader(fr);
296
				char[] buffer = new char[5];
297
				br.read(buffer);
298
				StringBuffer st = new StringBuffer(new String(buffer));
299
				br.close();
300
				fr.close();
301
				if(st.toString().equals("<?xml"))
302
					throw new GdalException("RasterMetaFile");
303
			} catch (FileNotFoundException e) {
304
				throw new GdalException("File Not Found");
305
			} catch (IOException e) {
306
				throw new GdalException("");
307
			}
308
		}
309
	}
310

  
311
	public RasterProvider load() {
312
		return this;
313
	}
314
	
315
	public boolean isOpen() {
316
		if(file != null && file.isOpen())
317
			return true;
318
		return false;
319
	}
320

  
321
	public String translateFileName(String fileName) {
322
		if(fileName.endsWith("hdr"))
323
			return fileName.substring(0, fileName.lastIndexOf("."));
324
		return fileName;
325
	}
326

  
327
	/**
328
	 * Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci?n
329
	 * de la vista asignada ya que la petici?n viene en coordenadas del fichero .rmf y la vista (v)
330
	 * ha de estar en coordenadas del fichero.
331
	 */
332
	public void setView(Extent e) {
333
		viewRequest = new ExtentImpl(e);
334
	}
335

  
336
	public Extent getView() {
337
		return viewRequest;
338
	}
339

  
340
	public double getWidth() {
341
		return file.width;
342
	}
343

  
344
	public double getHeight() {
345
		return file.height;
346
	}
347

  
348
	/**
349
	 * Read a line from the file
350
	 * @param line
351
	 * @param band
352
	 * @return
353
	 * @throws InvalidSetViewException
354
	 * @throws FileNotOpenException
355
	 * @throws RasterDriverException
356
	 * @Deprecated This operation is deprecated because is not useful and in the future
357
	 * it will not be maintained. The abstract operation has dissapear
358
	 */
359
	public Object readCompleteLine(int line, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
360
		if(line > this.getHeight() || band > this.getBandCount())
361
			throw new InvalidSetViewException("Request out of grid");
362

  
363
		try{
364
			return file.readCompleteLine(line, band);
365
		}catch(GdalException e){
366
			throw new RasterDriverException("Error reading data from Gdal library");
367
		}
368
	}
369

  
370
	public Object readBlock(int pos, int blockHeight, double scale)
371
		throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
372
		if(pos < 0)
373
			throw new InvalidSetViewException("Request out of grid");
374

  
375
		if((pos + blockHeight) > getHeight())
376
			blockHeight = Math.abs(((int)getHeight()) - pos);
377
		try{
378
			return file.readBlock(pos, blockHeight, scale);
379
		}catch(GdalException e){
380
			throw new RasterDriverException("Error reading data from Gdal library");
381
		}
382
	}
383

  
384
	public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
385
		if(file != null){
386
			if(x < 0 || y < 0 || x >= file.width || y >= file.height)
387
				throw new InvalidSetViewException("Request out of grid");
388
			Object[] data = file.getData(x, y);
389
			return data[band];
390
		}
391
		throw new FileNotOpenException("GdalNative not exist");
392
	}
393

  
394
	@Override
395
	public void loadBuffer(SpiRasterQuery q) 
396
			throws ProcessInterruptedException, RasterDriverException {
397
		setView(q.getAdjustedRequestBoundingBox());
398
		
399
		try {
400
			file.readWindow(q.getBufferForProviders(), 
401
					q.getBandList(), 
402
					q.getAdjustedRequestBoundingBox(), 
403
					q.getAdjustedRequestPxWindow(),
404
					q.getTaskStatus());
405
		} catch (GdalException e) {
406
			throw new RasterDriverException("Error reading data", e);
407
		}
408
		
409
	}
410
	
411
	public int getBlockSize(){
412
		if(file != null)
413
			return file.getBlockSize();
414
		else
415
			return 0;
416
	}
417

  
418
	public DataStoreMetadata getMetadata() {
419
		if(file != null)
420
			return file.metadata;
421
		else
422
			return null;
423
	}
424

  
425
	public Transparency getTransparency() {
426
		return file.fileTransparency;
427
	}
428

  
429
	public boolean isGeoreferenced() {
430
		if(file != null)
431
			return file.georeferenced;
432
		else
433
			return false;
434
	}
435

  
436
	/**
437
	 * Informa de si el driver ha supersampleado en el ?ltimo dibujado. Es el driver el que colocar?
438
	 * el valor de esta variable cada vez que dibuja.
439
	 * @return true si se ha supersampleado y false si no se ha hecho.
440
	 */
441
	public boolean isSupersampling() {
442
		if(file != null)
443
			return file.isSupersampling;
444
		else
445
			return false;
446
	}
447

  
448
	public GdalNative getNative(){
449
		return file;
450
	}
451

  
452
	public void setAffineTransform(AffineTransform t){
453
		super.setAffineTransform(t);
454
		file.setExternalTransform(t);
455
	}
456

  
457
	public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
458
		if(band >= getBandCount())
459
			throw new BandAccessException("Wrong band");
460
		try {
461
			return file.getRasterBand(band + 1).getOverviewCount();
462
		} catch (GdalException e) {
463
			throw new RasterDriverException("");
464
		}
465
	}
466

  
467
	public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
468
		if (band >= getBandCount())
469
			throw new BandAccessException("Wrong band");
470
		try {
471
			if (overview >= file.getRasterBand(band + 1).getOverviewCount())
472
				throw new BandAccessException("Wrong overview count");
473
			return file.getRasterBand(band + 1).getOverview(overview).getRasterBandXSize();
474
		} catch (GdalException e) {
475
			throw new RasterDriverException("");
476
		}
477
	}
478

  
479
	public int getOverviewHeight(int band, int overview) throws BandAccessException, RasterDriverException {
480
		if (band >= getBandCount())
481
			throw new BandAccessException("Wrong band");
482
		try {
483
			if (overview >= file.getRasterBand(band + 1).getOverviewCount())
484
				throw new BandAccessException("Wrong overview count");
485
			return file.getRasterBand(band + 1).getOverview(overview).getRasterBandYSize();
486
		} catch (GdalException e) {
487
			throw new RasterDriverException("");
488
		}
489
	}
490

  
491
	public boolean isOverviewsSupported() {
492
		return true;
493
	}
494

  
495
	public boolean isReproyectable() {
496
		return true;
497
	}
498
	
499
	public boolean needEnhanced() {
500
		return (getDataType()[0] != Buffer.TYPE_BYTE); 
501
		//Desconozco pq raz?n estaba esta condici?n. Quiz?s haya que volver a a?adirla
502
		//Eliminada 30/5/2013
503
		//|| (getBandCount() == 1 && getDataType()[0] == Buffer.TYPE_BYTE));
504
	}
505

  
506
	public String getProviderName() {
507
		return NAME;
508
	}
509
	     
510
	public void setStatus(RasterProvider provider) {
511
		if(provider instanceof GdalProvider) {
512
			//Not implemented yet
513
		}
514
	}
515
	
516
	public TileServer getTileServer() {
517
		if(tileServer == null) {
518
			DefaultRasterStore store = new DefaultRasterStore();
519
			store.setProvider(this);
520
			tileServer = new FileTileServer(store);
521
		}
522
		return tileServer;
523
	}
524
	
525
	public void close() {
526
		if(file != null){
527
			file.dispose();
528
		}
529
		try {
530
			finalize();
531
		} catch (Throwable e) {
532
		}
533
	}
534
	
535
	protected void finalize() throws Throwable {
536
		file           = null;
537
		viewRequest    = null;
538
		if(formatList != null) {
539
			for (int i = 0; i < formatList.length; i++) {
540
				formatList[i] = null;
541
			}
542
			formatList = null;
543
		}
544
		super.finalize();
545
	}
546
}
0 547

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.8/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/JpegWriter.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.gdal.io;
23

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

  
28
import org.cresques.cts.IProjection;
29
import org.gvsig.fmap.dal.coverage.RasterLocator;
30
import org.gvsig.fmap.dal.coverage.datastruct.Params;
31
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
32
import org.gvsig.fmap.dal.coverage.store.DataServerWriter;
33
import org.gvsig.jgdal.Gdal;
34
import org.gvsig.jgdal.GdalDriver;
35
import org.gvsig.jgdal.GdalException;
36
import org.gvsig.raster.gdal.io.features.JpegFeatures;
37
import org.gvsig.raster.impl.store.WriteFileFormatFeatures;
38
import org.gvsig.raster.impl.store.writer.DefaultRasterWriter;
39
import org.gvsig.raster.util.DefaultProviderServices;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.extensionpoint.ExtensionPoint;
42
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
43
/**
44
 * Driver para la escritura de Jpeg.
45
 * Este driver utiliza GdalWriter para salvar Jpeg.
46
 * La escritura de un jpeg no es posible utilizando un servidor de datos
47
 * como el que usan los drivers comunes por lo que ser? necesario salvar antes
48
 * a Tif con el driver de Gdal para posteriormente convertir la imagen completa
49
 * a jpg.
50
 *
51
 * @version 22/07/2008
52
 * @author Nacho Brodin (nachobrodin@gmail.com)
53
 */
54
public class JpegWriter extends DefaultRasterWriter {
55

  
56
	// Datos de registro de drivers
57
	public static void register() {
58
		DefaultProviderServices pInfo = (DefaultProviderServices)RasterLocator.getManager().getProviderServices();
59
		ExtensionPointManager extensionPoints =ToolsLocator.getExtensionPointManager();
60
		ExtensionPoint point=extensionPoints.get("RasterWriter");
61
		point.append("jpg", "", JpegWriter.class);
62
		pInfo.getFileFeature().put("jpg", new JpegFeatures());
63
	}
64

  
65
	private GdalWriter gdalWriter = null;
66
	private String     outTif     = null;
67
	private String     outJpg     = null;
68

  
69
	/**
70
	 * Carga los par?metros de este driver.
71
	 */
72
	public void loadParams(String ident) {
73
		WriteFileFormatFeatures wfff = (WriteFileFormatFeatures) pInfo.getFileFeature().get(ident);
74
		wfff.loadParams();
75
		driverParams = wfff.getParams();
76
	}
77
	
78
	/*
79
	 * (non-Javadoc)
80
	 * @see org.gvsig.fmap.dal.coverage.store.RasterWriter#getProviderName()
81
	 */
82
	public String getProviderName() {
83
		return GdalProvider.NAME;
84
	}
85

  
86
	/**
87
	 * Constructor para la obtenci?n de par?metros del driver
88
	 * @param drvType Tipo de driver
89
	 */
90
	public JpegWriter(String fileName) {
91
		ident = fileUtil.getExtensionFromFileName(fileName);
92
		driver = ((WriteFileFormatFeatures) pInfo.getFileFeature().get(ident)).getDriverName();
93
		gdalWriter = new GdalWriter(fileName);
94

  
95
		loadParams(ident);
96
	}
97

  
98
	/**
99
	 * Constructor para salvar datos servidos por el cliente
100
	 * @param dataWriter Objeto servidor de datos para el driver de escritura
101
	 * @param outSizeX N?mero de pixels en X de la imagen de salida
102
	 * @param outSizeY N?mero de pixels en Y de la imagen de salida
103
	 * @param outFilename Fichero de salida
104
	 * @param extentMaxX Posici?n en X m?xima del extent
105
	 * @param extentMinX Posici?n en X m?nima del extent
106
	 * @param extentMaxY Posici?n en Y m?xima del extent
107
	 * @param extentMinY Posici?n en Y m?nima del extent
108
	 * @param nBands N?mero de bandas
109
	 * @param drvType Tipo de driver
110
	 * @throws GdalException
111
	 * @throws IOException
112
	 */
113
	public JpegWriter(DataServerWriter dataWriter,
114
							String outFileName,
115
							Integer nBands,
116
							AffineTransform at,
117
							Integer outSizeX,
118
							Integer outSizeY,
119
							Integer dataType,
120
							Params params,
121
							IProjection proj,
122
							Boolean geo)throws GdalException, IOException  {
123
		ident = fileUtil.getExtensionFromFileName(outFileName);
124
		driver = ((WriteFileFormatFeatures) pInfo.getFileFeature().get(ident)).getDriverName();
125
		outJpg = outFileName;
126
		outTif = outFileName.substring(0, outFileName.lastIndexOf("."));
127
		outTif += ".tif";
128

  
129
		gdalWriter = new GdalWriter(dataWriter, outTif, nBands, at, outSizeX, outSizeY, dataType, params, proj, geo);
130
		if (params == null)
131
			loadParams(ident);
132
		else
133
			this.driverParams = params;
134
	}
135

  
136
	/**
137
	 * Asigna el tipo de driver con el que se salvar? la imagen
138
	 * @param drvType Tipo de driver
139
	 */
140
	public void setDriverType(String drvType) {
141
		gdalWriter.setDriverType(drvType);
142
	}
143

  
144
	/**
145
	 * Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
146
	 * @throws IOException
147
	 */
148
	public void fileWrite() throws IOException, ProcessInterruptedException {
149
		gdalWriter.fileWrite();
150
	}
151

  
152
	/**
153
	 * Realiza una copia en el formato especificado.
154
	 * @throws IOException
155
	 */
156
	public static void createCopy(GdalDriver driverDst, String dst, String src, boolean bstrict, String[] params) throws IOException, GdalException {
157
		GdalWriter.createCopy(driverDst, dst, src, bstrict, params);
158
	}
159

  
160
	/**
161
	 * Realiza la escritura de datos con los datos que le pasa el cliente.
162
	 * @throws IOException
163
	 */
164
	public void dataWrite() throws IOException, ProcessInterruptedException {
165
		if (colorInterp != null)
166
			gdalWriter.setColorBandsInterpretation(colorInterp.getValues());
167
		gdalWriter.dataWrite();
168
		if (gdalWriter.isWrite()) {
169
			gdalWriter.writeClose();
170
			if (outTif != null) {
171
				GdalDriver driver = null;
172
				try {
173
					driver = Gdal.getDriverByName("JPEG");
174
					GdalWriter.createCopy(driver, outJpg, outTif, false, gdalWriter.gdalParamsFromRasterParams(driverParams));
175
				} catch (GdalException exc) {
176
					throw new IOException("No se ha podido obtener el driver.");
177
				}
178
				File file = new File(outTif);
179
				file.delete();
180
			}
181
		}
182
	}
183

  
184
	/**
185
	 * Cancela el salvado de datos.
186
	 */
187
	public void writeCancel() {
188
		gdalWriter.setWrite(false);
189
	}
190

  
191
	/*
192
	 * (non-Javadoc)
193
	 * @see org.gvsig.raster.dataset.GeoRasterWriter#setParams(org.gvsig.raster.dataset.Params)
194
	 */
195
	public void setParams(Params params) {
196
		driverParams = params;
197
		if (gdalWriter != null)
198
			gdalWriter.setParams(params);
199
	}
200

  
201
	/**
202
	 * Cierra el compresor ecw.
203
	 * @throws GdalException
204
	 */
205
	public void writeClose() {
206
	// El close del tif se hizo en dataWrite
207
	}
208

  
209
	public void setWkt(String wkt) {}
210
}
0 211

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.8/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalNewRasterStoreParameters.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.gdal.io;
23

  
24
import org.gvsig.raster.impl.store.AbstractNewRasterStoreParameters;
25

  
26
/**
27
 * Parameters for creating a Gdal store
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public class GdalNewRasterStoreParameters extends AbstractNewRasterStoreParameters {
31

  
32
	public String getDataStoreName() {
33
		return GdalProvider.NAME;
34
	}
35

  
36
	public String getDescription() {
37
		return GdalProvider.DESCRIPTION;
38
	}
39

  
40
}
0 41

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.8/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalFilesystemServerExplorer.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

  
23
/*
24
* AUTHORS (In addition to CIT):
25
* 2009 IVER T.I   {{Task}}
26
*/
27

  
28
package org.gvsig.raster.gdal.io;
29

  
30
import java.awt.geom.AffineTransform;
31
import java.io.File;
32
import java.io.FileInputStream;
33
import java.io.IOException;
34

  
35
import org.gvsig.fmap.dal.DALLocator;
36
import org.gvsig.fmap.dal.DataManager;
37
import org.gvsig.fmap.dal.DataServerExplorer;
38
import org.gvsig.fmap.dal.DataStoreParameters;
39
import org.gvsig.fmap.dal.NewDataStoreParameters;
40
import org.gvsig.fmap.dal.coverage.RasterLocator;
41
import org.gvsig.fmap.dal.coverage.datastruct.Params;
42
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
43
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
44
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
45
import org.gvsig.fmap.dal.coverage.store.DataServerWriter;
46
import org.gvsig.fmap.dal.coverage.store.RasterWriter;
47
import org.gvsig.fmap.dal.coverage.store.parameter.NewRasterStoreParameters;
48
import org.gvsig.fmap.dal.exception.CreateException;
49
import org.gvsig.fmap.dal.exception.DataException;
50
import org.gvsig.fmap.dal.exception.RemoveException;
51
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
52
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
53
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters;
54
import org.gvsig.tools.locator.LocatorException;
55

  
56
public class GdalFilesystemServerExplorer extends AbstractFilesystemServerExplorerProvider {
57
	
58
	public boolean canCreate() {
59
		return false;
60
	}
61

  
62
	public boolean canCreate(NewDataStoreParameters parameters) {
63
		return false;
64
	}
65

  
66
	public void create(NewDataStoreParameters parameters, boolean overwrite)
67
			throws CreateException {
68
		NewRasterStoreParameters p = null;
69
		if(parameters instanceof NewRasterStoreParameters)
70
			 p = (NewRasterStoreParameters)parameters;
71
		
72
		DataServerWriter dataWriter = p.getDataServer();
73
		if(dataWriter == null)
74
			dataWriter = RasterLocator.getManager().createDataServerWriter();
75
		
76
		dataWriter.setBuffer(p.getBuffer(), p.getBand());
77
		Params params;
78
		try {
79
			if(p.getDriverParams() != null)
80
				params = p.getDriverParams();
81
			else
82
				params = RasterLocator.getManager().createWriter(p.getFileName()).getParams();
83
			
84
			AffineTransform affineTransform = p.getAffineTransform();
85
			if(affineTransform == null) {
86
				if(p.getBuffer().getDataExtent() != null) {
87
					double x = p.getBuffer().getDataExtent().getMinX();
88
					double y = p.getBuffer().getDataExtent().getMaxY();
89
					double pixelSizeX = p.getBuffer().getDataExtent().getWidth() / p.getBuffer().getWidth();
90
					double pixelSizeY = p.getBuffer().getDataExtent().getHeight() / p.getBuffer().getHeight();
91
					affineTransform = new AffineTransform(pixelSizeX, 0, 0, -pixelSizeY, x, y);
92
				} else {
93
					affineTransform = new AffineTransform();
94
				}
95
			}
96
			
97
			RasterWriter writer = RasterLocator.getManager().createWriter(
98
					dataWriter, 
99
					p.getPath() + File.separator + p.getFileName(),
100
					p.getBand() < 0 ? p.getBuffer().getBandCount() : 1, 
101
					affineTransform, 
102
					p.getBuffer().getWidth(),
103
					p.getBuffer().getHeight(), 
104
					p.getBuffer().getDataType(), 
105
					params, 
106
					null);
107
			if(p.getColorInterpretation() != null)
108
				writer.setColorBandsInterpretation(p.getColorInterpretation());
109
			writer.setWkt(p.getWktProjection());
110
			
111
			writer.dataWrite();
112
			writer.writeClose();
113
		} catch (LocatorException e) {
114
			throw new CreateException("", e);
115
		} catch (NotSupportedExtensionException e) {
116
			throw new CreateException("", e);
117
		} catch (RasterDriverException e) {
118
			throw new CreateException("", e);
119
		} catch (ProcessInterruptedException e) {
120
			//Fin del proceso
121
		} catch (IOException e) {
122
			throw new CreateException("", e);
123
		}
124
	}
125

  
126
	public NewDataStoreParameters getCreateParameters() throws DataException {
127
		return new GdalNewRasterStoreParameters();
128
	}
129

  
130
	public void initialize(FilesystemServerExplorerProviderServices serverExplorer) {
131
	}
132
	
133
	public void remove(DataStoreParameters parameters) throws RemoveException {
134
		throw new UnsupportedOperationException();
135
	}
136

  
137
	public String getDataStoreProviderName() {
138
		return GdalProvider.NAME;
139
	}
140

  
141
	public boolean accept(File pathname) {
142
		if (pathname.getParentFile() != null && 
143
			pathname.getParentFile().getName().equals("cellhd")) {
144
			if (pathname.getName().endsWith(".rmf")
145
					|| pathname.getName().endsWith(".rmf~")) {
146
				return false;
147
			}
148
			return true;
149
		}
150

  
151
		// Comprobamos que no sea un rmf propio, osea, que contenga xml
152
		if (pathname.getName().toLowerCase().endsWith(".rmf")) {
153
			FileInputStream reader = null;
154
			try {
155
				reader = new FileInputStream(pathname);
156
				String xml = "";
157
				for (int i = 0; i < 6; i++) {
158
					xml += (char) reader.read();
159
				}
160
				if (xml.equals("<?xml ")) {
161
					return false;
162
				}
163
			} catch (Exception e) {
164
			} finally {
165
				try {
166
					reader.close();
167
				} catch (Exception e) {
168
				}
169
			}
170
		}
171
		return RasterLocator.getManager().getProviderServices().isExtensionSupported(
172
				pathname.getAbsolutePath(), 
173
				GdalProvider.class);
174
	}
175

  
176
	public String getDescription() {
177
		return GdalProvider.DESCRIPTION;
178
	}
179

  
180
	public DataStoreParameters getParameters(File file) throws DataException {
181
		DataManager manager = DALLocator.getDataManager();
182
		AbstractRasterFileDataParameters params = (AbstractRasterFileDataParameters) manager
183
				.createStoreParameters(this.getDataStoreProviderName());
184
		params.setFile(file);
185
		return params;
186
	}
187
	
188
	public int getMode() {
189
		return DataServerExplorer.MODE_RASTER;
190
	}
191

  
192
}
0 193

  
org.gvsig.raster.gdal/tags/org.gvsig.raster.gdal-2.2.8/org.gvsig.raster.gdal.io/src/main/java/org/gvsig/raster/gdal/io/GdalWriter.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.gdal.io;
23

  
24
import java.awt.geom.AffineTransform;
25
import java.awt.geom.Point2D;
26
import java.io.File;
27
import java.io.IOException;
28
import java.util.ArrayList;
29

  
30
import org.cresques.cts.IProjection;
31
import org.gvsig.fmap.dal.coverage.RasterLibrary;
32
import org.gvsig.fmap.dal.coverage.RasterLocator;
33
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
34
import org.gvsig.fmap.dal.coverage.datastruct.Params;
35
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
36
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
37
import org.gvsig.fmap.dal.coverage.exception.RmfSerializerException;
38
import org.gvsig.fmap.dal.coverage.store.DataServerWriter;
39
import org.gvsig.jgdal.Gdal;
40
import org.gvsig.jgdal.GdalBuffer;
41
import org.gvsig.jgdal.GdalDriver;
42
import org.gvsig.jgdal.GdalException;
43
import org.gvsig.jgdal.GdalRasterBand;
44
import org.gvsig.jgdal.GeoTransform;
45
import org.gvsig.raster.gdal.io.features.BMPFeatures;
46
import org.gvsig.raster.gdal.io.features.GTiffFeatures;
47
import org.gvsig.raster.gdal.io.features.HFAFeatures;
48
import org.gvsig.raster.gdal.io.features.IDRISIFeatures;
49
import org.gvsig.raster.gdal.io.features.ILWIS_MprFeatures;
50
import org.gvsig.raster.gdal.io.features.Jpeg2000Features;
51
import org.gvsig.raster.gdal.io.features.PNM_PgmFeatures;
52
import org.gvsig.raster.gdal.io.features.PNM_PpmFeatures;
53
import org.gvsig.raster.impl.buffer.DefaultDataServerWriter;
54
import org.gvsig.raster.impl.buffer.RasterBuffer;
55
import org.gvsig.raster.impl.process.RasterTask;
56
import org.gvsig.raster.impl.process.RasterTaskQueue;
57
import org.gvsig.raster.impl.store.ParamImpl;
58
import org.gvsig.raster.impl.store.ParamsImpl;
59
import org.gvsig.raster.impl.store.WriteFileFormatFeatures;
60
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
61
import org.gvsig.raster.impl.store.writer.DefaultRasterWriter;
62
import org.gvsig.raster.util.DefaultProviderServices;
63
import org.gvsig.tools.ToolsLocator;
64
import org.gvsig.tools.extensionpoint.ExtensionPoint;
65
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
66

  
67

  
68
/**
69
 * Driver para la escritura a trav?s de Gdal.
70
 * Puede exportar un fichero de un formato a otro desde un GeoRasterFile
71
 * en cualquier formato soportado por la lectura a un formato que este incluido
72
 * en la lista supportedDrv.
73
 *
74
 * Puede salvar a disco en un formato que este incluido en la lista supportedDrv
75
 * obteniendo los datos que van siendo servidos desde el cliente. Este cliente
76
 * debe implementar un DataServerWriter o tener un objeto que lo implemente. Inicialmente
77
 * le pasar? los par?metros de la imagen de salida y cuando el driver comience a
78
 * escribir le ir? solicitando m?s a trav?s del m?todo readData de DataServerWriter.
79
 * El cliente ser? el que lleve el control de lo que va sirviendo y lo que le queda
80
 * por servir.
81
 * @author Nacho Brodin (nachobrodin@gmail.com)
82
 */
83
public class GdalWriter extends DefaultRasterWriter {
84

  
85
	public static void register() {
86
		DefaultProviderServices pInfo = (DefaultProviderServices)RasterLocator.getManager().getProviderServices();
87
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
88
		ExtensionPoint point = extensionPoints.get("RasterWriter");
89

  
90
		point.append("tif", "", GdalWriter.class);
91
		pInfo.getFileFeature().put("tif", new GTiffFeatures());
92

  
93
		point.append("img", "", GdalWriter.class);
94
		pInfo.getFileFeature().put("img", new HFAFeatures());
95

  
96
		point.append("bmp", "", GdalWriter.class);
97
		pInfo.getFileFeature().put("bmp", new BMPFeatures());
98

  
99
		point.append("pgm", "", GdalWriter.class);
100
		pInfo.getFileFeature().put("pgm", new PNM_PgmFeatures());
101

  
102
		point.append("ppm", "", GdalWriter.class);
103
		pInfo.getFileFeature().put("ppm", new PNM_PpmFeatures());
104

  
105
		point.append("mpl", "", GdalWriter.class);
106
		pInfo.getFileFeature().put("mpl", new ILWIS_MprFeatures());
107

  
108
		point.append("rst", "", GdalWriter.class);
109
		pInfo.getFileFeature().put("rst", new IDRISIFeatures());
110
		
111
		/*point.append("jp2", "", GdalWriter.class);
112
		pInfo.getFileFeature().put("jp2", new Jpeg2000Features());*/
113

  
114
		//La exportaci?n no es correcta del todo
115
		//point.register("rmf", GdalWriter.class);
116
		//fileFeature.put("rmf", new RMFFeatures());
117

  
118
		//No salva datos. Siempre sale negra la imagen
119
		//point.register("aux", GdalWriter.class);
120
		//fileFeature.put("aux", new PAuxFeatures());
121
	}
122

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff