Revision 15737

View differences:

org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.154/pom.xml
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3
	<modelVersion>4.0.0</modelVersion>
4
	<artifactId>org.gvsig.raster.netcdf</artifactId>
5
	<packaging>pom</packaging>
6
	<version>2.2.154</version>
7
	<name>${project.artifactId}</name>
8
	<description>NetCDF adapter</description>
9
	<inceptionYear>2011</inceptionYear>
10
	<parent>
11
      <groupId>org.gvsig</groupId>
12
      <artifactId>org.gvsig.desktop</artifactId>
13
      <version>2.0.346</version>
14
  </parent>
15

  
16
        <properties>
17
            <!-- El plugin versions:use-latest-versions falla con scope import -->
18
            <!-- asi que toca usar el versions:update-properties que si que funciona -->
19
            <org.gvsig.raster.version>2.2.177</org.gvsig.raster.version>
20
        </properties>    
21

  
22
    <repositories>
23
      <repository>
24
        <id>gvsig-public-http-repository</id>
25
        <name>gvSIG maven public HTTP repository</name>
26
        <url>http://devel.gvsig.org/m2repo/j2se</url>
27
        <releases>
28
          <enabled>true</enabled>
29
          <updatePolicy>daily</updatePolicy>
30
          <checksumPolicy>warn</checksumPolicy>
31
        </releases>
32
        <snapshots>
33
          <enabled>true</enabled>
34
          <updatePolicy>daily</updatePolicy>
35
          <checksumPolicy>warn</checksumPolicy>
36
        </snapshots>
37
      </repository>
38
    </repositories>
39
    
40
    <scm>
41
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.154</connection>
42
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.154</developerConnection>
43
        <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.154</url>
44
    </scm>
45
    
46
    <build>
47
        <plugins>
48
            <plugin>
49
                <groupId>org.apache.maven.plugins</groupId>
50
                <artifactId>maven-release-plugin</artifactId>
51
                <configuration>
52
                    <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.netcdf/tags/</tagBase>
53
                    <goals>deploy</goals>
54
                </configuration>
55
            </plugin>
56
        </plugins>
57
    </build>
58
    
59
    <dependencyManagement>
60
    	<dependencies>
61
                        <dependency>
62
                                <groupId>org.gvsig</groupId>
63
                                <artifactId>org.gvsig.raster</artifactId>
64
                                <version>${org.gvsig.raster.version}</version>
65
                                <type>pom</type>
66
                                <scope>import</scope>
67
                        </dependency>
68
    	
69
	    <dependency>
70
			  <groupId>essi-unidata</groupId>
71
			  <artifactId>netcdf-java</artifactId>
72
			  <version>4.2</version>
73
			</dependency>
74
			
75

  
76
			<dependency>
77
        <groupId>org.gvsig</groupId>
78
        <artifactId>org.gvsig.raster.netcdf.io</artifactId>
79
        <version>2.2.154</version>
80
      </dependency>
81
      
82
    	</dependencies>
83
    </dependencyManagement>
84
    
85
	<modules>
86
		<module>org.gvsig.raster.netcdf.io</module>
87
		<module>org.gvsig.raster.netcdf.app.netcdfclient</module>
88
	</modules>
89
	
90
</project>
0 91

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.154/org.gvsig.raster.netcdf.io/src/main/java/org/gvsig/raster/netcdf/io/NetCDFFilesystemServerExplorer.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.netcdf.io;
29

  
30
import java.io.File;
31
import java.util.List;
32

  
33
import org.gvsig.fmap.dal.DALLocator;
34
import org.gvsig.fmap.dal.DataManager;
35
import org.gvsig.fmap.dal.DataServerExplorer;
36
import org.gvsig.fmap.dal.DataServerExplorerParameters;
37
import org.gvsig.fmap.dal.DataStoreParameters;
38
import org.gvsig.fmap.dal.NewDataStoreParameters;
39
import org.gvsig.fmap.dal.coverage.RasterLocator;
40
import org.gvsig.fmap.dal.exception.CreateException;
41
import org.gvsig.fmap.dal.exception.DataException;
42
import org.gvsig.fmap.dal.exception.RemoveException;
43
import org.gvsig.fmap.dal.serverexplorer.filesystem.impl.AbstractFilesystemServerExplorerProvider;
44
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProvider;
45
import org.gvsig.fmap.dal.serverexplorer.filesystem.spi.FilesystemServerExplorerProviderServices;
46
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
47

  
48
public class NetCDFFilesystemServerExplorer extends AbstractFilesystemServerExplorerProvider implements FilesystemServerExplorerProvider {
49
	public static final String NAME       = NetCDFProvider.NAME;
50
	
51
	public boolean canCreate() {
52
		return false;
53
	}
54

  
55
	public boolean canCreate(NewDataStoreParameters parameters) {
56
		return false;
57
	}
58

  
59
	public void create(NewDataStoreParameters parameters, boolean overwrite)
60
			throws CreateException {
61
		throw new UnsupportedOperationException();
62
	}
63

  
64
	public NewDataStoreParameters getCreateParameters() throws DataException {
65
		return null;
66
	}
67

  
68
	public void initialize(FilesystemServerExplorerProviderServices serverExplorer) {
69
	}
70
	
71
	public void remove(DataStoreParameters parameters) throws RemoveException {
72
		throw new UnsupportedOperationException();
73
	}
74

  
75
	public String getDataStoreProviderName() {
76
		return NetCDFProvider.NAME;
77
	}
78

  
79
	public boolean accept(File pathname) {
80
		return RasterLocator.getManager().getProviderServices().isExtensionSupported(
81
				pathname.getAbsolutePath(), 
82
				NetCDFProvider.class);
83
	}
84

  
85
	public String getDescription() {
86
		return NetCDFProvider.DESCRIPTION;
87
	}
88

  
89
	public DataStoreParameters getParameters(File file) throws DataException {
90
		DataManager manager = DALLocator.getDataManager();
91
		NetCDFDataParameters params = (NetCDFDataParameters) manager
92
				.createStoreParameters(this.getDataStoreProviderName());
93
		params.setFile(file);
94
		return params;
95
	}
96
	
97
	public int getMode() {
98
		return DataServerExplorer.MODE_RASTER;
99
	}
100

  
101
	public DataServerExplorerProviderServices getServerExplorerProviderServices() {
102
		return null;
103
	}
104

  
105
	public boolean add(String provider, NewDataStoreParameters parameters,
106
			boolean overwrite) throws DataException {
107
		// TODO Auto-generated method stub
108
		return false;
109
	}
110

  
111
	public boolean canAdd() {
112
		return false;
113
	}
114

  
115
	public boolean canAdd(String storeName) throws DataException {
116
		return false;
117
	}
118

  
119
	public NewDataStoreParameters getAddParameters(String storeName)
120
			throws DataException {
121
		return null;
122
	}
123

  
124
	public List<?> getDataStoreProviderNames() {
125
		return null;
126
	}
127

  
128
	public DataServerExplorerParameters getParameters() {
129
		// TODO Auto-generated method stub
130
		return null;
131
	}
132

  
133
	public String getProviderName() {
134
		return NetCDFProvider.NAME;
135
	}
136

  
137
	public List<?> list() throws DataException {
138
		return null;
139
	}
140

  
141
	public List<?> list(int mode) throws DataException {
142
		return null;
143
	}
144

  
145
	public void dispose() {
146
		
147
	}
148

  
149
}
0 150

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.154/org.gvsig.raster.netcdf.io/src/main/java/org/gvsig/raster/netcdf/io/NetCDFWriter.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.netcdf.io;
23

  
24

  
25

  
26
/**
27
 * Writer for netCDF format
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public class NetCDFWriter /*extends DefaultRasterWriter*/ {
31

  
32
//	public static void register() {
33
//		DefaultProviderServices pInfo = (DefaultProviderServices)RasterLocator.getManager().getProviderServices();
34
//		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
35
//		ExtensionPoint point = extensionPoints.get("RasterWriter");
36
//
37
//		point.append("nc", "", NetCDFWriter.class);
38
//		WriteFileFormatFeatures features = new WriteFileFormatFeatures("NetCDF", "nc", new int[] { -1 }, new int[] { 0, 1, 2, 3, 4, 5 }, NetCDFWriter.class);
39
//		pInfo.getFileFeature().put("nc", features);
40
//	}
41
//	
42
//	private boolean							write             = true; //Cuando est? a true se puede escribir en la imagen de salida. Si est? a false el proceso es interrumpido
43
//	private int 							dataType          = RasterBuffer.TYPE_UNDEFINED;
44
//	private NetcdfFileWriteable             ncfile            = null; 
45
//	private String                          bandPrefix        = "band_";
46
//	/**
47
//	 * Loads the driver parameters.
48
//	 */
49
//	public void loadParams(String ident) {
50
//		WriteFileFormatFeatures wfff = (WriteFileFormatFeatures)pInfo.getFileFeature().get(ident);
51
//		wfff.loadParams();
52
//		driverParams = (ParamsImpl)wfff.getParams();
53
//	}
54
//
55
//	/**
56
//	 * Constructor para la obtenci?n de par?metros del driver
57
//	 * @param fileName
58
//	 */
59
//	public NetCDFWriter(String fileName) {
60
//		ident = fileUtil.getExtensionFromFileName(fileName);
61
//		driver = ((WriteFileFormatFeatures)pInfo.getFileFeature().get(ident)).getDriverName();
62
//
63
//		loadParams(ident);
64
//	}
65
//
66
//	/**
67
//	 * NetCDFWriter constructor
68
//	 * @param dataWriter       	Objeto servidor de datos para el driver de escritura
69
//	 * @param outFilename      	Fichero de salida
70
//	 * @param blockSize        	Tama?o de bloque
71
//	 * @param Extent           	extent
72
//	 * @param compresion	   	Compresi?n si la tiene
73
//	 * @param outSizeX		  	Tama?o de salida en X
74
//	 * @param outSizeY			Tama?o de salida en Y
75
//	 * @param dataType			Tipo de dato
76
//	 * @throws GdalException
77
//	 * @throws IOException
78
//	 */
79
//	public NetCDFWriter (DataServerWriter dataWriter,
80
//			String outFileName,
81
//			Integer nBands,
82
//			AffineTransform at,
83
//			Integer outSizeX,
84
//			Integer outSizeY,
85
//			Integer dataType,
86
//			Params params,
87
//			IProjection proj) throws GdalException, IOException {
88
//		this(dataWriter, outFileName, nBands, at, outSizeX, outSizeY, dataType, params, proj, new Boolean(true));
89
//	}
90
//
91
//	/**
92
//	 * NetCDFWriter constructor
93
//	 * @param dataWriter       	Objeto servidor de datos para el driver de escritura
94
//	 * @param outFilename      	Fichero de salida
95
//	 * @param blockSize        	Tama?o de bloque
96
//	 * @param Extent           	extent
97
//	 * @param compresion	   	Compresi?n si la tiene
98
//	 * @param outSizeX		  	Tama?o de salida en X
99
//	 * @param outSizeY			Tama?o de salida en Y
100
//	 * @param dataType			Tipo de dato
101
//	 * @param geo				Flag que dice si se salva con georreferenciaci?n o sin ella
102
//	 * @throws GdalException
103
//	 * @throws IOException
104
//	 */
105
//	public NetCDFWriter (DataServerWriter dataWriter,
106
//			String outFileName,
107
//			Integer nBands,
108
//			AffineTransform at,
109
//			Integer outSizeX,
110
//			Integer outSizeY,
111
//			Integer dataType,
112
//			Params params,
113
//			IProjection proj,
114
//			Boolean geo)throws GdalException, IOException {
115
//
116
//		this.proj = proj;
117
//		ident = outFileName.toLowerCase().substring(outFileName.lastIndexOf(".") + 1);
118
//		driver = ((WriteFileFormatFeatures)pInfo.getFileFeature().get(ident)).getDriverName();
119
//		this.dataType = dataType.intValue();
120
//		this.at = at;
121
//		percent = 0;
122
//
123
//		this.dataWriter = dataWriter;
124
//		this.outFileName = outFileName;
125
//
126
//		this.sizeWindowX = outSizeX.intValue();
127
//		this.sizeWindowY = outSizeY.intValue();
128
//
129
//		if ((sizeWindowX < 0) || (sizeWindowY < 0))
130
//			throw new IOException("Tama?o del fichero de salida erroneo.");
131
//
132
//		this.nBands = nBands.intValue();
133
//
134
//		//Calculamos la georeferenciaci?n a partir del extend pasado por el cliente.
135
//
136
//		/*LatLonPoint p1 = new LatLonPointImpl(at.getTranslateY(), at.getTranslateX());
137
//		Point2D p = rasterToWorld(new Point2D.Double(outSizeX, outSizeY), at); 
138
//		LatLonPoint p2 = new LatLonPointImpl(at.getTranslateY() - p.getY() , at.getTranslateX() + p.getX());
139
//		boundingBox = new LatLonRect(p1, p2);*/
140
//		
141
//		ncfile = NetcdfFileWriteable.createNew(outFileName, false);
142
//		
143
//		/*Dimension latDim = ncfile.addDimension("La1", 1);
144
//		Dimension lonDim = ncfile.addDimension("Lo1", 1);*/
145
//		
146
//		Dimension latDim = ncfile.addDimension("y_dim", sizeWindowY);
147
//		Dimension lonDim = ncfile.addDimension("x_dim", sizeWindowX);
148
//		
149
//		ArrayList<Dimension> dims = new ArrayList<Dimension>();
150
//		dims.add(latDim);
151
//		dims.add(lonDim);
152
//		
153
//		for (int i = 0; i < nBands; i++) {
154
//			switch(dataType) {
155
//			case RasterBuffer.TYPE_BYTE:
156
//				ncfile.addVariable(bandPrefix + i, ucar.ma2.DataType.CHAR, dims);
157
//				break;
158
//			case RasterBuffer.TYPE_SHORT:
159
//				ncfile.addVariable(bandPrefix + i, ucar.ma2.DataType.SHORT, dims);
160
//				break;
161
//			case RasterBuffer.TYPE_INT:
162
//				ncfile.addVariable(bandPrefix + i, ucar.ma2.DataType.INT, dims);
163
//				break;
164
//			case RasterBuffer.TYPE_FLOAT:
165
//				ncfile.addVariable(bandPrefix + i, ucar.ma2.DataType.FLOAT, dims);
166
//				break;
167
//			case RasterBuffer.TYPE_DOUBLE:
168
//				ncfile.addVariable(bandPrefix + i, ucar.ma2.DataType.DOUBLE, dims);
169
//				break;
170
//			}
171
//		}
172
//		
173
//		/*String outRmf = outFileName.substring(0, outFileName.lastIndexOf("."));
174
//		if(geo.booleanValue())
175
//			rasterUtil.saveGeoInfo(outRmf, at, new Point2D.Double(sizeWindowX, sizeWindowY));*/
176
//
177
//		if(params == null)
178
//			loadParams(ident);
179
//		else
180
//			if(params instanceof ParamsImpl)
181
//				this.driverParams = (ParamsImpl)params;
182
//	}
183
//	
184
//	/**
185
//	 * Convierte un punto desde coordenadas pixel a coordenadas del mundo.
186
//	 * @param pt Punto a transformar
187
//	 * @return punto transformado en coordenadas del mundo
188
//	 */
189
//	public Point2D rasterToWorld(Point2D pt, AffineTransform at) {
190
//		Point2D p = new Point2D.Double();
191
//		at.transform(pt, p);
192
//		return p;
193
//	}
194
//
195
//	/**
196
//	 * Convierte un punto desde del mundo a coordenadas pixel.
197
//	 * @param pt Punto a transformar
198
//	 * @return punto transformado en coordenadas pixel
199
//	 */
200
//	public Point2D worldToRaster(Point2D pt, AffineTransform at) {
201
//		Point2D p = new Point2D.Double();
202
//		try {
203
//			at.inverseTransform(pt, p);
204
//		} catch (NoninvertibleTransformException e) {
205
//			return pt;
206
//		}
207
//		return p;
208
//	}
209
//	
210
//	public void setDates(String[] dates) {
211
//		for (int i = 0; i < dates.length; i++) {
212
//			
213
//		}
214
//	}
215
//
216
//	/**
217
//	 * A?ade la proyecci?n Wkt con la que salvar.
218
//	 * @param wkt
219
//	 * @throws GdalException
220
//	 */
221
//	public void setWkt(String wkt) {
222
//		
223
//	}
224
//
225
//	/**
226
//	 * Asigna el tipo de driver con el que se salvar? la imagen
227
//	 * @param drvType        Tipo de driver
228
//	 */
229
//	public void setDriverType(String drvType) {
230
//		this.driver = drvType;
231
//	}
232
//
233
//	
234
//	/**
235
//	 * Realiza la funci?n de compresi?n a partir de un GeoRasterFile.
236
//	 * @throws IOException
237
//	 */
238
//	public void fileWrite() throws IOException, ProcessInterruptedException {
239
//	}
240
//
241
//	/**
242
//	 * Realiza una copia en el formato especificado.
243
//	 * @throws IOException
244
//	 */
245
//	public static void createCopy(GdalDriver driverDst, String dst, String src,
246
//			boolean bstrict, String[] params) throws IOException, GdalException {
247
//		if (dst == null || src == null)
248
//			throw new IOException("No se ha asignado un fichero de entrada.");
249
//
250
//		
251
//	}
252
//
253
//	/**
254
//	 * Realiza la escritura de datos con los datos que le pasa el cliente.
255
//	 * @throws IOException
256
//	 * @throws RmfSerializerException
257
//	 */
258
//	public void dataWrite() throws IOException, ProcessInterruptedException,
259
//	OutOfMemoryError {
260
//		if (ncfile == null)
261
//			throw new IOException("No se ha obtenido un objeto de entrada para la escritura valido.");
262
//
263
//		ncfile.create();
264
//		int[] origin = new int[2];
265
//		try {
266
//			for (int iBand = 0; iBand < nBands; iBand++) {
267
//				switch(dataType) {
268
//				case RasterBuffer.TYPE_BYTE:
269
//					ArrayByte b = new ArrayByte.D2(sizeWindowY, sizeWindowX);
270
//					dataWriter.setBand(iBand);
271
//					byte[][] valueb = dataWriter.readByteData(sizeWindowX, sizeWindowY);
272
//					for (int i = 0; i < b.getSize(); i++) {
273
//						b.setByte(i, valueb[0][i]);
274
//					}
275
//					ncfile.write(bandPrefix + iBand, origin, b);
276
//					break;
277
//				case RasterBuffer.TYPE_SHORT:
278
//					ArrayShort s = new ArrayShort.D2(sizeWindowY, sizeWindowX);
279
//					dataWriter.setBand(iBand);
280
//					short[][] values = dataWriter.readShortData(sizeWindowX, sizeWindowY);
281
//					for (int i = 0; i < s.getSize(); i++) {
282
//						s.setDouble(i, values[0][i]);
283
//					}
284
//					ncfile.write(bandPrefix + iBand, origin, s);
285
//					break;
286
//				case RasterBuffer.TYPE_INT:
287
//					ArrayInt in = new ArrayInt.D2(sizeWindowY, sizeWindowX);
288
//					dataWriter.setBand(iBand);
289
//					int[][] valuei = dataWriter.readIntData(sizeWindowX, sizeWindowY);
290
//					for (int i = 0; i < in.getSize(); i++) {
291
//						in.setDouble(i, valuei[0][i]);
292
//					}
293
//					ncfile.write(bandPrefix + iBand, origin, in);
294
//					break;
295
//				case RasterBuffer.TYPE_FLOAT:
296
//					ArrayFloat f = new ArrayFloat.D2(sizeWindowY, sizeWindowX);
297
//					dataWriter.setBand(iBand);
298
//					float[][] valuef = dataWriter.readFloatData(sizeWindowX, sizeWindowY);
299
//					for (int i = 0; i < f.getSize(); i++) {
300
//						f.setFloat(i, valuef[0][i]);
301
//					}
302
//					ncfile.write(bandPrefix + iBand, origin, f);
303
//					break;
304
//				case RasterBuffer.TYPE_DOUBLE:
305
//					ArrayDouble d = new ArrayDouble.D2(sizeWindowY, sizeWindowX);
306
//					dataWriter.setBand(iBand);
307
//					double[][] valued = dataWriter.readDoubleData(sizeWindowX, sizeWindowY);
308
//					for (int i = 0; i < d.getSize(); i++) {
309
//						d.setDouble(i, valued[0][i]);
310
//					}
311
//					ncfile.write(bandPrefix + iBand, origin, d);
312
//					break;
313
//				}
314
//			}
315
//		} catch (InvalidRangeException e) {
316
//			new IOException(e.getMessage());
317
//		}
318
//	}
319
//
320
//
321
//	/**
322
//	 * Cancela el salvado de datos.
323
//	 * @throws GdalException
324
//	 */
325
//	public void writeClose() {
326
//		try {
327
//			ncfile.close();
328
//		} catch (IOException e) {
329
//			e.printStackTrace();
330
//		}
331
//	}
332
//
333
//	/**
334
//	 * Cancela el salvado de datos.
335
//	 */
336
//	public void writeCancel() {
337
//		write = false;
338
//	}
339
//
340
//	/**
341
//	 * Obtiene el valor a la variable write que estar? a true cuando se est? escribiendo
342
//	 *  o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
343
//	 * pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
344
//	 * de salida.
345
//	 * @return True si puede escribirse y false si no puede
346
//	 */
347
//	public boolean isWrite() {
348
//		return write;
349
//	}
350
//
351
//	/**
352
//	 * Asigna el valor a la variable write que estar? a true cuando se est? escribiendo
353
//	 *  o puede escribirse la imagen de salida. El cancelar la operaci?n de escritura
354
//	 * pondr? esta variable a false deteniendose la escritura y cerrandose el dataset
355
//	 * de salida.
356
//	 * @param write Variable booleana. True si puede escribirse y false si no puede
357
//	 */
358
//	public void setWrite(boolean write) {
359
//		this.write = write;
360
//	}
361
//
362
//	/**
363
//	 * Asigna los par?metros del driver modificados por el cliente.
364
//	 * @param Params
365
//	 */
366
//	public void setParams(Params params) {
367
//		if(params instanceof ParamsImpl)
368
//			this.driverParams = (ParamsImpl)params;
369
//		else 
370
//			return;
371
//	}
372
}
0 373

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.154/org.gvsig.raster.netcdf.io/src/main/java/org/gvsig/raster/netcdf/io/NetCDFDataParameters.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.netcdf.io;
29

  
30
import java.io.File;
31
import java.io.IOException;
32
import java.util.ArrayList;
33
import java.util.Date;
34

  
35
import org.gvsig.fmap.dal.coverage.store.parameter.MultiDimensionalStoreParameters;
36

  
37
import ucar.nc2.Variable;
38

  
39
/**
40
 * Parameters for the NetCDF provider
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 */
43
public interface NetCDFDataParameters extends MultiDimensionalStoreParameters {
44
	public static final String            FIELD_VARIABLE             = "GridVariable";
45
	public static final String            FIELD_TIME                 = "Time";
46
	public static final String            FIELD_LEVEL                = "Level";
47
	public static final String            FIELD_XDIM                 = "XDim";
48
	public static final String            FIELD_YDIM                 = "YDim";
49
	
50
	/**
51
	 * Gets the list of grids
52
	 * @return A list of pair of values. The first element of one pair is the variable's name 
53
	 * and the second its description
54
	 * @throws IOException 
55
	 */
56
	public ArrayList<Variable> getVariables() throws IOException;
57
	
58
	/**
59
	 * Gets the list of grids
60
	 * @return A list of pair of values. The first element of one pair is the variable's name 
61
	 * and the second its description
62
	 * @throws IOException 
63
	 */
64
	public ArrayList<String[]> getGridVariables() throws IOException;
65
	
66
	/**
67
	 * Gets the list of dates
68
	 * @param var
69
	 * @return
70
	 */
71
	public Date[] getTimeList(String var);
72

  
73
	/**
74
	 * Gets the number of levels of one variable
75
	 * @param var
76
	 * @return
77
	 */
78
	public double[] getLevelList(String var);
79
	
80
	/**
81
	 * Gets the variable's name of the X dimension
82
	 * @return
83
	 */
84
	public String getXDimVariable();
85
	
86
	/**
87
	 * Gets the variable's name of the Y dimension
88
	 * @return
89
	 */
90
	public String getYDimVariable();
91
	
92
	public void selectNextInstant();
93
	
94
	public void selectPrevInstant();
95
	
96
	public void goTo(int position);
97
	
98
	public int getFieldTime();
99
	
100
	/**
101
	 * Gets the level selected in the list of levels of the selected variable
102
	 * @return
103
	 */
104
	public int getFieldLevel();
105
	
106
	public String getStringVariable();
107
	
108
	public String getStringLevel();
109
	
110
	public String getStringTime();
111
	
112
	public void setFieldVariable(String variable);
113
	
114
	public void setFieldTime(int timePosInList);
115
	
116
	public void setFieldLevel(int levelPosInList);
117

  
118
	public void setFile(File file);
119
}
0 120

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.154/org.gvsig.raster.netcdf.io/src/main/java/org/gvsig/raster/netcdf/io/NetCDFDataParametersImpl.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.netcdf.io;
29

  
30
import java.io.IOException;
31
import java.util.ArrayList;
32
import java.util.Date;
33
import java.util.HashMap;
34
import java.util.Iterator;
35
import java.util.List;
36

  
37
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters;
38
import org.gvsig.tools.ToolsLocator;
39
import org.gvsig.tools.dynobject.DelegatedDynObject;
40
import org.gvsig.tools.dynobject.DynStruct;
41
import org.gvsig.tools.persistence.PersistenceManager;
42

  
43
import ucar.nc2.Dimension;
44
import ucar.nc2.NetcdfFile;
45
import ucar.nc2.Variable;
46
import ucar.nc2.dataset.CoordinateAxis1D;
47
import ucar.nc2.dataset.CoordinateAxis1DTime;
48
import ucar.nc2.dt.GridCoordSystem;
49
import ucar.nc2.dt.GridDatatype;
50
import ucar.nc2.dt.grid.GridDataset;
51

  
52
/**
53
 * Parameters for the NetCDF provider
54
 * @author Nacho Brodin (nachobrodin@gmail.com)
55
 */
56
public class NetCDFDataParametersImpl extends AbstractRasterFileDataParameters implements NetCDFDataParameters {
57
	private ArrayList<String[]>           gridVarList                = null;
58
	private ArrayList<Variable>           varList                    = null;
59
	private HashMap<String, double[]>     rankByVar                  = new HashMap<String, double[]>();
60
	private HashMap<String, Date[]>       dateByVar                  = new HashMap<String, Date[]>();
61
	private String                        xDimVariable               = null;
62
	private String                        yDimVariable               = null;
63
	
64
	
65
	public NetCDFDataParametersImpl() {
66
		super();
67
		initialize();
68
	}
69
	
70
	protected void initialize() {
71
		delegatedDynObject = (DelegatedDynObject) ToolsLocator
72
				.getDynObjectManager().createDynObject(
73
						registerDynClass());
74
	}
75
	
76
	public static DynStruct registerDynClass() {
77
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
78
		DynStruct definition = manager.getDefinition("NetCDFDataParametersImpl_Persistent");
79
		if( definition == null ) {
80
			definition = manager.addDefinition(
81
					NetCDFDataParametersImpl.class,
82
					"NetCDFDataParametersImpl_Persistent",
83
					"NetCDFDataParametersImpl Persistent",
84
					null, 
85
					null
86
			);
87
			AbstractRasterFileDataParameters.registerDynClass(definition);
88
		}
89
		
90
		definition.addDynFieldString(FIELD_VARIABLE)
91
		.setDescription("Grid variable")
92
		.setMandatory(false);
93
        
94
		definition.addDynFieldInt(FIELD_LEVEL)
95
		.setDescription("Level selected")
96
		.setMandatory(false);
97
        
98
		definition.addDynFieldInt(FIELD_TIME)
99
		.setDescription("Time selected")
100
		.setMandatory(false);
101
		
102
		definition.addDynFieldString(FIELD_XDIM).
103
		setMandatory(false);
104
		
105
		definition.addDynFieldString(FIELD_YDIM).
106
		setMandatory(false);
107
        
108
		return definition;
109
	}
110
	
111
	/**
112
	 * Gets the list of grids
113
	 * @return A list of pair of values. The first element of one pair is the variable's name 
114
	 * and the second its description
115
	 * @throws IOException 
116
	 */
117
	public ArrayList<Variable> getVariables() throws IOException {
118
		if(varList == null) {
119
			NetcdfFile netCDFFile = NetcdfFile.open(getFile().getAbsolutePath());
120
			varList = new ArrayList<Variable>();
121
			
122
			List<Variable> variableList = netCDFFile.getVariables();
123
            Iterator<Variable> it = variableList.iterator();
124
            while(it.hasNext()) {
125
            	Variable var = it.next();
126
            	varList.add(var);
127
            }
128
            netCDFFile.close();
129
		}
130
		return varList;
131
	}
132
	
133
	/**
134
	 * Gets the list of grids
135
	 * @return A list of pair of values. The first element of one pair is the variable's name 
136
	 * and the second its description
137
	 * @throws IOException 
138
	 */
139
	public ArrayList<String[]> getGridVariables() throws IOException {
140
		if(gridVarList == null) {
141
			GridDataset connector = GridDataset.open(getFile().getAbsolutePath());
142
			List<GridDatatype> gridList = connector.getGrids();
143
			gridVarList = new ArrayList<String[]>();
144
			Iterator<GridDatatype> it = gridList.iterator();
145
			while(it.hasNext()) {
146
				GridDatatype dt = it.next();
147
				
148
				//Loads name and description
149
				String[] pair = new String[2];
150
				pair[0] = dt.getName();
151
				pair[1] = dt.getDescription();
152
				gridVarList.add(pair);
153
				
154
				//Loads variable's name
155
				Dimension dim = dt.getDimensions().get(dt.getXDimensionIndex());
156
				xDimVariable = dim.getName();
157
				dim = dt.getDimensions().get(dt.getYDimensionIndex());
158
				yDimVariable = dim.getName();
159
				
160
				if(dt.getShape() != null) {
161
					GridCoordSystem gcs = dt.getCoordinateSystem();
162
					//Loads levels
163
					CoordinateAxis1D zAxis = gcs.getVerticalAxis();
164
					if(zAxis != null) {
165
						double[] d = calcSliceValue(zAxis.getCoordEdges());
166
						rankByVar.put(pair[0], d);
167
					}
168
					
169
					//Loads time list
170
					if (gcs.hasTimeAxis1D()) {
171
						CoordinateAxis1DTime tAxis1D = gcs.getTimeAxis1D();
172
						Date[] dates = tAxis1D.getTimeDates();
173
						dateByVar.put(pair[0], dates);
174
					}
175
				}
176
			}
177
			connector.close();
178
		}
179
		return gridVarList;
180
	}
181
	
182
	/**
183
	 * Calculates the array of levels
184
	 * @param coordsEdges
185
	 * @return
186
	 */
187
	private double[] calcSliceValue(double[] coordsEdges) {
188
		if(coordsEdges == null)
189
			return null;
190
		double[] values = new double[coordsEdges.length - 1];
191
		for (int i = 0; i < coordsEdges.length - 1; i++) {
192
			values[i] = ((coordsEdges[i] + coordsEdges[i + 1]) / 2);
193
		}
194
		return values;
195
	}
196
	
197
	/**
198
	 * Gets the list of dates
199
	 * @param var
200
	 * @return
201
	 */
202
	public Date[] getTimeList(String var) {
203
		return dateByVar.get(var);
204
	}
205

  
206
	/**
207
	 * Gets the number of levels of one variable
208
	 * @param var
209
	 * @return
210
	 */
211
	public double[] getLevelList(String var) {
212
		return rankByVar.get(var);
213
	}
214
	
215
	/**
216
	 * Gets the variable's name of the X dimension
217
	 * @return
218
	 */
219
	public String getXDimVariable() {
220
		return xDimVariable;
221
	}
222
	
223
	/**
224
	 * Gets the variable's name of the Y dimension
225
	 * @return
226
	 */
227
	public String getYDimVariable() {
228
		return yDimVariable;
229
	}
230
	
231
	public String getDataStoreName() {
232
		return NetCDFProvider.NAME;
233
	}
234
	
235
	public String getDescription() {
236
		return NetCDFProvider.DESCRIPTION;
237
	}
238
	
239
	public void selectNextInstant() {
240
		int i = getFieldTime() + 1;
241
		if(i < getTimeListLength()) {
242
			setDynValue(NetCDFDataParameters.FIELD_TIME, i);
243
		}
244
	}
245
	
246
	public void selectPrevInstant() {
247
		int i = getFieldTime() - 1;
248
		if(i >= 0) {
249
			setDynValue(NetCDFDataParameters.FIELD_TIME, i);
250
		}
251
	}
252
	
253
	public void goTo(int position) {
254
		if(position < getTimeListLength() && position >= 0) {
255
			setDynValue(NetCDFDataParameters.FIELD_TIME, position);
256
		}
257
	}
258
	
259
	public int getFieldTime() {
260
		if(hasDynValue(NetCDFDataParameters.FIELD_TIME) && getDynValue(NetCDFDataParameters.FIELD_TIME) != null) {
261
			return ((Integer)getDynValue(NetCDFDataParameters.FIELD_TIME)).intValue();
262
		}
263
		return 0;
264
	}
265
	
266
	public int getFieldLevel() {
267
		if(hasDynValue(NetCDFDataParameters.FIELD_LEVEL) && getDynValue(NetCDFDataParameters.FIELD_LEVEL) != null) {
268
			return ((Integer)getDynValue(NetCDFDataParameters.FIELD_LEVEL)).intValue();
269
		}
270
		return 0;
271
	}
272
	
273
	public String getStringVariable() {
274
		if(hasDynValue(NetCDFDataParameters.FIELD_VARIABLE)) {
275
			return (String)getDynValue(NetCDFDataParameters.FIELD_VARIABLE);
276
		}
277
		
278
		//We will use the first variable in the list
279
		
280
		try {
281
			ArrayList<String[]> vars = getGridVariables();
282
			if(vars.size() > 0) {
283
				String[] var = vars.get(0);
284
				if(var.length > 0) {
285
					setFieldVariable(var[0]); 
286
					return var[0];
287
				}
288
			}
289
		} catch (IOException e) {
290
			e.printStackTrace();
291
		}
292
		return null;
293
	}
294
	
295
	public String getStringLevel() {
296
		if(!hasDynValue(NetCDFDataParameters.FIELD_LEVEL)) {
297
			//We will use the first level in the list
298
			setFieldLevel(0);
299
		}
300
		
301
		int index = ((Integer)getDynValue(NetCDFDataParameters.FIELD_LEVEL)).intValue();
302
		double[] levelList = getLevelList(getStringVariable());
303
		if(levelList == null)
304
			return "-1";
305
		return levelList[index] + "";
306
	}
307
	
308
	public String getStringTime() {
309
		if(!hasDynValue(NetCDFDataParameters.FIELD_TIME)) {
310
			setFieldTime(0);
311
		}
312
		
313
		int index = ((Integer)getDynValue(NetCDFDataParameters.FIELD_TIME)).intValue();
314
		Date[] timeList = getTimeList(getStringVariable());
315
		if(timeList == null)
316
			return "-1";
317
		return timeList[index].toString();
318
	}
319
	
320
	/**
321
	 * Gets the length of the time list
322
	 * @return
323
	 */
324
	private int getTimeListLength() {
325
		String var = (String)getDynValue(NetCDFDataParameters.FIELD_VARIABLE);
326
		if(var != null) {
327
			Date[] dateList = getTimeList(var);
328
			if(dateList != null)
329
				return dateList.length;
330
		}
331
		return 0;
332
	}
333
	
334
	public void setFieldVariable(String variable) {
335
		setDynValue(NetCDFDataParameters.FIELD_VARIABLE, variable);
336
	}
337
	
338
	public void setFieldTime(int timePosInList) {
339
		setDynValue(NetCDFDataParameters.FIELD_TIME, timePosInList);
340
	}
341
	
342
	public void setFieldLevel(int levelPosInList) {
343
		setDynValue(NetCDFDataParameters.FIELD_LEVEL, levelPosInList);
344
	}
345
}
0 346

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.154/org.gvsig.raster.netcdf.io/src/main/java/org/gvsig/raster/netcdf/io/DefaultNetCDFIOLibrary.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.netcdf.io;
23

  
24
import org.gvsig.tools.library.AbstractLibrary;
25
import org.gvsig.tools.library.LibraryException;
26
/**
27
 *
28
 * @author Nacho Brodin (nachobrodin@gmail.com)
29
 */
