Revision 2692

View differences:

org.gvsig.raster.netcdf/tags/v2.2.1/prepare-workspace.xml
1
<project name="org.gvsig.initial.build" default="prepare-workspace">
2

  
3
	<dirname property="org.gvsig.initial.build.basedir" file="${ant.file.org.gvsig.initial.build}" />
4

  
5
	<property name="workspace.basedir" value="${org.gvsig.initial.build.basedir}/.." />
6
	<property name="build.basedir" value="${workspace.basedir}/org.gvsig.maven.base.build" description="Eclipse workspace location" />
7
	<property name="build.jar.version" value="1.0.8-SNAPSHOT" />
8
	<property name="build.jar.file" value="org.gvsig.maven.base.build-${build.jar.version}.jar" />
9

  
10
	<property name="ant.libs.dir" location="${build.basedir}" description="Additional ant tasks libs folder" />
11

  
12
	<target name="check-maven-base-build-available">
13
		<available file="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" property="maven-base-build-available" />
14
	</target>
15

  
16
	<target name="get-maven-base-build-local" depends="check-maven-base-build-available" if="maven-base-build-available">
17
		<!-- Unzip de build jar file from the maven repository into the workspace root folder -->
18
		<copy todir="${workspace.basedir}" preservelastmodified="false" filtering="false">
19
			<zipfileset src="${user.home}/.m2/repository/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}">
20
				<patternset>
21
					<exclude name="META-INF/**" />
22
				</patternset>
23
			</zipfileset>
24
		</copy>
25
	</target>
26

  
27
	<target name="get-maven-base-build-remote" depends="check-maven-base-build-available" unless="maven-base-build-available">
28
		<mkdir dir="target" />
29

  
30
		<!-- Download the build jar file -->
31
		<get src="http://devel.gvsig.org/m2repo/j2se/org/gvsig/org.gvsig.maven.base.build/${build.jar.version}/${build.jar.file}" dest="target/${build.jar.file}" verbose="true" />
32

  
33
		<!-- Unzip de build jar file into the workspace root folder -->
34
		<copy todir="${workspace.basedir}" preservelastmodified="false" filtering="false">
35
			<zipfileset src="target/${build.jar.file}">
36
				<patternset>
37
					<exclude name="META-INF/**" />
38
				</patternset>
39
			</zipfileset>
40
		</copy>
41

  
42
	</target>
43
	
44
	<target name="find.depends.natives.file">
45
	    <condition property="depends.natives.file.exists">
46
            <available file="${org.gvsig.initial.build.basedir}/DEPENDS_ON_NATIVE_LIBRARIES"/>
47
	    </condition>	
48
	</target>
49
	
50
	<target name="find.gvsig.platform.properties.file" 
51
			depends="find.depends.natives.file"
52
			if="depends.natives.file.exists">
53
	    <condition property="gvsig.platform.exists">
54
            <available file="${user.home}/.gvsig.platform.properties"/>
55
	    </condition>	
56
	</target>
57
	
58
	<target name="check.gvsig.platform.properties" 
59
			depends="find.gvsig.platform.properties.file">
60
		<fail if="depends.natives.file.exists" unless="gvsig.platform.exists">
61
ERROR!!
62
	
63
You have to define your gvSIG platform properties, 
64
by creating the file: ${user.home}/.gvsig.platform.properties
65
with the following content:
66

  
67
native_platform=linux
68
native_distribution=all
69
native_compiler=gcc4
70
native_arch=i386
71
native_libraryType=dynamic
72
export native_classifier=${native_platform}-${native_distribution}-${native_compiler}-${native_arch}-${native_libraryType}
73

  
74
Replace the fifth initial variables values with the ones appropiate 
75
to your platform.
76
	
77
If you use maven in the command line, you can use the previous file also
78
to define the MAVEN_OPTS environment variable, by adding to your 
79
.bash_rc file something like this:
80

  
81
if [ -f "${HOME}/.gvsig.platform.properties" ]
82
then
83
    . ${HOME}/.gvsig.platform.properties
84
    export MAVEN_OPTS="-Xmx256M -XX:MaxPermSize=64m -Dnative-classifier=${native_classifier}"
85
else
86
    export MAVEN_OPTS="-Xmx256M -XX:MaxPermSize=64m"
87
fi
88

  
89
It will work if you use the bash shell. In any other case or platform, you'll
90
have to define your MAVEN_OPTS environment variable and set the 
91
"native-classifier" parameter directly.
92
		</fail>			
93
	
94
	</target>
95

  
96
	<target name="prepare-workspace" depends="get-maven-base-build-local,get-maven-base-build-remote,check.gvsig.platform.properties">
97

  
98
		<mkdir dir="target" />
99

  
100
		<chmod dir="${build.basedir}/maven/bin" perm="u+x" includes="m2,mvn,mvnDebug" />
101

  
102
		<!-- Copy the maven launchers to the workspace metadata folder -->
103
		<copy todir="${workspace.basedir}/.metadata">
104
			<fileset dir="${build.basedir}/eclipse-launchers">
105
				<exclude name="**/org.eclipse.jdt.core.prefs" />
106
				<exclude name="**/org.eclipse.core.variables.prefs" />
107
			</fileset>
108
		</copy>
109

  
110
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" append="true">
111
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.jdt.core.prefs" />
112
		</concat>
113
		<concat destfile="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" append="true">
114
			<filelist dir="${build.basedir}/eclipse-launchers/.plugins/org.eclipse.core.runtime/.settings" files="org.eclipse.core.variables.prefs" />
115
		</concat>
116

  
117
		<!-- Configure the eclipse workspace -->
118
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-configure-eclipse-workspace" />
119

  
120
		<!-- Configure the gvSIG profile -->
121
		<ant antfile="${build.basedir}/check-gvsig-profile.xml" />
122

  
123
		<property name="user-settings-file-location" value="${user.home}/.m2/settings.xml" />
124

  
125
		<taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask">
126
			<classpath>
127
				<pathelement location="${ant.libs.dir}/com.oopsconsultancy.xmltask-1.16.1.jar" />
128
			</classpath>
129
		</taskdef>
130

  
131
		<xmltask source="${user-settings-file-location}" dest="${user-settings-file-location}">
132
			<copy path="//:settings/:profiles/:profile[:id/text() = 'gvsig-install']/:properties/:gvsig.install.dir/text()" property="current-gvsig-location" />
133
		</xmltask>
134

  
135
		<replace file="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.jdt.core.prefs" token="@GVSIG_HOME@" value="${current-gvsig-location}" />
136
		<replace file="${workspace.basedir}/.metadata/.plugins/org.eclipse.core.runtime/.settings/org.eclipse.core.variables.prefs" token="@GVSIG_HOME@" value="${current-gvsig-location}" />
137

  
138
		<!-- Compile, install and generate eclipse projects -->
139
		<ant antfile="${build.basedir}/maven-goals.xml" target="mvn-install-and-eclipse-eclipse" />
140

  
141
		<echo>INFORMATION!!!</echo>
142
		<echo>Restart eclipse and then proceed to import the subprojects contained into the main project</echo>
143

  
144
		<!-- TODO: copiar al proyecto de configuración general -->
145
	</target>
146

  
147
	<target name="clean">
148
		<delete dir="target" />
149
	</target>
150
	
151
</project>
0 152

  
org.gvsig.raster.netcdf/tags/v2.2.1/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.1</version>
7
	<name>org.gvsig.raster.netcdf</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.25</version>
14
    </parent>
15
    
16
    <repositories>
17
      <repository>
18
        <id>gvsig-public-http-repository</id>
19
        <name>gvSIG maven public HTTP repository</name>
20
        <url>http://devel.gvsig.org/m2repo/j2se</url>
21
        <releases>
22
          <enabled>true</enabled>
23
          <updatePolicy>daily</updatePolicy>
24
          <checksumPolicy>warn</checksumPolicy>
25
        </releases>
26
        <snapshots>
27
          <enabled>true</enabled>
28
          <updatePolicy>daily</updatePolicy>
29
          <checksumPolicy>warn</checksumPolicy>
30
        </snapshots>
31
      </repository>
32
    </repositories>
33
    
34
    <scm>
35
        <connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.netcdf/tags/v2.2.1</connection>
36
        <developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.netcdf/tags/v2.2.1</developerConnection>
37
        <url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.netcdf/tags/v2.2.1</url>
38
    </scm>
39
    <build>
40
        <plugins>
41
            <plugin>
42
                <groupId>org.apache.maven.plugins</groupId>
43
                <artifactId>maven-release-plugin</artifactId>
44
                <configuration>
45
                    <tagBase>https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.netcdf/tags/</tagBase>
46
                    <goals>deploy</goals>
47
                </configuration>
48
            </plugin>
49
        </plugins>
50
    </build>
51
    <dependencyManagement>
52
    	<dependencies>
53
	    	<dependency>
54
				<groupId>essi-unidata</groupId>
55
				<artifactId>netcdf-java</artifactId>
56
				<version>4.2</version>
57
			</dependency>
58
			<dependency>
59
				<groupId>org.gvsig</groupId>
60
				<artifactId>org.gvsig.raster.lib.api</artifactId>
61
				<version>2.2.1</version>
62
			</dependency>
63
	        <dependency>
64
	            <groupId>org.gvsig</groupId>
65
	            <artifactId>org.gvsig.raster.lib.impl</artifactId>
66
	            <version>2.2.1</version>
67
	        </dependency>
68
	        <dependency>
69
				<groupId>org.gvsig</groupId>
70
				<artifactId>org.gvsig.raster.cache.lib.api</artifactId>
71
				<version>2.2.0</version>
72
			</dependency>
73
			<!--<dependency>
74
				<groupId>org.gvsig</groupId>
75
				<artifactId>org.gvsig.jproj</artifactId>
76
				<version>2.0.1-SNAPSHOT</version>
77
				<classifier>${native_classifier}</classifier>
78
				<type>tar.gz</type>
79
			</dependency>-->
80
		    <dependency>
81
				<groupId>org.gvsig</groupId>
82
				<artifactId>org.gvsig.raster.fmap</artifactId>
83
				<version>2.2.1</version>
84
			</dependency>
85
			<dependency>
86
	            <groupId>org.gvsig</groupId>
87
	            <artifactId>org.gvsig.raster.netcdf.io</artifactId>
88
	            <version>2.2.1</version>
89
	        </dependency>
90
    	</dependencies>
91
    </dependencyManagement>
92
	<modules>
93
		<module>org.gvsig.raster.netcdf.io</module>
94
		<module>org.gvsig.raster.netcdf.app.netcdfclient</module>
95
	</modules>
96
</project>
0 97

  
org.gvsig.raster.netcdf/tags/v2.2.1/org.gvsig.raster.netcdf.io/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.netcdf.io.DefaultNetCDFIOLibrary
org.gvsig.raster.netcdf/tags/v2.2.1/org.gvsig.raster.netcdf.io/src/main/java/org/gvsig/raster/netcdf/io/NetCDFServerExplorerParameters.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 org.gvsig.fmap.dal.DataServerExplorerParameters;
31
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemServerExplorerParameters;
32
import org.gvsig.tools.ToolsLocator;
33
import org.gvsig.tools.dynobject.DelegatedDynObject;
34
import org.gvsig.tools.dynobject.DynClass;
35
import org.gvsig.tools.dynobject.DynField;
36
import org.gvsig.tools.dynobject.DynObjectManager;
37

  
38

  
39
/**
40
 * Parameters for the NetCDF explorer
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 */
43
public class NetCDFServerExplorerParameters extends FilesystemServerExplorerParameters
44
implements DataServerExplorerParameters {
45
	public static final String            PARAMS_NAME         = "NetCDFRasterServerExplorerParameters";
46
	protected static DynClass             DYNCLASS            = null;
47
	private static final String           FIELD_ROOT          = "root";
48
	private static DelegatedDynObject     delegatedDynObject  = null;
49

  
50
	public NetCDFServerExplorerParameters() {
51
		super();
52
		initialize();
53
	}
54

  
55
	protected void initialize() {
56
		delegatedDynObject = (DelegatedDynObject) ToolsLocator
57
				.getDynObjectManager().createDynObject(
58
						DYNCLASS);
59
	}
60
	
61
	public static DynClass registerDynClass() {
62
		DynObjectManager dynman = ToolsLocator.getDynObjectManager();
63
		DynClass dynClass = dynman.get(PARAMS_NAME);
64
		DynField field;
65
		if (dynClass == null) {
66
			dynClass = dynman.add(PARAMS_NAME);
67
			
68
			field = dynClass.addDynFieldString(FIELD_ROOT);
69
            field.setDescription("Root directory path of the explorer");
70
            field.setMandatory(false);
71
            field.setClassOfValue(String.class); 
72

  
73
			field = dynClass.addDynFieldString("initialpath");
74
            field.setDescription("Initial path of the explorer");
75
            field.setMandatory(false);
76
            field.setClassOfValue(String.class);
77
            DYNCLASS = dynClass;
78
		}
79
		return dynClass;
80
	}
81

  
82
	public void setRoot(String path) {
83
		this.setDynValue(FIELD_ROOT, path);
84
	}
85

  
86
	public String getRoot() {
87
		return (String) this.getDynValue(FIELD_ROOT);
88
	}
89

  
90
	public void setInitialpath(String path) {
91
		this.setDynValue("initialpath", path);
92
	}
93

  
94
	public String getInitialpath() {
95
		return (String) this.getDynValue("initialpath");
96
	}
97

  
98
	public String getExplorerName() {
99
		return NetCDFFilesystemServerExplorer.NAME;
100
	}
101

  
102
	public String getDataStoreName() {
103
		return NetCDFProvider.NAME;
104
	}
105
	
106
	public String getDescription() {
107
		return NetCDFProvider.DESCRIPTION;
108
	}
109

  
110
	protected DelegatedDynObject getDelegatedDynObject() {
111
		return delegatedDynObject;
112
	}
113
}
0 114

  
org.gvsig.raster.netcdf/tags/v2.2.1/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/v2.2.1/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/v2.2.1/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/v2.2.1/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/v2.2.1/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/v2.2.1/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
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff