Revision 1379
org.gvsig.raster.netcdf/tags/buildNumber_18/org.gvsig.raster.netcdf/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/buildNumber_18/org.gvsig.raster.netcdf/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.0.0-SNAPSHOT</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>gvsig-base-pom</artifactId> |
|
13 |
<version>2.0-SNAPSHOT</version> |
|
14 |
</parent> |
|
15 |
<scm> |
|
16 |
<connection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.app/trunk/org.gvsig.raster.app</connection> |
|
17 |
<developerConnection>scm:svn:https://devel.gvsig.org/svn/gvsig-raster/org.gvsig.raster.app/trunk/org.gvsig.raster.app</developerConnection> |
|
18 |
<url>https://devel.gvsig.org/redmine/projects/gvsig-raster/repository/show/org.gvsig.raster.netcdf/trunk/org.gvsig.raster.netcdf</url> |
|
19 |
</scm> |
|
20 |
<properties> |
|
21 |
<build-dir>${basedir}/../..</build-dir> |
|
22 |
</properties> |
|
23 |
<modules> |
|
24 |
<module>org.gvsig.raster.netcdf.io</module> |
|
25 |
<module>org.gvsig.raster.netcdf.app</module> |
|
26 |
</modules> |
|
27 |
</project> |
|
0 | 28 |
org.gvsig.raster.netcdf/tags/buildNumber_18/org.gvsig.raster.netcdf/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/buildNumber_18/org.gvsig.raster.netcdf/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.AbstractRasterDataParameters; |
|
38 |
import org.gvsig.raster.impl.store.AbstractRasterFileDataParameters; |
|
39 |
import org.gvsig.tools.ToolsLocator; |
|
40 |
import org.gvsig.tools.dynobject.DelegatedDynObject; |
|
41 |
import org.gvsig.tools.dynobject.DynClass; |
|
42 |
import org.gvsig.tools.dynobject.DynField; |
|
43 |
import org.gvsig.tools.dynobject.DynObjectManager; |
|
44 |
import org.gvsig.tools.dynobject.DynStruct; |
|
45 |
import org.gvsig.tools.persistence.PersistenceManager; |
|
46 |
import org.gvsig.tools.persistence.PersistentState; |
|
47 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
|
48 |
|
|
49 |
import ucar.nc2.Dimension; |
|
50 |
import ucar.nc2.NetcdfFile; |
|
51 |
import ucar.nc2.Variable; |
|
52 |
import ucar.nc2.dataset.CoordinateAxis1D; |
|
53 |
import ucar.nc2.dataset.CoordinateAxis1DTime; |
|
54 |
import ucar.nc2.dt.GridCoordSystem; |
|
55 |
import ucar.nc2.dt.GridDatatype; |
|
56 |
import ucar.nc2.dt.grid.GridDataset; |
|
57 |
|
|
58 |
/** |
|
59 |
* Parameters for the NetCDF provider |
|
60 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
61 |
*/ |
|
62 |
public class NetCDFDataParametersImpl extends AbstractRasterFileDataParameters implements NetCDFDataParameters { |
|
63 |
public static final String PARAMETERS_DEFINITION_NAME = "NetCDFRasterDataParameters"; |
|
64 |
private static DynClass DYNCLASS = null; |
|
65 |
|
|
66 |
private ArrayList<String[]> gridVarList = null; |
|
67 |
private ArrayList<Variable> varList = null; |
|
68 |
private HashMap<String, double[]> rankByVar = new HashMap<String, double[]>(); |
|
69 |
private HashMap<String, Date[]> dateByVar = new HashMap<String, Date[]>(); |
|
70 |
private String xDimVariable = null; |
|
71 |
private String yDimVariable = null; |
|
72 |
|
|
73 |
|
|
74 |
public NetCDFDataParametersImpl() { |
|
75 |
super(); |
|
76 |
initialize(); |
|
77 |
} |
|
78 |
|
|
79 |
protected void initialize() { |
|
80 |
delegatedDynObject = (DelegatedDynObject) ToolsLocator |
|
81 |
.getDynObjectManager().createDynObject( |
|
82 |
DYNCLASS); |
|
83 |
} |
|
84 |
|
|
85 |
public static void registerDynClass() { |
|
86 |
DynObjectManager dynman = ToolsLocator.getDynObjectManager(); |
|
87 |
DynClass dynClass; |
|
88 |
DynField field; |
|
89 |
|
|
90 |
if(dynman == null) |
|
91 |
return; |
|
92 |
|
|
93 |
if (DYNCLASS == null) { |
|
94 |
dynClass = AbstractRasterDataParameters.registerDynClass(PARAMETERS_DEFINITION_NAME); |
|
95 |
//dynClass = dynman.add(AbstractRasterDataParameters.DYNCLASS_NAME); |
|
96 |
|
|
97 |
field = dynClass.addDynFieldString(FIELD_VARIABLE); |
|
98 |
field.setDescription("Grid variable"); |
|
99 |
field.setMandatory(false); |
|
100 |
field.setClassOfValue(String.class); |
|
101 |
|
|
102 |
field = dynClass.addDynFieldInt(FIELD_LEVEL); |
|
103 |
field.setDescription("Level selected"); |
|
104 |
field.setMandatory(false); |
|
105 |
field.setClassOfValue(Integer.class); |
|
106 |
|
|
107 |
field = dynClass.addDynFieldInt(FIELD_TIME); |
|
108 |
field.setDescription("Time selected"); |
|
109 |
field.setMandatory(false); |
|
110 |
field.setClassOfValue(Integer.class); |
|
111 |
|
|
112 |
DYNCLASS = dynClass; |
|
113 |
} |
|
114 |
|
|
115 |
} |
|
116 |
|
|
117 |
/** |
|
118 |
* Gets the list of grids |
|
119 |
* @return A list of pair of values. The first element of one pair is the variable's name |
|
120 |
* and the second its description |
|
121 |
* @throws IOException |
|
122 |
*/ |
|
123 |
public ArrayList<Variable> getVariables() throws IOException { |
|
124 |
if(varList == null) { |
|
125 |
NetcdfFile netCDFFile = NetcdfFile.open(getFile().getAbsolutePath()); |
|
126 |
varList = new ArrayList<Variable>(); |
|
127 |
|
|
128 |
List<Variable> variableList = netCDFFile.getVariables(); |
|
129 |
Iterator<Variable> it = variableList.iterator(); |
|
130 |
while(it.hasNext()) { |
|
131 |
Variable var = it.next(); |
|
132 |
varList.add(var); |
|
133 |
} |
|
134 |
netCDFFile.close(); |
|
135 |
} |
|
136 |
return varList; |
|
137 |
} |
|
138 |
|
|
139 |
/** |
|
140 |
* Gets the list of grids |
|
141 |
* @return A list of pair of values. The first element of one pair is the variable's name |
|
142 |
* and the second its description |
|
143 |
* @throws IOException |
|
144 |
*/ |
|
145 |
public ArrayList<String[]> getGridVariables() throws IOException { |
|
146 |
if(gridVarList == null) { |
|
147 |
GridDataset connector = GridDataset.open(getFile().getAbsolutePath()); |
|
148 |
List<GridDatatype> gridList = connector.getGrids(); |
|
149 |
gridVarList = new ArrayList<String[]>(); |
|
150 |
Iterator<GridDatatype> it = gridList.iterator(); |
|
151 |
while(it.hasNext()) { |
|
152 |
GridDatatype dt = it.next(); |
|
153 |
|
|
154 |
//Loads name and description |
|
155 |
String[] pair = new String[2]; |
|
156 |
pair[0] = dt.getName(); |
|
157 |
pair[1] = dt.getDescription(); |
|
158 |
gridVarList.add(pair); |
|
159 |
|
|
160 |
//Loads variable's name |
|
161 |
Dimension dim = dt.getDimensions().get(dt.getXDimensionIndex()); |
|
162 |
xDimVariable = dim.getName(); |
|
163 |
dim = dt.getDimensions().get(dt.getYDimensionIndex()); |
|
164 |
yDimVariable = dim.getName(); |
|
165 |
|
|
166 |
if(dt.getShape() != null) { |
|
167 |
GridCoordSystem gcs = dt.getCoordinateSystem(); |
|
168 |
//Loads levels |
|
169 |
CoordinateAxis1D zAxis = gcs.getVerticalAxis(); |
|
170 |
if(zAxis != null) { |
|
171 |
double[] d = calcSliceValue(zAxis.getCoordEdges()); |
|
172 |
rankByVar.put(pair[0], d); |
|
173 |
} |
|
174 |
|
|
175 |
//Loads time list |
|
176 |
if (gcs.hasTimeAxis1D()) { |
|
177 |
CoordinateAxis1DTime tAxis1D = gcs.getTimeAxis1D(); |
|
178 |
Date[] dates = tAxis1D.getTimeDates(); |
|
179 |
dateByVar.put(pair[0], dates); |
|
180 |
} |
|
181 |
} |
|
182 |
} |
|
183 |
connector.close(); |
|
184 |
} |
|
185 |
return gridVarList; |
|
186 |
} |
|
187 |
|
|
188 |
/** |
|
189 |
* Calculates the array of levels |
|
190 |
* @param coordsEdges |
|
191 |
* @return |
|
192 |
*/ |
|
193 |
private double[] calcSliceValue(double[] coordsEdges) { |
|
194 |
if(coordsEdges == null) |
|
195 |
return null; |
|
196 |
double[] values = new double[coordsEdges.length - 1]; |
|
197 |
for (int i = 0; i < coordsEdges.length - 1; i++) { |
|
198 |
values[i] = ((coordsEdges[i] + coordsEdges[i + 1]) / 2); |
|
199 |
} |
|
200 |
return values; |
|
201 |
} |
|
202 |
|
|
203 |
/** |
|
204 |
* Gets the list of dates |
|
205 |
* @param var |
|
206 |
* @return |
|
207 |
*/ |
|
208 |
public Date[] getTimeList(String var) { |
|
209 |
return dateByVar.get(var); |
|
210 |
} |
|
211 |
|
|
212 |
/** |
|
213 |
* Gets the number of levels of one variable |
|
214 |
* @param var |
|
215 |
* @return |
|
216 |
*/ |
|
217 |
public double[] getLevelList(String var) { |
|
218 |
return rankByVar.get(var); |
|
219 |
} |
|
220 |
|
|
221 |
/** |
|
222 |
* Gets the variable's name of the X dimension |
|
223 |
* @return |
|
224 |
*/ |
|
225 |
public String getXDimVariable() { |
|
226 |
return xDimVariable; |
|
227 |
} |
|
228 |
|
|
229 |
/** |
|
230 |
* Gets the variable's name of the Y dimension |
|
231 |
* @return |
|
232 |
*/ |
|
233 |
public String getYDimVariable() { |
|
234 |
return yDimVariable; |
|
235 |
} |
|
236 |
|
|
237 |
/* |
|
238 |
* (non-Javadoc) |
|
239 |
* @see org.gvsig.fmap.dal.DataStoreParameters#getDataStoreName() |
|
240 |
*/ |
|
241 |
public String getDataStoreName() { |
|
242 |
return NetCDFProvider.NAME; |
|
243 |
} |
|
244 |
|
|
245 |
/* |
|
246 |
* (non-Javadoc) |
|
247 |
* @see org.gvsig.fmap.dal.DataStoreParameters#getDescription() |
|
248 |
*/ |
|
249 |
public String getDescription() { |
|
250 |
return NetCDFProvider.DESCRIPTION; |
|
251 |
} |
|
252 |
|
|
253 |
/* |
|
254 |
* (non-Javadoc) |
|
255 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.TimeStoreParameters#selectNextInstant() |
|
256 |
*/ |
|
257 |
public void selectNextInstant() { |
|
258 |
int i = getFieldTime() + 1; |
|
259 |
if(i < getTimeListLength()) { |
|
260 |
setDynValue(NetCDFDataParameters.FIELD_TIME, i); |
|
261 |
} |
|
262 |
} |
|
263 |
|
|
264 |
/* |
|
265 |
* (non-Javadoc) |
|
266 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.TimeStoreParameters#selectPrevInstant() |
|
267 |
*/ |
|
268 |
public void selectPrevInstant() { |
|
269 |
int i = getFieldTime() - 1; |
|
270 |
if(i >= 0) { |
|
271 |
setDynValue(NetCDFDataParameters.FIELD_TIME, i); |
|
272 |
} |
|
273 |
} |
|
274 |
|
|
275 |
/* |
|
276 |
* (non-Javadoc) |
|
277 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.TimeStoreParameters#goTo(int) |
|
278 |
*/ |
|
279 |
public void goTo(int position) { |
|
280 |
if(position < getTimeListLength() && position >= 0) { |
|
281 |
setDynValue(NetCDFDataParameters.FIELD_TIME, position); |
|
282 |
} |
|
283 |
} |
|
284 |
|
|
285 |
/* |
|
286 |
* (non-Javadoc) |
|
287 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.TimeStoreParameters#getFieldTime() |
|
288 |
*/ |
|
289 |
public int getFieldTime() { |
|
290 |
if(hasDynValue(NetCDFDataParameters.FIELD_TIME)) { |
|
291 |
return ((Integer)getDynValue(NetCDFDataParameters.FIELD_TIME)).intValue(); |
|
292 |
} |
|
293 |
return 0; |
|
294 |
} |
|
295 |
|
|
296 |
/* |
|
297 |
* (non-Javadoc) |
|
298 |
* @see org.gvsig.raster.netcdf.io.NetCDFDataParameters#getFieldLevel() |
|
299 |
*/ |
|
300 |
public int getFieldLevel() { |
|
301 |
if(hasDynValue(NetCDFDataParameters.FIELD_LEVEL)) { |
|
302 |
return ((Integer)getDynValue(NetCDFDataParameters.FIELD_LEVEL)).intValue(); |
|
303 |
} |
|
304 |
return 0; |
|
305 |
} |
|
306 |
|
|
307 |
/* |
|
308 |
* (non-Javadoc) |
|
309 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.TimeStoreParameters#getFieldVariable() |
|
310 |
*/ |
|
311 |
public String getStringVariable() { |
|
312 |
if(hasDynValue(NetCDFDataParameters.FIELD_VARIABLE)) { |
|
313 |
return (String)getDynValue(NetCDFDataParameters.FIELD_VARIABLE); |
|
314 |
} |
|
315 |
|
|
316 |
//We will use the first variable in the list |
|
317 |
|
|
318 |
try { |
|
319 |
ArrayList<String[]> vars = getGridVariables(); |
|
320 |
if(vars.size() > 0) { |
|
321 |
String[] var = vars.get(0); |
|
322 |
if(var.length > 0) { |
|
323 |
setFieldVariable(var[0]); |
|
324 |
return var[0]; |
|
325 |
} |
|
326 |
} |
|
327 |
} catch (IOException e) { |
|
328 |
e.printStackTrace(); |
|
329 |
} |
|
330 |
return null; |
|
331 |
} |
|
332 |
|
|
333 |
/* |
|
334 |
* (non-Javadoc) |
|
335 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.TimeStoreParameters#getFieldLevel() |
|
336 |
*/ |
|
337 |
public String getStringLevel() { |
|
338 |
if(!hasDynValue(NetCDFDataParameters.FIELD_LEVEL)) { |
|
339 |
//We will use the first level in the list |
|
340 |
setFieldLevel(0); |
|
341 |
} |
|
342 |
|
|
343 |
int index = ((Integer)getDynValue(NetCDFDataParameters.FIELD_LEVEL)).intValue(); |
|
344 |
double[] levelList = getLevelList(getStringVariable()); |
|
345 |
if(levelList == null) |
|
346 |
return "-1"; |
|
347 |
return levelList[index] + ""; |
|
348 |
} |
|
349 |
|
|
350 |
/* |
|
351 |
* (non-Javadoc) |
|
352 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.TimeStoreParameters#getStringTime() |
|
353 |
*/ |
|
354 |
public String getStringTime() { |
|
355 |
if(!hasDynValue(NetCDFDataParameters.FIELD_TIME)) { |
|
356 |
setFieldTime(0); |
|
357 |
} |
|
358 |
|
|
359 |
int index = ((Integer)getDynValue(NetCDFDataParameters.FIELD_TIME)).intValue(); |
|
360 |
Date[] timeList = getTimeList(getStringVariable()); |
|
361 |
if(timeList == null) |
|
362 |
return "-1"; |
|
363 |
return timeList[index].toString(); |
|
364 |
} |
|
365 |
|
|
366 |
/** |
|
367 |
* Gets the length of the time list |
|
368 |
* @return |
|
369 |
*/ |
|
370 |
private int getTimeListLength() { |
|
371 |
String var = (String)getDynValue(NetCDFDataParameters.FIELD_VARIABLE); |
|
372 |
if(var != null) { |
|
373 |
Date[] dateList = getTimeList(var); |
|
374 |
if(dateList != null) |
|
375 |
return dateList.length; |
|
376 |
} |
|
377 |
return 0; |
|
378 |
} |
|
379 |
|
|
380 |
/* |
|
381 |
* (non-Javadoc) |
|
382 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.MultiDimensionalStoreParameters#setFieldVariable(java.lang.String) |
|
383 |
*/ |
|
384 |
public void setFieldVariable(String variable) { |
|
385 |
setDynValue(NetCDFDataParameters.FIELD_VARIABLE, variable); |
|
386 |
} |
|
387 |
|
|
388 |
/* |
|
389 |
* (non-Javadoc) |
|
390 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.TimeStoreParameters#setFieldTime(int) |
|
391 |
*/ |
|
392 |
public void setFieldTime(int timePosInList) { |
|
393 |
setDynValue(NetCDFDataParameters.FIELD_TIME, timePosInList); |
|
394 |
} |
|
395 |
|
|
396 |
/* |
|
397 |
* (non-Javadoc) |
|
398 |
* @see org.gvsig.fmap.dal.coverage.store.parameter.MultiDimensionalStoreParameters#setFieldLevel(int) |
|
399 |
*/ |
|
400 |
public void setFieldLevel(int levelPosInList) { |
|
401 |
setDynValue(NetCDFDataParameters.FIELD_LEVEL, levelPosInList); |
|
402 |
} |
|
403 |
|
|
404 |
public static void registerPersistence() { |
|
405 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
|
406 |
DynStruct definition = manager.getDefinition("NetCDFDataParametersImpl_Persistent"); |
|
407 |
if( definition == null ) { |
|
408 |
definition = manager.addDefinition( |
|
409 |
NetCDFDataParametersImpl.class, |
|
410 |
"NetCDFDataParametersImpl_Persistent", |
|
411 |
"NetCDF DataParameters Persistency", |
|
412 |
null, |
|
413 |
null |
|
414 |
); |
|
415 |
AbstractRasterDataParameters.registerPersistence(definition); |
|
416 |
|
|
417 |
definition.addDynFieldString(FIELD_VARIABLE).setMandatory(false); |
|
418 |
definition.addDynFieldInt(FIELD_LEVEL).setMandatory(false); |
|
419 |
definition.addDynFieldInt(FIELD_TIME).setMandatory(false); |
|
420 |
definition.addDynFieldString(FIELD_XDIM).setMandatory(false); |
|
421 |
definition.addDynFieldString(FIELD_YDIM).setMandatory(false); |
|
422 |
} |
|
423 |
} |
|
424 |
|
|
425 |
@Override |
|
426 |
public void saveToState(PersistentState state) throws PersistenceException { |
|
427 |
super.saveToState(state); |
|
428 |
|
|
429 |
state.set(FIELD_VARIABLE, getStringVariable()); |
|
430 |
state.set(FIELD_LEVEL, getFieldLevel()); |
|
431 |
state.set(FIELD_TIME, getFieldTime()); |
|
432 |
state.set(FIELD_XDIM, getXDimVariable()); |
|
433 |
state.set(FIELD_YDIM, getYDimVariable()); |
|
434 |
} |
|
435 |
|
|
436 |
@Override |
|
437 |
public void loadFromState(PersistentState state) |
|
438 |
throws PersistenceException { |
|
439 |
super.loadFromState(state); |
|
440 |
|
|
441 |
setFieldVariable(state.getString(FIELD_VARIABLE)); |
|
442 |
setFieldTime(state.getInt(FIELD_TIME)); |
|
443 |
setFieldLevel(state.getInt(FIELD_LEVEL)); |
|
444 |
xDimVariable = state.getString(FIELD_XDIM); |
|
445 |
yDimVariable = state.getString(FIELD_YDIM); |
|
446 |
} |
|
447 |
} |
|
0 | 448 |
org.gvsig.raster.netcdf/tags/buildNumber_18/org.gvsig.raster.netcdf/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 |
NetCDFDataParametersImpl.registerPersistence(); |
|
44 |
} |
|
45 |
} |
|
0 | 46 |
org.gvsig.raster.netcdf/tags/buildNumber_18/org.gvsig.raster.netcdf/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.io.IOException; |
|
27 |
import java.util.List; |
|
28 |
|
|
29 |
import org.gvsig.fmap.dal.DALFileLocator; |
|
30 |
import org.gvsig.fmap.dal.DALLocator; |
|
31 |
import org.gvsig.fmap.dal.DataStore; |
|
32 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
|
33 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
|
34 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
|
35 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
|
36 |
import org.gvsig.fmap.dal.coverage.exception.BandAccessException; |
|
37 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
|
38 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
|
39 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
|
40 |
import org.gvsig.fmap.dal.coverage.exception.ParsingException; |
|
41 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
|
42 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
|
43 |
import org.gvsig.fmap.dal.coverage.store.parameter.RasterFileStoreParameters; |
|
44 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
|
45 |
import org.gvsig.fmap.dal.exception.OpenException; |
|
46 |
import org.gvsig.fmap.dal.spi.DataManagerProviderServices; |
|
47 |
import org.gvsig.fmap.dal.spi.DataStoreProviderServices; |
|
48 |
import org.gvsig.metadata.MetadataLocator; |
|
49 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
|
50 |
import org.gvsig.raster.cache.tile.provider.TileServer; |
|
51 |
import org.gvsig.raster.impl.DefaultRasterManager; |
|
52 |
import org.gvsig.raster.impl.datastruct.DefaultNoData; |
|
53 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
|
54 |
import org.gvsig.raster.impl.provider.DefaultRasterProvider; |
|
55 |
import org.gvsig.raster.impl.provider.RasterProvider; |
|
56 |
import org.gvsig.raster.impl.provider.tile.FileTileServer; |
|
57 |
import org.gvsig.raster.impl.store.DefaultStoreFactory; |
|
58 |
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation; |
|
59 |
import org.gvsig.raster.impl.store.properties.DataStoreTransparency; |
|
60 |
import org.gvsig.tools.ToolsLocator; |
|
61 |
import org.gvsig.tools.task.TaskStatus; |
|
62 |
import org.slf4j.Logger; |
|
63 |
import org.slf4j.LoggerFactory; |
|
64 |
|
|
65 |
import ucar.ma2.Array; |
|
66 |
import ucar.ma2.DataType; |
|
67 |
import ucar.ma2.InvalidRangeException; |
|
68 |
import ucar.ma2.Range; |
|
69 |
import ucar.nc2.dt.GridDatatype; |
|
70 |
import ucar.nc2.dt.grid.GridDataset; |
|
71 |
import ucar.unidata.geoloc.ProjectionRect; |
|
72 |
/** |
|
73 |
* Data provider for NetCDF files with raster data |
|
74 |
* |
|
75 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
76 |
*/ |
|
77 |
public class NetCDFProvider extends DefaultRasterProvider { |
|
78 |
public static String NAME = "NetCDF Raster"; |
|
79 |
public static String DESCRIPTION = "NetCDF Raster file"; |
|
80 |
public final String METADATA_DEFINITION_NAME = NAME; |
|
81 |
private Extent viewRequest = null; |
|
82 |
private TileServer tileServer = null; |
|
83 |
private boolean open = false; |
|
84 |
|
|
85 |
private GridDataset gridNetCDF = null; |
|
86 |
private List<GridDatatype> gridList = null; |
|
87 |
private GridDatatype selectedGridDataType = null; |
|
88 |
private DataStoreTransparency fileTransparency = null; |
|
89 |
private static final Logger logger = LoggerFactory.getLogger(NetCDFProvider.class); |
|
90 |
protected static String[] formatList = null; |
|
91 |
|
|
92 |
public static void register() { |
|
93 |
DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager(); |
|
94 |
RasterLocator.getManager().registerFileProvidersTiled(NetCDFProvider.class); |
|
95 |
registerFormats(); |
|
96 |
|
|
97 |
if (dataman != null && !dataman.getStoreProviders().contains(NAME)) { |
|
98 |
dataman.registerStoreProvider(NAME, |
|
99 |
NetCDFProvider.class, NetCDFDataParametersImpl.class); |
|
100 |
} |
|
101 |
|
|
102 |
|
|
103 |
/*if (!dataman.getExplorerProviders().contains(NetCDFFilesystemServerExplorer.NAME)) { |
|
104 |
dataman.registerExplorerProvider(NetCDFFilesystemServerExplorer.NAME, NetCDFFilesystemServerExplorer.class, NetCDFServerExplorerParameters.class); |
|
105 |
}*/ |
|
106 |
|
|
107 |
if(DALFileLocator.getFilesystemServerExplorerManager() != null) |
|
108 |
DALFileLocator.getFilesystemServerExplorerManager().registerProvider( |
|
109 |
NAME, DESCRIPTION, |
|
110 |
NetCDFFilesystemServerExplorer.class); |
|
111 |
|
|
112 |
|
|
113 |
dataman.registerStoreFactory(NAME, DefaultStoreFactory.class); |
|
114 |
} |
|
115 |
|
|
116 |
private static void registerFormats() { |
|
117 |
formatList = new String[] {"nc"}; |
|
118 |
for (int i = 0; i < formatList.length; i++) |
|
119 |
RasterLocator.getManager().addFormat(formatList[i], NetCDFProvider.class); |
|
120 |
} |
|
121 |
|
|
122 |
/* |
|
123 |
* (non-Javadoc) |
|
124 |
* @see org.gvsig.raster.impl.provider.RasterProvider#getFormatList() |
|
125 |
*/ |
|
126 |
public String[] getFormatList() { |
|
127 |
return formatList; |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Returns true if the extension is supported and false if doesn't |
|
132 |
* @param ext |
|
133 |
* @return |
|
134 |
*/ |
|
135 |
public boolean isExtensionSupported(String ext) { |
|
136 |
if(ext.indexOf(".") != -1) |
|
137 |
ext = ext.substring(ext.lastIndexOf(".") + 1, ext.length()); |
|
138 |
for (int i = 0; i < formatList.length; i++) { |
|
139 |
if(formatList[i].compareTo(ext) == 0) |
|
140 |
return true; |
|
141 |
} |
|
142 |
return false; |
|
143 |
} |
|
144 |
|
|
145 |
public NetCDFProvider() { |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Opens the dataset. |
|
150 |
* @param proj Projection |
|
151 |
* @param fName File name |
|
152 |
* @throws NotSupportedExtensionException |
|
153 |
*/ |
|
154 |
public NetCDFProvider(String params) throws NotSupportedExtensionException, OpenException { |
|
155 |
super(params); |
|
156 |
if(params instanceof String) { |
|
157 |
NetCDFDataParameters p = new NetCDFDataParametersImpl(); |
|
158 |
p.setURI((String)params); |
|
159 |
super.init(p, null, ToolsLocator.getDynObjectManager() |
|
160 |
.createDynObject( |
|
161 |
MetadataLocator.getMetadataManager().getDefinition( |
|
162 |
DataStore.METADATA_DEFINITION_NAME))); |
|
163 |
init(p, null); |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
public NetCDFProvider (NetCDFDataParameters params, |
|
168 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException { |
|
169 |
super(params, storeServices, ToolsLocator.getDynObjectManager() |
|
170 |
.createDynObject( |
|
171 |
MetadataLocator.getMetadataManager().getDefinition( |
|
172 |
DataStore.METADATA_DEFINITION_NAME))); |
|
173 |
init(params, storeServices); |
|
174 |
} |
|
175 |
|
|
176 |
/** |
|
177 |
* Build file references |
|
178 |
* @param proj Projection |
|
179 |
* @param param Load parameters |
|
180 |
* @throws NotSupportedExtensionException |
|
181 |
*/ |
|
182 |
public void init (NetCDFDataParameters params, |
|
183 |
DataStoreProviderServices storeServices) throws NotSupportedExtensionException, OpenException { |
|
184 |
|
|
185 |
if(((RasterFileStoreParameters)params).getFile().exists()) { |
|
186 |
String fileName = ((RasterFileStoreParameters)params).getFile().getAbsolutePath(); |
|
187 |
try { |
|
188 |
gridNetCDF = GridDataset.open(fileName); |
|
189 |
gridList = gridNetCDF.getGrids(); |
|
190 |
if(gridList.size() == 0) |
|
191 |
throw new OpenException("There is not a grid variable", null); |
|
192 |
selectedGridDataType = gridList.get(0); |
|
193 |
//netCDFFile = NetcdfFile.open(((RasterFileStoreParameters)params).getFile().getAbsolutePath()); |
|
194 |
} catch (IOException e) { |
|
195 |
throw new OpenException("Imposible to read the file", e); |
|
196 |
} |
|
197 |
|
|
198 |
/*List<Variable> variableList = netCDFFile.getVariables(); |
|
199 |
Iterator<Variable> it = variableList.iterator(); |
|
200 |
while(it.hasNext()) { |
|
201 |
Variable var = it.next(); |
|
202 |
System.out.println("===>>" + var.getName()); |
|
203 |
}*/ |
|
204 |
|
|
205 |
setParam(storeServices, params); |
|
206 |
reloadMetadataFromGrid(); |
|
207 |
|
|
208 |
noData = new DefaultNoData(Double.NaN, Double.NaN, fileName); |
|
209 |
load(); |
|
210 |
} else |
|
211 |
setParam(storeServices, params); |
|
212 |
|
|
213 |
super.init(); |
|
214 |
selectSubdataset(getId(0, 0, 0)); |
|
215 |
try { |
|
216 |
loadFromRmf(getRmfBlocksManager()); |
|
217 |
} catch (ParsingException e) { |
|
218 |
//No lee desde rmf |
|
219 |
} |
|
220 |
open = true; |
|
221 |
} |
|
222 |
|
|
223 |
/** |
|
224 |
* Reloads metadata using the selected grid |
|
225 |
*/ |
|
226 |
private void reloadMetadataFromGrid() { |
|
227 |
wktProjection = null; |
|
228 |
//CrsWkt crs = new CrsWkt(wktProjection); |
|
229 |
//IProjection proj = CRSFactory.getCRS("EPSG:23030"); |
|
230 |
|
|
231 |
/*LatLonRect gcs = selectedGridDataType.getCoordinateSystem().getLatLonBoundingBox(); |
|
232 |
getColorInterpretation(); |
|
233 |
double scaleX = gcs.getWidth() / selectedGridDataType.getXDimension().getLength(); |
|
234 |
double scaleY = gcs.getHeight() / selectedGridDataType.getYDimension().getLength(); |
|
235 |
ownTransformation = new AffineTransform( |
|
236 |
scaleX, 0, |
|
237 |
0, -scaleY, |
|
238 |
gcs.getLonMin(), |
|
239 |
gcs.getLatMax());*/ |
|
240 |
|
|
241 |
ProjectionRect pRect = selectedGridDataType.getCoordinateSystem().getBoundingBox(); |
|
242 |
double scaleX = pRect.getWidth() / selectedGridDataType.getXDimension().getLength(); |
|
243 |
double scaleY = pRect.getHeight() / selectedGridDataType.getYDimension().getLength(); |
|
244 |
ownTransformation = new AffineTransform( |
|
245 |
scaleX, 0, |
|
246 |
0, -scaleY, |
|
247 |
pRect.getMinX(), |
|
248 |
pRect.getMaxY()); |
|
249 |
externalTransformation = (AffineTransform)ownTransformation.clone(); |
|
250 |
bandCount = 1; //One variable is always shown |
|
251 |
setDataType(); |
|
252 |
} |
|
253 |
|
|
254 |
/** |
|
255 |
* @param dataType The dataType to set. |
|
256 |
*/ |
|
257 |
private void setDataType() { |
|
258 |
DataType dt = selectedGridDataType.getDataType(); |
|
259 |
int type = Buffer.TYPE_UNDEFINED; |
|
260 |
if(dt.name() == DataType.BYTE.name()) { |
|
261 |
type = Buffer.TYPE_BYTE; |
|
262 |
} |
|
263 |
if(dt.name() == DataType.SHORT.name()) { |
|
264 |
type = Buffer.TYPE_SHORT; |
|
265 |
} |
|
266 |
if(dt.name() == DataType.INT.name()) { |
|
267 |
type = Buffer.TYPE_INT; |
|
268 |
} |
|
269 |
if(dt.name() == DataType.DOUBLE.name()) { |
|
270 |
type = Buffer.TYPE_DOUBLE; |
|
271 |
} |
|
272 |
if(dt.name() == DataType.FLOAT.name()) { |
|
273 |
type = Buffer.TYPE_FLOAT; |
|
274 |
} |
|
275 |
if(dt.name() == DataType.LONG.name()) { |
|
276 |
type = Buffer.TYPE_DOUBLE; |
|
277 |
} |
|
278 |
|
|
279 |
int[] dtype = new int[getBandCount()]; |
|
280 |
for (int i = 0; i < dtype.length; i++) |
|
281 |
dtype[i] = type; |
|
282 |
setDataType(dtype); |
|
283 |
} |
|
284 |
|
|
285 |
/* |
|
286 |
* (non-Javadoc) |
|
287 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#load() |
|
288 |
*/ |
|
289 |
public RasterProvider load() { |
|
290 |
return this; |
|
291 |
} |
|
292 |
|
|
293 |
/* |
|
294 |
* (non-Javadoc) |
|
295 |
* @see org.gvsig.raster.impl.provider.RasterProvider#isOpen() |
|
296 |
*/ |
|
297 |
public boolean isOpen() { |
|
298 |
return open; |
|
299 |
} |
|
300 |
|
|
301 |
/* |
|
302 |
* (non-Javadoc) |
|
303 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#close() |
|
304 |
*/ |
|
305 |
public void close() { |
|
306 |
try { |
|
307 |
gridNetCDF.close(); |
|
308 |
} catch (IOException e) { |
|
309 |
logger.error("Error closing file", e); |
|
310 |
} |
|
311 |
} |
|
312 |
|
|
313 |
/* |
|
314 |
* (non-Javadoc) |
|
315 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#translateFileName(java.lang.String) |
|
316 |
*/ |
|
317 |
public String translateFileName(String fileName) { |
|
318 |
return fileName; |
|
319 |
} |
|
320 |
|
|
321 |
/** |
|
322 |
* Asigna el extent de la vista actual. existe un fichero .rmf debemos hacer una transformaci�n |
|
323 |
* de la vista asignada ya que la petici�n viene en coordenadas del fichero .rmf y la vista (v) |
|
324 |
* ha de estar en coordenadas del fichero. |
|
325 |
*/ |
|
326 |
public void setView(Extent e) { |
|
327 |
viewRequest = new ExtentImpl(e); |
|
328 |
} |
|
329 |
|
|
330 |
/* |
|
331 |
* (non-Javadoc) |
|
332 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getView() |
|
333 |
*/ |
|
334 |
public Extent getView() { |
|
335 |
return viewRequest; |
|
336 |
} |
|
337 |
|
|
338 |
/* |
|
339 |
* (non-Javadoc) |
|
340 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWidth() |
|
341 |
*/ |
|
342 |
public double getWidth() { |
|
343 |
return selectedGridDataType.getXDimension().getLength(); |
|
344 |
} |
|
345 |
|
|
346 |
/* |
|
347 |
* (non-Javadoc) |
|
348 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getHeight() |
|
349 |
*/ |
|
350 |
public double getHeight() { |
|
351 |
return selectedGridDataType.getYDimension().getLength(); |
|
352 |
} |
|
353 |
|
|
354 |
/* |
|
355 |
* (non-Javadoc) |
|
356 |
* @see org.gvsig.raster.dataset.RasterDataset#readBlock(int, int, double) |
|
357 |
*/ |
|
358 |
public Object readBlock(int pos, int blockHeight, double scale) |
|
359 |
throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException { |
|
360 |
NetCDFDataParameters p = (NetCDFDataParameters)param; |
|
361 |
if(pos < 0) |
|
362 |
throw new InvalidSetViewException("Request out of grid"); |
|
363 |
|
|
364 |
if((pos + blockHeight) > getHeight()) |
|
365 |
blockHeight = Math.abs(((int)getHeight()) - pos); |
|
366 |
|
|
367 |
Buffer buf = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], (int)getWidth(), blockHeight, 1, true); |
|
368 |
try { |
|
369 |
int time = p.getFieldTime(); |
|
370 |
int level = getLevelValue(); |
|
371 |
Range rangeY = new Range(pos, pos + blockHeight - 1, 1); |
|
372 |
Range rangeX = new Range(0, (int)(getWidth() - 1), 1); |
|
373 |
GridDatatype dt = selectedGridDataType.makeSubset(null, null, null, null /*getTime(1), getLevel(1)*/, rangeY, rangeX); |
|
374 |
Array values = dt.readDataSlice(time, level, -1, -1); |
|
375 |
return arrayValuesToBuffer(values, buf, rangeX.length(), rangeY.length(), null); |
|
376 |
} catch (IOException e) { |
|
377 |
throw new RasterDriverException("Error reading a slice", e); |
|
378 |
} catch (InvalidRangeException e) { |
|
379 |
throw new RasterDriverException("Error reading a slice", e); |
|
380 |
} |
|
381 |
} |
|
382 |
|
|
383 |
/* |
|
384 |
* (non-Javadoc) |
|
385 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getData(int, int, int) |
|
386 |
*/ |
|
387 |
public Object getData(int x, int y, int band)throws InvalidSetViewException, FileNotOpenException, RasterDriverException { |
|
388 |
NetCDFDataParameters p = (NetCDFDataParameters)param; |
|
389 |
if(x < 0 || y < 0 || x >= getWidth() || y >= getHeight()) |
|
390 |
throw new InvalidSetViewException("Request out of grid"); |
|
391 |
try { |
|
392 |
int strideX = 1; |
|
393 |
int strideY = 1; |
|
394 |
Range rangeY = new Range((int)(getHeight() - y), (int)(getHeight() - y), strideY); |
|
395 |
Range rangeX = new Range(x, x, strideX); |
|
396 |
|
|
397 |
selectSubdataset(); |
|
398 |
int time = p.getFieldTime(); |
|
399 |
int level = getLevelValue(); |
|
400 |
GridDatatype dt = selectedGridDataType.makeSubset(null, null, null, null, rangeY, rangeX); |
|
401 |
Array values = dt.readDataSlice(time, level, -1, -1); |
|
402 |
Object data = null; |
|
403 |
|
|
404 |
if(getDataType()[0] == Buffer.TYPE_BYTE) { |
|
405 |
data = new java.lang.Integer(values.getByte(0)); |
|
406 |
} |
|
407 |
|
|
408 |
if(getDataType()[0] == Buffer.TYPE_SHORT) { |
|
409 |
data = new java.lang.Integer(values.getShort(0)); |
|
410 |
} |
|
411 |
|
|
412 |
if(getDataType()[0] == Buffer.TYPE_INT) { |
|
413 |
data = new java.lang.Integer(values.getInt(0)); |
|
414 |
} |
|
415 |
|
|
416 |
if(getDataType()[0] == Buffer.TYPE_FLOAT) { |
|
417 |
data = new java.lang.Float(values.getFloat(0)); |
|
418 |
} |
|
419 |
if(getDataType()[0] == Buffer.TYPE_DOUBLE) { |
|
420 |
data = new java.lang.Double(values.getDouble(0)); |
|
421 |
} |
|
422 |
return data; |
|
423 |
} catch (IOException e) { |
|
424 |
throw new RasterDriverException("Error reading a slice", e); |
|
425 |
} catch (InvalidRangeException e) { |
|
426 |
throw new RasterDriverException("Error reading a slice", e); |
|
427 |
} |
|
428 |
} |
|
429 |
|
|
430 |
/* |
|
431 |
* (non-Javadoc) |
|
432 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.raster.cache.tile.provider.TileListener) |
|
433 |
*/ |
|
434 |
public void getWindow(Extent ex, int bufWidth, int bufHeight, |
|
435 |
BandList bandList, TileListener listener, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
436 |
} |
|
437 |
|
|
438 |
/* |
|
439 |
* (non-Javadoc) |
|
440 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer) |
|
441 |
*/ |
|
442 |
public Buffer getWindow(Extent extent, BandList bandList, Buffer rasterBuf, TaskStatus status) |
|
443 |
throws ProcessInterruptedException, RasterDriverException { |
|
444 |
NetCDFDataParameters p = (NetCDFDataParameters)param; |
|
445 |
setView(extent); |
|
446 |
|
|
447 |
Point2D ul = new Point2D.Double(viewRequest.getULX(), viewRequest.getULY()); |
|
448 |
Point2D lr = new Point2D.Double(viewRequest.getLRX(), viewRequest.getLRY()); |
|
449 |
ul = worldToRaster(ul); |
|
450 |
lr = worldToRaster(lr); |
|
451 |
ul.setLocation(ul.getX() < 0 ? 0 : ul.getX(), ul.getY() < 0 ? 0 : ul.getY()); |
|
452 |
lr.setLocation(lr.getX() < 0 ? 0 : lr.getX(), lr.getY() < 0 ? 0 : lr.getY()); |
|
453 |
ul.setLocation(ul.getX() > getWidth() ? getWidth() : ul.getX(), ul.getY() > getHeight() ? getHeight() : ul.getY()); |
|
454 |
lr.setLocation(lr.getX() > getWidth() ? getWidth() : lr.getX(), lr.getY() > getHeight() ? getHeight() : lr.getY()); |
|
455 |
|
|
456 |
adjustPoints(ul, lr); |
|
457 |
|
|
458 |
try { |
|
459 |
int strideX = 1; |
|
460 |
int strideY = 1; |
|
461 |
Range rangeY = new Range((int)(getHeight() - lr.getY()), (int)(getHeight() - ul.getY() - 1), strideY); |
|
462 |
Range rangeX = new Range((int)ul.getX(), (int)(lr.getX() - 1), strideX); |
|
463 |
|
|
464 |
selectSubdataset(); |
|
465 |
int time = p.getFieldTime(); |
|
466 |
int level = getLevelValue(); |
|
467 |
GridDatatype dt = selectedGridDataType.makeSubset(null, null, null, null /*getTime(strideX), getLevel(strideX)*/, rangeY, rangeX); |
|
468 |
Array values = dt.readDataSlice(time, level, -1, -1); |
|
469 |
rasterBuf = arrayValuesToBuffer(values, rasterBuf, rangeX.length(), rangeY.length(), bandList); |
|
470 |
} catch (IOException e) { |
|
471 |
throw new RasterDriverException("Error reading a slice", e); |
|
472 |
} catch (InvalidRangeException e) { |
|
473 |
throw new RasterDriverException("Error reading a slice", e); |
|
474 |
} |
|
475 |
|
|
476 |
return rasterBuf; |
|
477 |
} |
|
478 |
|
|
479 |
/** |
|
480 |
* Gets the Range of the selected time or null if there is not a selected time |
|
481 |
* @param strideX |
|
482 |
* @return |
|
483 |
* @throws InvalidRangeException |
|
484 |
*/ |
|
485 |
@SuppressWarnings("unused") |
|
486 |
private Range getTime(int strideX) throws InvalidRangeException { |
|
487 |
NetCDFDataParameters p = (NetCDFDataParameters)param; |
|
488 |
int time = p.getFieldTime(); |
|
489 |
return new Range(time, time, strideX); |
|
490 |
} |
|
491 |
|
|
492 |
/*private int getTimeValue() { |
|
493 |
int time = 0; |
|
494 |
if(param.hasDynValue(NetCDFDataParameters.FIELD_TIME)) |
|
495 |
time = ((Integer)param.getDynValue(NetCDFDataParameters.FIELD_TIME)).intValue(); |
|
496 |
return time; |
|
497 |
}*/ |
|
498 |
|
|
499 |
/** |
|
500 |
* Gets the Range of the selected level or null if there is not a selected level |
|
501 |
* @param strideX |
|
502 |
* @return |
|
503 |
* @throws InvalidRangeException |
|
504 |
*/ |
|
505 |
@SuppressWarnings("unused") |
|
506 |
private Range getLevel(int strideX) throws InvalidRangeException { |
|
507 |
int level = getLevelValue(); |
|
508 |
return new Range(level, level, strideX); |
|
509 |
} |
|
510 |
|
|
511 |
private int getLevelValue() { |
|
512 |
int level = 0; |
|
513 |
if(param.hasDynValue(NetCDFDataParameters.FIELD_LEVEL)) |
|
514 |
level = ((Integer)param.getDynValue(NetCDFDataParameters.FIELD_LEVEL)).intValue(); |
|
515 |
return level; |
|
516 |
} |
|
517 |
|
|
518 |
|
|
519 |
/** |
|
520 |
* Selects the GridDataType using the selected variable in the parameters |
|
521 |
*/ |
|
522 |
public void selectSubdataset() { |
|
523 |
if(param.hasDynValue(NetCDFDataParameters.FIELD_VARIABLE)) { |
|
524 |
NetCDFDataParameters p = (NetCDFDataParameters)param; |
|
525 |
String variable = (String)param.getDynValue(NetCDFDataParameters.FIELD_VARIABLE); |
|
526 |
if(variable != null) { |
|
527 |
for (int j = 0; j < gridList.size(); j++) { |
|
528 |
if(gridList.get(j).getName().compareTo(variable) == 0) { |
|
529 |
selectedGridDataType = gridList.get(j); |
|
530 |
reloadMetadataFromGrid(); |
|
531 |
super.selectSubdataset(getId(j, getLevelValue(), p.getFieldTime())); |
|
532 |
} |
|
533 |
} |
|
534 |
} |
|
535 |
} |
|
536 |
} |
|
537 |
|
|
538 |
/** |
|
539 |
* Gets the identifier of a subdataset |
|
540 |
* @param grid |
|
541 |
* @param level |
|
542 |
* @param time |
|
543 |
* @return |
|
544 |
*/ |
|
545 |
private String getId(int grid, int level, int time) { |
|
546 |
return grid + "-" + level + "-" + time; |
|
547 |
} |
|
548 |
|
|
549 |
/** |
|
550 |
* Loads a Buffer object from an netCDF Array. |
|
551 |
* @param values |
|
552 |
* @param rasterBuf |
|
553 |
* @param w |
|
554 |
* @param h |
|
555 |
* @return |
|
556 |
*/ |
|
557 |
private Buffer arrayValuesToBuffer(Array values, Buffer rasterBuf, int w, int h, BandList bandList) { |
|
558 |
Buffer buf = null; |
|
559 |
boolean resampling = false; |
|
560 |
|
|
561 |
if((rasterBuf.getWidth() * rasterBuf.getHeight()) != values.getSize()) { |
|
562 |
buf = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], w, h, rasterBuf.getBandCount(), true); |
|
563 |
resampling = true; |
|
564 |
} else |
|
565 |
buf = rasterBuf; |
|
566 |
|
|
567 |
int[] drawableBands = bandList != null ? bandList.getBufferBandToDraw(getURIOfFirstProvider(), 0) : new int[1]; |
|
568 |
if(drawableBands == null || (drawableBands.length == 1 && drawableBands[0] == -1)) |
|
569 |
return rasterBuf; |
|
570 |
|
|
571 |
if(getDataType()[0] == Buffer.TYPE_BYTE) { |
|
572 |
for (int i = 0; i < values.getSize(); i++) { |
|
573 |
int[] rc = getColAndRow(i, buf); |
|
574 |
for (int iBands = 0; iBands < drawableBands.length; iBands++) |
|
575 |
buf.setElem(rc[0], rc[1], drawableBands[iBands], values.getByte(i)); |
|
576 |
} |
|
577 |
} |
|
578 |
|
|
579 |
if(getDataType()[0] == Buffer.TYPE_SHORT) { |
|
580 |
for (int i = 0; i < values.getSize(); i++) { |
|
581 |
int[] rc = getColAndRow(i, buf); |
|
582 |
for (int iBands = 0; iBands < drawableBands.length; iBands++) |
|
583 |
buf.setElem(rc[0], rc[1], drawableBands[iBands], values.getShort(i)); |
|
584 |
} |
|
585 |
} |
|
586 |
|
|
587 |
if(getDataType()[0] == Buffer.TYPE_INT) { |
|
588 |
for (int i = 0; i < values.getSize(); i++) { |
|
589 |
int[] rc = getColAndRow(i, buf); |
|
590 |
for (int iBands = 0; iBands < drawableBands.length; iBands++) |
|
591 |
buf.setElem(rc[0], rc[1], drawableBands[iBands], values.getInt(i)); |
|
592 |
} |
|
593 |
} |
|
594 |
|
|
595 |
if(getDataType()[0] == Buffer.TYPE_FLOAT) { |
|
596 |
for (int i = 0; i < values.getSize(); i++) { |
|
597 |
int[] rc = getColAndRow(i, buf); |
|
598 |
for (int iBands = 0; iBands < drawableBands.length; iBands++) |
|
599 |
buf.setElem(rc[0], rc[1], drawableBands[iBands], values.getFloat(i)); |
|
600 |
} |
|
601 |
} |
|
602 |
|
|
603 |
if(getDataType()[0] == Buffer.TYPE_DOUBLE) { |
|
604 |
for (int i = 0; i < values.getSize(); i++) { |
|
605 |
int[] rc = getColAndRow(i, buf); |
|
606 |
for (int iBands = 0; iBands < drawableBands.length; iBands++) |
|
607 |
buf.setElem(rc[0], rc[1], drawableBands[iBands], values.getDouble(i)); |
|
608 |
} |
|
609 |
} |
|
610 |
if(resampling) { |
|
611 |
try { |
|
612 |
Buffer result = null; |
|
613 |
result = buf.getAdjustedWindow(rasterBuf.getWidth(), rasterBuf.getHeight(), Buffer.INTERPOLATION_NearestNeighbour); |
|
614 |
if(result != buf) |
|
615 |
buf.dispose(); |
|
616 |
return result; |
|
617 |
} catch (ProcessInterruptedException e) { |
|
618 |
return buf; |
|
619 |
} |
|
620 |
} |
|
621 |
return buf; |
|
622 |
} |
|
623 |
|
|
624 |
/** |
|
625 |
* Calculates the row and column number for the position i in the |
|
626 |
* array of data |
|
627 |
* @param i |
|
628 |
* @param buf |
|
629 |
* @return |
|
630 |
*/ |
|
631 |
private int[] getColAndRow(int i, Buffer buf) { |
|
632 |
int auxRow = (int)(i / buf.getWidth()); |
|
633 |
return new int[]{ |
|
634 |
(int)buf.getHeight() - auxRow - 1, |
|
635 |
i - (auxRow * buf.getWidth()) |
|
636 |
}; |
|
637 |
} |
|
638 |
|
|
639 |
/* |
|
640 |
* (non-Javadoc) |
|
641 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean) |
|
642 |
*/ |
|
643 |
public Buffer getWindow(double ulx, double uly, double w, double h, |
|
644 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
645 |
return rasterBuf; |
|
646 |
} |
|
647 |
|
|
648 |
/* |
|
649 |
* (non-Javadoc) |
|
650 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(double, double, double, double, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean) |
|
651 |
*/ |
|
652 |
public Buffer getWindow(Extent extent, int bufWidth, int bufHeight, |
|
653 |
BandList bandList, Buffer rasterBuf, boolean adjustToExtent, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
654 |
NetCDFDataParameters p = (NetCDFDataParameters)param; |
|
655 |
setView(extent); |
|
656 |
|
|
657 |
Point2D ul = new Point2D.Double(viewRequest.getULX(), viewRequest.getULY()); |
|
658 |
Point2D lr = new Point2D.Double(viewRequest.getLRX(), viewRequest.getLRY()); |
|
659 |
ul = worldToRaster(ul); |
|
660 |
lr = worldToRaster(lr); |
|
661 |
ul.setLocation(ul.getX() < 0 ? 0 : ul.getX(), ul.getY() < 0 ? 0 : ul.getY()); |
|
662 |
lr.setLocation(lr.getX() < 0 ? 0 : lr.getX(), lr.getY() < 0 ? 0 : lr.getY()); |
|
663 |
ul.setLocation(ul.getX() >= getWidth() ? getWidth() - 1 : ul.getX(), ul.getY() >= getHeight() ? getHeight() - 1 : ul.getY()); |
|
664 |
lr.setLocation(lr.getX() >= getWidth() ? getWidth() - 1 : lr.getX(), lr.getY() >= getHeight() ? getHeight() - 1 : lr.getY()); |
|
665 |
|
|
666 |
adjustPoints(ul, lr); |
|
667 |
|
|
668 |
int width = Math.abs(((int)lr.getX()) - ((int)ul.getX())); |
|
669 |
int height = Math.abs(((int)lr.getY()) - ((int)ul.getY())); |
|
670 |
|
|
671 |
try { |
|
672 |
int strideX = width / rasterBuf.getWidth(); |
|
673 |
int strideY = height / rasterBuf.getHeight(); |
|
674 |
Range rangeY = new Range((int)(getHeight() - lr.getY()), (int)(getHeight() - ul.getY() - 1), strideY <= 0 ? 1 : strideY); |
|
675 |
Range rangeX = new Range((int)ul.getX(), (int)(lr.getX() - 1), strideX <= 0 ? 1 : strideX); |
|
676 |
|
|
677 |
selectSubdataset(); |
|
678 |
int time = p.getFieldTime(); |
|
679 |
int level = getLevelValue(); |
|
680 |
GridDatatype dt = selectedGridDataType.makeSubset(null, null, null, null /*getTime(strideX), getLevel(strideX)*/, rangeY, rangeX); |
|
681 |
Array values = dt.readDataSlice(time, level, -1, -1); |
|
682 |
rasterBuf = arrayValuesToBuffer(values, rasterBuf, rangeX.length(), rangeY.length(), bandList); |
|
683 |
} catch (IOException e) { |
|
684 |
throw new RasterDriverException("Error reading a slice", e); |
|
685 |
} catch (InvalidRangeException e) { |
|
686 |
throw new RasterDriverException("Error reading a slice", e); |
|
687 |
} |
|
688 |
|
|
689 |
return rasterBuf; |
|
690 |
} |
|
691 |
|
|
692 |
private void adjustPoints(Point2D ul, Point2D lr) { |
|
693 |
double a = (ul.getX() - (int)ul.getX()); |
|
694 |
double b = (ul.getY() - (int)ul.getY()); |
|
695 |
ul.setLocation( (a > 0.95 || a < 0.05) ? Math.round(ul.getX()) : ul.getX(), |
|
696 |
(b > 0.95 || b < 0.05) ? Math.round(ul.getY()) : ul.getY()); |
|
697 |
lr.setLocation( (a > 0.95 || a < 0.05) ? Math.round(lr.getX()) : lr.getX(), |
|
698 |
(b > 0.95 || b < 0.05) ? Math.round(lr.getY()) : lr.getY()); |
|
699 |
} |
|
700 |
|
|
701 |
/* |
|
702 |
* (non-Javadoc) |
|
703 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer) |
|
704 |
*/ |
|
705 |
public Buffer getWindow(int x, int y, int w, int h, |
|
706 |
BandList bandList, Buffer rasterBuf, TaskStatus status) throws ProcessInterruptedException, RasterDriverException { |
|
707 |
try { |
|
708 |
NetCDFDataParameters p = (NetCDFDataParameters)param; |
|
709 |
int strideX = 1; |
|
710 |
int strideY = 1; |
|
711 |
Range rangeY = new Range((int)(h - y), (int)(h - y - 1), strideY); |
|
712 |
Range rangeX = new Range((int)x, (int)(x + w - 1), strideX); |
|
713 |
|
|
714 |
selectSubdataset(); |
|
715 |
int time = p.getFieldTime(); |
|
716 |
int level = getLevelValue(); |
|
717 |
GridDatatype dt = selectedGridDataType.makeSubset(null, null, null, null, rangeY, rangeX); |
|
718 |
Array values = dt.readDataSlice(time, level, -1, -1); |
|
719 |
rasterBuf = arrayValuesToBuffer(values, rasterBuf, rangeX.length(), rangeY.length(), bandList); |
|
720 |
} catch (IOException e) { |
|
721 |
throw new RasterDriverException("Error reading a slice", e); |
|
722 |
} catch (InvalidRangeException e) { |
|
723 |
throw new RasterDriverException("Error reading a slice", e); |
|
724 |
} |
|
725 |
|
|
726 |
return rasterBuf; |
|
727 |
} |
|
728 |
|
|
729 |
/* |
|
730 |
* (non-Javadoc) |
|
731 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getBlockSize() |
|
732 |
*/ |
|
733 |
public int getBlockSize(){ |
|
734 |
return 0; |
|
735 |
} |
|
736 |
|
|
737 |
/* |
|
738 |
* (non-Javadoc) |
|
739 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getColorInterpretation() |
|
740 |
*/ |
|
741 |
public ColorInterpretation getColorInterpretation() { |
|
742 |
if(super.getColorInterpretation() == null) { |
|
743 |
setColorInterpretation(new DataStoreColorInterpretation(new String[]{ColorInterpretation.GRAY_BAND})); |
|
744 |
} |
|
745 |
return super.getColorInterpretation(); |
|
746 |
} |
|
747 |
|
|
748 |
/* |
|
749 |
* (non-Javadoc) |
|
750 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getTransparency() |
|
751 |
*/ |
|
752 |
public DataStoreTransparency getTransparency() { |
|
753 |
if(fileTransparency == null) |
|
754 |
fileTransparency = new DataStoreTransparency(); |
|
755 |
return fileTransparency; |
|
756 |
} |
|
757 |
|
|
758 |
/** |
|
759 |
* Informa de si el driver ha supersampleado en el �ltimo dibujado. Es el driver el que colocar� |
|
760 |
* el valor de esta variable cada vez que dibuja. |
|
761 |
* @return true si se ha supersampleado y false si no se ha hecho. |
|
762 |
*/ |
|
763 |
public boolean isSupersampling() { |
|
764 |
return false; |
|
765 |
} |
|
766 |
|
|
767 |
/* |
|
768 |
* (non-Javadoc) |
|
769 |
* @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setAffineTransform(java.awt.geom.AffineTransform) |
|
770 |
*/ |
|
771 |
public void setAffineTransform(AffineTransform t){ |
|
772 |
super.setAffineTransform(t); |
|
773 |
} |
|
774 |
|
|
775 |
/* |
Also available in: Unified diff