30
public class DefaultNetCDFIOLibrary extends AbstractLibrary {	
31
	
32
	@Override
33
	protected void doInitialize() throws LibraryException {
34
		//RasterLibrary.wakeUp();
35
	}
36

  
37
	@Override
38
	protected void doPostInitialize() throws LibraryException {
39
		//NetCDFServerExplorerParameters.registerDynClass();
40
		NetCDFDataParametersImpl.registerDynClass();
41
		NetCDFProvider.register();
42
		//NetCDFWriter.register();
43
	}
44
}
0 45

  
org.gvsig.raster.netcdf/tags/org.gvsig.raster.netcdf-2.2.154/org.gvsig.raster.netcdf.io/src/main/java/org/gvsig/raster/netcdf/io/NetCDFProvider.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.netcdf.io;
23

  
24
import java.awt.geom.AffineTransform;
25
import java.awt.geom.Point2D;
26
import java.awt.geom.Rectangle2D;
27
import java.io.File;
28
import java.io.IOException;
29
import java.net.URI;
30
import java.net.URISyntaxException;
31
import java.util.List;
32

  
33
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
35

  
36
import org.gvsig.fmap.dal.DALFileLocator;
37
import org.gvsig.fmap.dal.DALLocator;
38
import org.gvsig.fmap.dal.DataStore;
39
import org.gvsig.fmap.dal.coverage.RasterLocator;
40
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
41
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
42
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
43
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
44
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
45
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
46
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
47
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
48
import org.gvsig.fmap.dal.coverage.exception.ParsingException;
49
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
50
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
51
import org.gvsig.fmap.dal.coverage.store.parameter.RasterFileStoreParameters;
52
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
53
import org.gvsig.fmap.dal.exception.OpenException;
54
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
55
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
56
import org.gvsig.metadata.MetadataLocator;
57
import org.gvsig.raster.cache.tile.provider.TileServer;
58
import org.gvsig.raster.impl.DefaultRasterManager;
59
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
60
import org.gvsig.raster.impl.datastruct.DefaultNoData;
61
import org.gvsig.raster.impl.datastruct.ExtentImpl;
62
import org.gvsig.raster.impl.provider.AbstractRasterProvider;
63
import org.gvsig.raster.impl.provider.RasterProvider;
64
import org.gvsig.raster.impl.provider.tile.FileTileServer;
65
import org.gvsig.raster.impl.store.DefaultRasterStore;
66
import org.gvsig.raster.impl.store.DefaultStoreFactory;
67
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
68
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
69
import org.gvsig.tools.ToolsLocator;
70

  
71
import ucar.ma2.Array;
72
import ucar.ma2.DataType;
73
import ucar.ma2.InvalidRangeException;
74
import ucar.ma2.Range;
75
import ucar.nc2.dt.GridDatatype;
76
import ucar.nc2.dt.grid.GridDataset;
77
import ucar.unidata.geoloc.ProjectionRect;
78
/**
79
 * Data provider for NetCDF files with raster data
80
 *
81
 * @author Nacho Brodin (nachobrodin@gmail.com)
82
 */
83
public class NetCDFProvider extends AbstractRasterProvider {
84
	public static String                     NAME                     = "NetCDF Raster";
85
	public static String                     DESCRIPTION              = "NetCDF Raster file";
86
	public final String                      METADATA_DEFINITION_NAME = NAME;
87
	private Extent                           viewRequest              = null;
88
	private TileServer                       tileServer               = null;
89
	private boolean                          open                     = false;
90

  
91
    private GridDataset                      gridNetCDF               = null;
92
    private List<GridDatatype>               gridList                 = null;
93
    private GridDatatype                     selectedGridDataType     = null;
94
    private DataStoreTransparency            fileTransparency         = null;
95
    private static final Logger              logger                   = LoggerFactory.getLogger(NetCDFProvider.class);
96
    protected static String[]                formatList               = null;
97

  
98
	public static void register() {
99
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
100
		RasterLocator.getManager().getProviderServices().registerFileProvidersTiled(NetCDFProvider.class);
101
		registerFormats();
102

  
103
		if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
104
			dataman.registerStoreProvider(NAME,
105
					NetCDFProvider.class, NetCDFDataParametersImpl.class);
106
		}
107

  
108

  
109
		/*if (!dataman.getExplorerProviders().contains(NetCDFFilesystemServerExplorer.NAME)) {
110
			dataman.registerExplorerProvider(NetCDFFilesystemServerExplorer.NAME, NetCDFFilesystemServerExplorer.class, NetCDFServerExplorerParameters.class);
111
		}*/
112

  
113
		if(DALFileLocator.getFilesystemServerExplorerManager() != null)
114
			DALFileLocator.getFilesystemServerExplorerManager().registerProvider(
115
					NAME, DESCRIPTION,
116
					NetCDFFilesystemServerExplorer.class);
117

  
118

  
119
		dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
120
	}
121

  
122
	private static void registerFormats() {
123
		formatList      = new String[] {"nc", "nc4"};
124
		for (int i = 0; i < formatList.length; i++)
125
			RasterLocator.getManager().getProviderServices().addFormat(formatList[i], NetCDFProvider.class);
126
	}
127

  
128
	public String[] getFormatList() {
129
		return formatList;
130
	}
131

  
132
	/**
133
	 * Returns true if the extension is supported and false if doesn't
134
	 * @param ext
135
	 * @return
136
	 */
137
	public boolean isExtensionSupported(String ext) {
138
		if(ext.indexOf(".") != -1)
139
			ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length());
140
		for (int i = 0; i < formatList.length; i++) {
141
			if(formatList[i].compareTo(ext) == 0)
142
				return true;
143
		}
144
		return false;
145
	}
146

  
147
	public NetCDFProvider() {
148
	}
149

  
150
	/**
151
	 * Opens the dataset.
152
	 * @param proj Projection
153
	 * @param fName File name
154
	 * @throws NotSupportedExtensionException
155
     * @deprecated use {@link #NetCDFProvider(URI)}, this constructor will be removed in gvSIG 2.5
156
	 */
157
	public NetCDFProvider(String params) throws NotSupportedExtensionException, OpenException {
158
		super(params);
159
        logger.info("Deprecated use of NetCDFProvider constructor");
160
		if(params instanceof String) {
161
			NetCDFDataParameters p = new NetCDFDataParametersImpl();
162
			URI uriObj;
163
            try {
164
                uriObj = new URI((String)params);
165
            } catch (URISyntaxException e) {
166
                throw new OpenException("Can't create URI from "+(String)params, e);
167
            }
168
			p.setURI(uriObj);
169
			super.init(p, null, ToolsLocator.getDynObjectManager()
170
					.createDynObject(
171
							MetadataLocator.getMetadataManager().getDefinition(
172
									DataStore.METADATA_DEFINITION_NAME)));
173
			init(p, null);
174
		}
175
	}
176

  
177
    /**
178
     * Opens the dataset.
179
     * @param proj Projection
180
     * @param fName File name
181
     * @throws NotSupportedExtensionException
182
     */
183
    public NetCDFProvider(URI uri) throws NotSupportedExtensionException, OpenException {
184
        super(uri);
185
        NetCDFDataParameters p = new NetCDFDataParametersImpl();
186
        p.setURI(uri);
187
        super.init(
188
            p,
189
            null,
190
            ToolsLocator.getDynObjectManager().createDynObject(
191
                MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME)));
192
        init(p, null);
193
    }
194

  
195
    public NetCDFProvider (NetCDFDataParameters params,
196
			DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException {
197
		super(params, storeServices, ToolsLocator.getDynObjectManager()
198
				.createDynObject(
199
						MetadataLocator.getMetadataManager().getDefinition(
200
								DataStore.METADATA_DEFINITION_NAME)));
201
		init(params, storeServices);
202
	}
203

  
204
	/**
205
	 * Build file references
206
	 * @param proj Projection
207
	 * @param param Load parameters
208
	 * @throws NotSupportedExtensionException
209
	 */
210
	public void init (NetCDFDataParameters params,
211
			DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException {
212

  
213
		if(((RasterFileStoreParameters)params).getFile().exists()) {
214
			String fileName = ((RasterFileStoreParameters)params).getFile().getAbsolutePath();
215
            try {
216
            	gridNetCDF = GridDataset.open(fileName);
217
            	gridList = gridNetCDF.getGrids();
218
            	if(gridList.size() == 0)
219
            		throw new OpenException("There is not a grid variable", null);
220
            	selectedGridDataType = gridList.get(0);
221
                //netCDFFile = NetcdfFile.open(((RasterFileStoreParameters)params).getFile().getAbsolutePath());
222
            } catch (IOException e) {
223
                throw new OpenException("Imposible to read the file", e);
224
            }
225

  
226
            /*List<Variable> variableList = netCDFFile.getVariables();
227
            Iterator<Variable> it = variableList.iterator();
228
            while(it.hasNext()) {
229
            	Variable var = it.next();
230
            	System.out.println("===>>" + var.getName());
231
            }*/
232

  
233
			setParam(storeServices, params);
234
			reloadMetadataFromGrid();
235

  
236
			noData = new DefaultNoData(Double.NaN, Double.NaN, fileName);
237
			load();
238
		} else
239
			setParam(storeServices, params);
240

  
241
		super.init();
242
		selectSubdataset(getId(0, 0, 0));
243
		try {
244
			loadFromRmf(getRmfBlocksManager());
245
		} catch (ParsingException e) {
246
			//No lee desde rmf
247
		}
248
		open = true;
249
	}
250

  
251
	/**
252
	 * Reloads metadata using the selected grid
253
	 */
254
	private void reloadMetadataFromGrid() {
255
		//wktProjection = null;
256
		//CrsWkt crs = new CrsWkt(wktProjection);
257
		//IProjection proj = CRSFactory.getCRS("EPSG:23030");
258

  
259
		/*LatLonRect gcs = selectedGridDataType.getCoordinateSystem().getLatLonBoundingBox();
260
		getColorInterpretation();
261
		double scaleX = gcs.getWidth() / selectedGridDataType.getXDimension().getLength();
262
		double scaleY = gcs.getHeight() / selectedGridDataType.getYDimension().getLength();
263
		ownTransformation = new AffineTransform(
264
				scaleX, 0,
265
				0, -scaleY,
266
				gcs.getLonMin(),
267
				gcs.getLatMax());*/
268

  
269
		ProjectionRect pRect = selectedGridDataType.getCoordinateSystem().getBoundingBox();
270
		double scaleX = pRect.getWidth() / selectedGridDataType.getXDimension().getLength();
271
		double scaleY = pRect.getHeight() / selectedGridDataType.getYDimension().getLength();
272
		ownTransformation = new AffineTransform(
273
				scaleX, 0,
274
				0, -scaleY,
275
				pRect.getMinX(),
276
				pRect.getMaxY());
277
		externalTransformation = (AffineTransform)ownTransformation.clone();
278
		bandCount = 1; //One variable is always shown
279
		setDataType();
280
	}
281

  
282
	/**
283
	 * @param dataType The dataType to set.
284
	 */
285
	private void setDataType() {
286
		DataType dt = selectedGridDataType.getDataType();
287
		int type = Buffer.TYPE_UNDEFINED;
288
		if(dt.name() == DataType.BYTE.name()) {
289
			type = Buffer.TYPE_BYTE;
290
		}
291
		if(dt.name() == DataType.SHORT.name()) {
292
			type = Buffer.TYPE_SHORT;
293
		}
294
		if(dt.name() == DataType.INT.name()) {
295
			type = Buffer.TYPE_INT;
296
		}
297
		if(dt.name() == DataType.DOUBLE.name()) {
298
			type = Buffer.TYPE_DOUBLE;
299
		}
300
		if(dt.name() == DataType.FLOAT.name()) {
301
			type = Buffer.TYPE_FLOAT;
302
		}
303
		if(dt.name() == DataType.LONG.name()) {
304
			type = Buffer.TYPE_DOUBLE;
305
		}
306

  
307
		int[] dtype = new int[getBandCount()];
308
		for (int i = 0; i < dtype.length; i++)
309
			dtype[i] = type;
310
		setDataType(dtype);
311
	}
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff