Revision 418

View differences:

org.gvsig.raster.wcs/trunk/org.gvsig.raster.wcs/distribution/distribution.xml
1
<assembly>
2
</assembly>
0 3

  
org.gvsig.raster.wcs/trunk/org.gvsig.raster.wcs/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.gvsig.raster.wcs</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
	</buildSpec>
9
	<natures>
10
	</natures>
11
</projectDescription>
0 12

  
org.gvsig.raster.wcs/trunk/org.gvsig.raster.wcs/org.gvsig.raster.wcs.io/pom.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
	xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
4
	<modelVersion>4.0.0</modelVersion>
5
	<artifactId>org.gvsig.raster.wcs.io</artifactId>
6
	<packaging>jar</packaging>
7
	<name>org.gvsig.raster.wcs.io</name>
8
	<version>2.0.1-SNAPSHOT</version>
9
	<parent>
10
		<groupId>org.gvsig</groupId>
11
		<artifactId>gvsig-base-library-pom</artifactId>
12
		<version>2.0-SNAPSHOT</version>
13
	</parent>
14
    <scm>
15
        <connection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-raster/org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.io/org.gvsig.raster.io.base</connection>
16
        <developerConnection>scm:svn:https://svn.forge.osor.eu/svn/gvsig-raster/org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.io/org.gvsig.raster.io.base</developerConnection>
17
        <url>https://forge.osor.eu/plugins/scmsvn/viewcvs.php/org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.io/org.gvsig.raster.io.base?root=gvsig-raster</url>
18
    </scm>
19
    <properties>
20
        <build-dir>${basedir}/../../../build</build-dir>
21
    </properties>
22
	<dependencies>
23
		<dependency>
24
			<groupId>org.gvsig</groupId>
25
			<artifactId>org.gvsig.raster.lib.api</artifactId>
26
			<version>2.0.1-SNAPSHOT</version>
27
            <scope>compile</scope>
28
		</dependency>
29
        <dependency>
30
            <groupId>org.gvsig</groupId>
31
            <artifactId>org.gvsig.raster.lib.impl</artifactId>
32
            <version>2.0.1-SNAPSHOT</version>
33
            <scope>compile</scope>
34
        </dependency>
35
        <dependency>
36
            <groupId>org.gvsig</groupId>
37
            <artifactId>org.gvsig.fmap.dal</artifactId>
38
            <scope>compile</scope>
39
        </dependency>
40
        <dependency>
41
            <groupId>org.gvsig</groupId>
42
            <artifactId>org.gvsig.fmap.dal</artifactId>
43
            <classifier>spi</classifier>
44
            <scope>compile</scope>
45
        </dependency>
46
        <dependency>
47
            <groupId>org.gvsig</groupId>
48
            <artifactId>org.gvsig.fmap.dal</artifactId>
49
            <version>2.0-SNAPSHOT</version>
50
            <scope>compile</scope>
51
        </dependency>
52
        <dependency>
53
            <groupId>org.gvsig</groupId>
54
            <artifactId>org.gvsig.fmap.dal.file</artifactId>
55
            <scope>compile</scope>
56
        </dependency>
57
        <dependency>
58
            <groupId>org.gvsig</groupId>
59
            <artifactId>org.gvsig.metadata.lib.basic.api</artifactId>
60
            <scope>compile</scope>
61
        </dependency>
62
        <dependency>
63
            <groupId>org.gvsig</groupId>
64
            <artifactId>org.gvsig.remoteclient</artifactId>
65
            <scope>compile</scope>
66
        </dependency>
67
        <dependency>
68
            <groupId>org.gvsig</groupId>
69
            <artifactId>org.gvsig.projection</artifactId>
70
            <scope>compile</scope>
71
        </dependency>
72
        <dependency>
73
            <groupId>org.gvsig</groupId>
74
            <artifactId>org.gvsig.compat</artifactId>
75
            <scope>compile</scope>
76
        </dependency>
77
        <dependency>
78
            <groupId>org.gvsig</groupId>
79
            <artifactId>org.gvsig.fmap.geometry</artifactId>
80
            <scope>compile</scope>
81
        </dependency>
82
		<dependency>
83
			<groupId>org.gvsig</groupId>
84
			<artifactId>org.gvsig.jproj</artifactId>
85
			<version>2.0.1-SNAPSHOT</version>
86
			<classifier>${native-classifier}</classifier>
87
			<type>tar.gz</type>
88
            <scope>runtime</scope>
89
		</dependency>
90
		<dependency>
91
            <groupId>org.gvsig</groupId>
92
            <artifactId>org.gvsig.tools.lib</artifactId>
93
            <scope>compile</scope>
94
        </dependency>
95
        <dependency>
96
            <groupId>org.gvsig</groupId>
97
            <artifactId>org.gvsig.raster.io.base</artifactId>
98
            <version>2.0.1-SNAPSHOT</version>
99
            <scope>compile</scope>
100
        </dependency>
101
	</dependencies>
102
</project>
0 103

  
org.gvsig.raster.wcs/trunk/org.gvsig.raster.wcs/org.gvsig.raster.wcs.io/resources/README.txt
1
Put into this folder the resources needed by your test classes.
2

  
3
This folder is added to the Tests classpath, so you can load any resources 
4
through the ClassLoader.
5

  
6
By default, in this folder you can find an example of log4j configuration,
7
prepared to log messages through the console, so logging works when you
8
run your tests classes.
0 9

  
org.gvsig.raster.wcs/trunk/org.gvsig.raster.wcs/org.gvsig.raster.wcs.io/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.wcs.io.DefaultWCSIOLibrary
org.gvsig.raster.wcs/trunk/org.gvsig.raster.wcs/org.gvsig.raster.wcs.io/.settings/org.eclipse.jdt.core.prefs
1
#Wed Apr 13 18:36:59 CEST 2011
2
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
3
eclipse.preferences.version=1
4
org.eclipse.jdt.core.compiler.source=1.5
5
org.eclipse.jdt.core.compiler.compliance=1.5
0 6

  
org.gvsig.raster.wcs/trunk/org.gvsig.raster.wcs/org.gvsig.raster.wcs.io/.classpath
1
<classpath>
2
  <classpathentry kind="src" path="src/test/java" output="target/test-classes" including="**/*.java"/>
3
  <classpathentry kind="src" path="src/test/resources" output="target/test-classes" excluding="**/*.java"/>
4
  <classpathentry kind="src" path="src/main/java" including="**/*.java"/>
5
  <classpathentry kind="src" path="src/main/resources" excluding="**/*.java"/>
6
  <classpathentry kind="output" path="target/classes"/>
7
  <classpathentry kind="var" path="M2_REPO/javax/media/jai_codec/1.1.3/jai_codec-1.1.3.jar"/>
8
  <classpathentry kind="var" path="M2_REPO/javax/media/jai_core/1.1.3/jai_core-1.1.3.jar">
9
    <attributes>
10
      <attribute value="jar:file:/home/nacho/.m2/repository/javax/media/jai_core/1.1.3/jai_core-1.1.3-javadoc.jar!/" name="javadoc_location"/>
11
    </attributes>
12
  </classpathentry>
13
  <classpathentry kind="var" path="M2_REPO/javax/units/jsr108/0.01/jsr108-0.01.jar"/>
14
  <classpathentry kind="var" path="M2_REPO/castor/castor/0.9.5.3/castor-0.9.5.3.jar"/>
15
  <classpathentry kind="var" path="M2_REPO/org/opengis/geoapi/2.0/geoapi-2.0.jar"/>
16
  <classpathentry kind="var" path="M2_REPO/geojava/geojava/unknown/geojava-unknown.jar"/>
17
  <classpathentry kind="var" path="M2_REPO/org/geotools/gt2-legacy/unknown/gt2-legacy-unknown.jar"/>
18
  <classpathentry kind="var" path="M2_REPO/org/geotools/gt2-main/unknown/gt2-main-unknown.jar"/>
19
  <classpathentry kind="var" path="M2_REPO/com/vividsolutions/jts/1.9/jts-1.9.jar" sourcepath="M2_REPO/com/vividsolutions/jts/1.9/jts-1.9-sources.jar"/>
20
  <classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar" sourcepath="M2_REPO/junit/junit/3.8.1/junit-3.8.1-sources.jar"/>
21
  <classpathentry kind="var" path="M2_REPO/net/sf/kxml/kxml2/2.2.2/kxml2-2.2.2.jar"/>
22
  <classpathentry kind="var" path="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14.jar" sourcepath="M2_REPO/log4j/log4j/1.2.14/log4j-1.2.14-sources.jar"/>
23
  <classpathentry kind="var" path="M2_REPO/essi-unidata/netcdf-java/4.2/netcdf-java-4.2.jar"/>
24
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.compat/2.0-SNAPSHOT/org.gvsig.compat-2.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.compat/2.0-SNAPSHOT/org.gvsig.compat-2.0-SNAPSHOT-sources.jar"/>
25
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.dxf/2.0-SNAPSHOT/org.gvsig.dxf-2.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.dxf/2.0-SNAPSHOT/org.gvsig.dxf-2.0-SNAPSHOT-sources.jar"/>
26
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.fmap.dal/2.0-SNAPSHOT/org.gvsig.fmap.dal-2.0-SNAPSHOT-impl.jar"/>
27
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.fmap.dal/2.0-SNAPSHOT/org.gvsig.fmap.dal-2.0-SNAPSHOT-spi.jar"/>
28
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.fmap.dal/2.0-SNAPSHOT/org.gvsig.fmap.dal-2.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.fmap.dal/2.0-SNAPSHOT/org.gvsig.fmap.dal-2.0-SNAPSHOT-sources.jar"/>
29
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.fmap.dal.file/2.0-SNAPSHOT/org.gvsig.fmap.dal.file-2.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.fmap.dal.file/2.0-SNAPSHOT/org.gvsig.fmap.dal.file-2.0-SNAPSHOT-sources.jar"/>
30
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.fmap.geometry/2.0-SNAPSHOT/org.gvsig.fmap.geometry-2.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.fmap.geometry/2.0-SNAPSHOT/org.gvsig.fmap.geometry-2.0-SNAPSHOT-sources.jar"/>
31
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.fmap.geometry/2.0-SNAPSHOT/org.gvsig.fmap.geometry-2.0-SNAPSHOT-operation.jar"/>
32
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.fmap.mapcontext/2.0-SNAPSHOT/org.gvsig.fmap.mapcontext-2.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.fmap.mapcontext/2.0-SNAPSHOT/org.gvsig.fmap.mapcontext-2.0-SNAPSHOT-sources.jar"/>
33
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.i18n/2.0.1-SNAPSHOT/org.gvsig.i18n-2.0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.i18n/2.0.1-SNAPSHOT/org.gvsig.i18n-2.0.1-SNAPSHOT-sources.jar"/>
34
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.jdk.v1_6/1.0.0-SNAPSHOT/org.gvsig.jdk.v1_6-1.0.0-SNAPSHOT.jar"/>
35
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.jecw/2.0.0-SNAPSHOT/org.gvsig.jecw-2.0.0-SNAPSHOT.jar"/>
36
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.jgdal/2.0.1-SNAPSHOT/org.gvsig.jgdal-2.0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.jgdal/2.0.1-SNAPSHOT/org.gvsig.jgdal-2.0.1-SNAPSHOT-sources.jar"/>
37
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.jmrsid/2.0.0-SNAPSHOT/org.gvsig.jmrsid-2.0.0-SNAPSHOT.jar"/>
38
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.jpotrace/2.0.0-SNAPSHOT/org.gvsig.jpotrace-2.0.0-SNAPSHOT.jar"/>
39
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.maven.base.tools/1.0.7-SNAPSHOT/org.gvsig.maven.base.tools-1.0.7-SNAPSHOT.jar"/>
40
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.metadata.lib.basic.api/1.0.0-SNAPSHOT/org.gvsig.metadata.lib.basic.api-1.0.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.metadata.lib.basic.api/1.0.0-SNAPSHOT/org.gvsig.metadata.lib.basic.api-1.0.0-SNAPSHOT-sources.jar"/>
41
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.metadata.lib.basic.impl/1.0.0-SNAPSHOT/org.gvsig.metadata.lib.basic.impl-1.0.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.metadata.lib.basic.impl/1.0.0-SNAPSHOT/org.gvsig.metadata.lib.basic.impl-1.0.0-SNAPSHOT-sources.jar"/>
42
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.projection/2.0-SNAPSHOT/org.gvsig.projection-2.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.projection/2.0-SNAPSHOT/org.gvsig.projection-2.0-SNAPSHOT-sources.jar"/>
43
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.projection/2.0-SNAPSHOT/org.gvsig.projection-2.0-SNAPSHOT-cresques-impl.jar"/>
44
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.raster.cache.lib.api/2.0.0-SNAPSHOT/org.gvsig.raster.cache.lib.api-2.0.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.raster.cache.lib.api/2.0.0-SNAPSHOT/org.gvsig.raster.cache.lib.api-2.0.0-SNAPSHOT-sources.jar"/>
45
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.raster.io.base/2.0.1-SNAPSHOT/org.gvsig.raster.io.base-2.0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.raster.io.base/2.0.1-SNAPSHOT/org.gvsig.raster.io.base-2.0.1-SNAPSHOT-sources.jar"/>
46
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.raster.lib.api/2.0.1-SNAPSHOT/org.gvsig.raster.lib.api-2.0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.raster.lib.api/2.0.1-SNAPSHOT/org.gvsig.raster.lib.api-2.0.1-SNAPSHOT-sources.jar"/>
47
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.raster.lib.impl/2.0.1-SNAPSHOT/org.gvsig.raster.lib.impl-2.0.1-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.raster.lib.impl/2.0.1-SNAPSHOT/org.gvsig.raster.lib.impl-2.0.1-SNAPSHOT-sources.jar"/>
48
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.remoteclient/2.0-SNAPSHOT/org.gvsig.remoteclient-2.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.remoteclient/2.0-SNAPSHOT/org.gvsig.remoteclient-2.0-SNAPSHOT-sources.jar"/>
49
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.symbology.lib.api/2.0.0-SNAPSHOT/org.gvsig.symbology.lib.api-2.0.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.symbology.lib.api/2.0.0-SNAPSHOT/org.gvsig.symbology.lib.api-2.0.0-SNAPSHOT-sources.jar"/>
50
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.tools.evaluator.sqljep/2.0-SNAPSHOT/org.gvsig.tools.evaluator.sqljep-2.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.tools.evaluator.sqljep/2.0-SNAPSHOT/org.gvsig.tools.evaluator.sqljep-2.0-SNAPSHOT-sources.jar"/>
51
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.tools.lib/3.0.0-SNAPSHOT/org.gvsig.tools.lib-3.0.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.tools.lib/3.0.0-SNAPSHOT/org.gvsig.tools.lib-3.0.0-SNAPSHOT-sources.jar"/>
52
  <classpathentry kind="var" path="M2_REPO/org/gvsig/org.gvsig.utils/2.0-SNAPSHOT/org.gvsig.utils-2.0-SNAPSHOT.jar" sourcepath="M2_REPO/org/gvsig/org.gvsig.utils/2.0-SNAPSHOT/org.gvsig.utils-2.0-SNAPSHOT-sources.jar"/>
53
  <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-api/1.5.5/slf4j-api-1.5.5.jar" sourcepath="M2_REPO/org/slf4j/slf4j-api/1.5.5/slf4j-api-1.5.5-sources.jar"/>
54
  <classpathentry kind="var" path="M2_REPO/org/slf4j/slf4j-log4j12/1.5.5/slf4j-log4j12-1.5.5.jar" sourcepath="M2_REPO/org/slf4j/slf4j-log4j12/1.5.5/slf4j-log4j12-1.5.5-sources.jar"/>
55
  <classpathentry kind="var" path="M2_REPO/net/sf/sqljep/0.2/sqljep-0.2.jar"/>
56
  <classpathentry kind="var" path="M2_REPO/xmlpull/xmlpull/1.1.3.1/xmlpull-1.1.3.1.jar"/>
57
  <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
58
</classpath>
0 59

  
org.gvsig.raster.wcs/trunk/org.gvsig.raster.wcs/org.gvsig.raster.wcs.io/.project
1
<projectDescription>
2
  <name>org.gvsig.raster.wmts.io</name>
3
  <comment>Base POM for all GvSIG projects</comment>
4
  <projects/>
5
  <buildSpec>
6
    <buildCommand>
7
      <name>org.eclipse.jdt.core.javabuilder</name>
8
    </buildCommand>
9
  </buildSpec>
10
  <natures>
11
    <nature>org.eclipse.jdt.core.javanature</nature>
12
  </natures>
13
</projectDescription>
0 14

  
org.gvsig.raster.wcs/trunk/org.gvsig.raster.wcs/org.gvsig.raster.wcs.io/src/main/resources/META-INF/services/org.gvsig.tools.library.Library
1
org.gvsig.raster.wcs.io.DefaultWCSIOLibrary
org.gvsig.raster.wcs/trunk/org.gvsig.raster.wcs/org.gvsig.raster.wcs.io/src/main/java/org/gvsig/raster/wcs/io/WCSConnector.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.wcs.io;
23

  
24
import java.awt.geom.Point2D;
25
import java.awt.geom.Rectangle2D;
26
import java.io.File;
27
import java.io.IOException;
28
import java.net.ConnectException;
29
import java.net.URL;
30
import java.util.ArrayList;
31
import java.util.Hashtable;
32
import java.util.Iterator;
33
import java.util.Set;
34

  
35
import org.gvsig.compat.net.ICancellable;
36
import org.gvsig.fmap.dal.coverage.datastruct.FMapWCSParameter;
37
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
38
import org.gvsig.raster.impl.datastruct.DefaultFMapWCSParameter;
39
import org.gvsig.raster.impl.datastruct.WCSLayerNode;
40
import org.gvsig.remoteclient.exceptions.ServerErrorException;
41
import org.gvsig.remoteclient.exceptions.WCSException;
42
import org.gvsig.remoteclient.utils.BoundaryBox;
43
import org.gvsig.remoteclient.wcs.WCSClient;
44
import org.gvsig.remoteclient.wcs.WCSCoverage;
45
import org.gvsig.remoteclient.wcs.WCSStatus;
46
import org.gvsig.remoteclient.wcs.WCSCoverage.AxisDescription;
47

  
48
/**
49
 * Connector between a WCS data provider and a WCSClient. 
50
 *
51
 * @author Nacho Brodin (nachobrodin@gmail.com)
52
 */
53
@SuppressWarnings("unchecked")
54
public class WCSConnector  {
55
	private WCSClient                     client;
56
    //private TreeMap<String, WMSLayerNode> layers = new TreeMap<String, WMSLayerNode>();
57
	private Hashtable                     coverages;
58
    private WCSLayerNode[]                layerList;
59
    
60
    public WCSConnector(URL url) throws ConnectException, IOException {
61
    	client = new WCSClient(url.toString());
62
    }
63

  
64
	/**
65
	 * Returns the string "WCSDriver", which is the driver's name.
66
	 *
67
	 * Devuelve "WCSDriver", el nombre del driver.
68
	 * @return String
69
	 */
70
	public String getName() { 
71
		return "WCSDriver"; 
72
	}
73

  
74
	/**
75
	 * Sets the server that we want to connect to.
76
	 *
77
	 * Establece el servidor al que se quiere conectar.
78
	 *
79
	 * @param host
80
	 * @throws IOException
81
	 */
82
	public void setHost(String host) throws IOException{
83
		client = new WCSClient(host);
84
	}
85

  
86

  
87
	/**
88
	 * Returns a human-readable string containing the server's name.
89
	 *
90
	 * Devuelve el nombre legible del servidor devuelto por ?ste.
91
	 *
92
	 * @return String
93
	 */
94
	public String getLabel() {
95
		return client.getServiceTitle();
96
	}
97

  
98
	/**
99
	 * Returns a string containing the server's WCS version number.
100
	 *
101
	 * Devuelve el n?mero de versi?n WCS del servidor
102
	 *
103
	 * @return String
104
	 */
105
	public String getVersion(){
106
		return client.getVersion();
107
	}
108

  
109
	/**
110
	 * <p>
111
	 * Returns name and description of the server. It is supposed to be used
112
	 * as the source of the abstract field in your application's interface.
113
	 * </p>
114
	 * <p>
115
	 * Devuelve nombre y descripci?n (abstract) del servidor.
116
	 * </p>
117
	 * @return String
118
	 */
119
	public String getDescription(){
120
		return client.getDescription();
121
	}
122

  
123
	/**
124
	 * Returns the layer descriptor for a given coverage name.
125
	 * @param layerName
126
	 * @return WCSLayer
127
	 */
128
	public WCSLayerNode getLayer(String layerName) {
129
		getLayerList();
130
		return (WCSLayerNode) coverages.get(layerName);
131
	}
132

  
133
	/**
134
	 * Returns an array of WCSLayer's with the descriptors of all coverages
135
	 * @return WCSLayer[]
136
	 */
137
	public WCSLayerNode[] getLayerList() {
138
		if (coverages == null || coverages.isEmpty()) {
139
			// the WCSLayer collection will be built
140
			coverages = new Hashtable();
141
			Hashtable wcsCoverages  = client.getCoverageList();
142
			int sz = wcsCoverages.size();
143

  
144
			// Create an array with the WCSCoverages
145
			WCSCoverage[] coverageList = new WCSCoverage[sz];
146
			Iterator it = wcsCoverages.keySet().iterator();
147
			int i = 0;
148
			while (it.hasNext()) {
149
				coverageList[i] = (WCSCoverage) wcsCoverages.get(it.next());
150
				i++;
151
			}
152

  
153
			// Create a WCSLayer array from the previous WCSCoverage array
154
			layerList = new WCSLayerNode[sz];
155
			for (int j = 0; j < layerList.length; j++) {
156
				WCSLayerNode lyr = new WCSLayerNode();
157
				WCSCoverage cov = coverageList[j];
158
				// name
159
				lyr.setName(cov.getName());
160

  
161
				// title
162
				lyr.setTitle(cov.getTitle());
163

  
164
				// description
165
				lyr.setDescription(cov.getAbstract());
166

  
167
				// srs
168
				lyr.addAllSrs(cov.getAllSrs());
169

  
170
				// native srs
171
				lyr.setNativeSRS(cov.getNativeSRS());
172

  
173
				// extents
174
				Set k = cov.getBBoxes().keySet();
175
				if (!k.isEmpty()) {
176
					it = k.iterator();
177
					while (it.hasNext()) {
178
						String srs = (String) it.next();
179
						BoundaryBox bBox = cov.getBbox(srs);
180
						Rectangle2D r = new Rectangle2D.Double(
181
								bBox.getXmin(),
182
								bBox.getYmin(),
183
								bBox.getXmax() - bBox.getXmin(),
184
								bBox.getYmax() - bBox.getYmin()
185
						);
186
						lyr.addExtent(srs, r);
187
					}
188
				}
189

  
190
				// formats
191
				lyr.setFormats(cov.getFormats());
192

  
193
				// time positions
194
				lyr.setTimePositions(cov.getTimePositions());
195

  
196
				// max res
197
				lyr.setMaxRes(new Point2D.Double(cov.getResX(), cov.getResY()));
198

  
199
				// interpolations
200
				lyr.setInterpolationMethods(cov.getInterpolationMethods());
201

  
202
				// parameters
203
				k = cov.axisPool.keySet();
204
				if (!k.isEmpty()) {
205
					it = k.iterator();
206
					while (it.hasNext()) {
207
						AxisDescription ad = (AxisDescription) cov.axisPool.get(it.next());
208
						FMapWCSParameter p = new DefaultFMapWCSParameter();
209
						p.setName(ad.getName());
210
						p.setLabel(ad.getLabel());
211
						p.setType(ad.getInterval() == null ? FMapWCSParameter.VALUE_LIST : FMapWCSParameter.INTERVAL);
212
						if (p.getType() == FMapWCSParameter.VALUE_LIST) {
213
							p.setValueList(ad.getSingleValues());
214
						} else {
215
							p.setInterval(ad.getInterval());
216
						}
217
						lyr.addParameter(p);
218
					}
219
				}
220
				layerList[j] = lyr;
221
				coverages.put(lyr.getName(), lyr);
222
			}
223
		}
224
		return layerList;
225
	}
226

  
227
	/**
228
	 * Establishes the connection to the WCS server. Connecting to a WCS is
229
	 * an abstraction.<br>
230
	 * <p>
231
	 * Actually, it sends a GetCapabilities and a general DescribeCoverage
232
	 * request (not a coverage-specific DescribeCoverage request) to read the
233
	 * necessary data for building further GetCoverage requests.
234
	 * </p>
235
	 * @param override
236
	 * @throws IOException.
237
	 */
238
	public boolean connect(boolean override, ICancellable cancel)
239
			throws IOException {
240
		coverages = null;
241
		setHost(client.getHost());
242
		return client.connect(override, cancel);
243
	}
244

  
245
	/**
246
	 * No close operation is needed since WCS service it is a non-session based
247
	 * protocol. So, this does nothing and you can omit it.<br>
248
	 */
249
	public void close() {
250
//		connected = false;
251
	}
252

  
253
	/**
254
	 * Returns the label of an specific coverage given by the coverage name
255
	 * @param coverage name (string)
256
	 * @return string
257
	 */
258
	public String getLabel(String coverageName) {
259
		return client.getLabel(coverageName);
260
	}
261

  
262
	/**
263
	 * Returns the coverage's MAX extent from the server.
264
	 * @return Rectangle2D
265
	 * @throws IOException
266
	 */
267
	public Rectangle2D getFullExtent(String coverageName, String srs)
268
			throws IOException {
269
		return client.getExtent(coverageName, srs);
270
	}
271

  
272
	/**
273
	 * Returns the max resolution of a specific coverage given by the coverage's name.
274
	 * @param coverage name (string)
275
	 * @return double
276
	 */
277
	public Point2D getMaxResolution(String coverageName) {
278
		if (coverages.containsKey(coverageName)) {
279
			return ((WCSLayerNode) coverages.get(coverageName)).getMaxRes();
280
		}
281
		return null;
282
	}
283

  
284

  
285
	/**
286
	 * Returns an ArrayList containing a set of Strings with the coverage's SRSs.
287
	 * @param coverage name (string)
288
	 * @return ArrayList
289
	 */
290
	public ArrayList getSRSs(String coverageName) {
291
		if (coverages.containsKey(coverageName)) {
292
			return ((WCSLayerNode) coverages.get(coverageName)).getSRSs();
293
		}
294
		return null;
295
	}
296

  
297
	/**
298
	 * Returns a String containing a description of an specific coverage.
299
	 * @param coverage name (string)
300
	 * @return string
301
	 */
302
	public String getCoverageDescription(String coverageName) {
303
		if (coverages.containsKey(coverageName)) {
304
			return ((WCSLayerNode) coverages.get(coverageName)).getDescription();
305
		}
306
		return null;
307
	}
308

  
309
	/**
310
	 * Returns an ArrayList containing strings for the time positions of an
311
	 * specific coverage given by the coverage's name.
312
	 * @param coverage name (string)
313
	 * @return ArrayList
314
	 */
315
	public ArrayList getTimes(String coverageName) {
316
		if (coverages.containsKey(coverageName)) {
317
			return ((WCSLayerNode) coverages.get(coverageName)).getTimePositions();
318
		}
319
		return null;
320
	}
321

  
322
	/**
323
	 * Sends a GetCoverage request to the client.
324
	 * @param status
325
	 * @return
326
	 * @throws WCSException
327
	 */
328
	public File getCoverage(WCSStatus status, ICancellable cancel) throws RemoteServiceException {
329
		try {
330
			return client.getCoverage(status, cancel);
331
		} catch (ServerErrorException e) {
332
			throw new RemoteServiceException(getName(), e);
333
		} catch (org.gvsig.remoteclient.exceptions.WCSException e) {
334
			throw new RemoteServiceException(getName(), e);
335
		}
336
	}
337
   
338
}
0 339

  
org.gvsig.raster.wcs/trunk/org.gvsig.raster.wcs/org.gvsig.raster.wcs.io/src/main/java/org/gvsig/raster/wcs/io/WCSProvider.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.wcs.io;
23

  
24
import java.awt.geom.AffineTransform;
25
import java.awt.geom.NoninvertibleTransformException;
26
import java.awt.geom.Point2D;
27
import java.awt.geom.Rectangle2D;
28
import java.io.File;
29
import java.io.IOException;
30
import java.net.URL;
31
import java.util.Hashtable;
32

  
33
import org.gvsig.compat.net.ICancellable;
34
import org.gvsig.fmap.dal.DALLocator;
35
import org.gvsig.fmap.dal.DataStore;
36
import org.gvsig.fmap.dal.DataStoreParameters;
37
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
38
import org.gvsig.fmap.dal.coverage.dataset.io.gdal.GdalProvider;
39
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
40
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
41
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
42
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException;
43
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
44
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
45
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
46
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
47
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
48
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
49
import org.gvsig.fmap.dal.coverage.explorer.WCSServerExplorer;
50
import org.gvsig.fmap.dal.coverage.store.parameter.WCSDataParameters;
51
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
52
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
53
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
54
import org.gvsig.metadata.MetadataLocator;
55
import org.gvsig.raster.cache.tile.TileCacheLocator;
56
import org.gvsig.raster.cache.tile.TileCacheManager;
57
import org.gvsig.raster.cache.tile.exception.TileGettingException;
58
import org.gvsig.raster.cache.tile.provider.TileListener;
59
import org.gvsig.raster.cache.tile.provider.TileServer;
60
import org.gvsig.raster.impl.DefaultRasterManager;
61
import org.gvsig.raster.impl.datastruct.BandListImpl;
62
import org.gvsig.raster.impl.datastruct.DatasetBandImpl;
63
import org.gvsig.raster.impl.datastruct.ExtentImpl;
64
import org.gvsig.raster.impl.provider.DefaultRasterProvider;
65
import org.gvsig.raster.impl.provider.RasterProvider;
66
import org.gvsig.raster.impl.provider.RemoteRasterProvider;
67
import org.gvsig.raster.impl.store.AbstractRasterDataStore;
68
import org.gvsig.raster.impl.store.DefaultStoreFactory;
69
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
70
import org.gvsig.raster.impl.store.properties.DataStoreTransparency;
71
import org.gvsig.raster.impl.store.properties.RemoteDataStoreStatistics;
72
import org.gvsig.remoteclient.wcs.WCSStatus;
73
import org.gvsig.tools.ToolsLocator;
74
import org.gvsig.tools.extensionpoint.ExtensionPoint;
75
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
76
/**
77
 * Clase que representa al driver de acceso a datos de wcs.
78
 *
79
 * @author Nacho Brodin (nachobrodin@gmail.com)
80
 */
81
public class WCSProvider extends DefaultRasterProvider implements RemoteRasterProvider {
82
	public static String                NAME                     = "Wcs Store";
83
	public static String                DESCRIPTION              = "Wcs Raster file";
84
	public static final String          METADATA_DEFINITION_NAME = "WcsStore";
85
	
86
	private Extent                      viewRequest              = null;
87
	private static Hashtable<URL, WCSConnector>    
88
	                                    drivers                  = new Hashtable<URL, WCSConnector> ();
89
	private boolean                     open                     = false;
90
	private DataStoreTransparency       fileTransparency         = null;
91
	private File                        lastRequest              = null;
92
	
93
	public static void register() {
94
		ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
95
		ExtensionPoint point = extensionPoints.get("RasterReader");
96
		point.append("wcs", "", WCSProvider.class);
97
		
98
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
99
		if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
100
			dataman.registerStoreProvider(NAME,
101
					WCSProvider.class, WCSDataParametersImpl.class);
102
		}
103

  
104
		if (!dataman.getExplorerProviders().contains(WCSServerExplorerImpl.NAME)) {
105
			dataman.registerExplorerProvider(WCSServerExplorer.NAME, WCSServerExplorerImpl.class, DefaultWCSServerExplorerParameters.class);
106
		}
107
		dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
108
	}
109
	
110
	public WCSProvider() throws NotSupportedExtensionException {
111
		super();
112
	}
113
	
114
	/**
115
	 * Constructor. Abre el dataset.
116
	 * @param proj Proyecci?n
117
	 * @param fName Nombre del fichero
118
	 * @throws NotSupportedExtensionException
119
	 */
120
	public WCSProvider(String params) throws NotSupportedExtensionException {
121
		super(params);
122
		if(params instanceof String) {
123
			WCSDataParametersImpl p = new WCSDataParametersImpl();
124
			p.setHost((String)params);
125
			super.init(p, null, ToolsLocator.getDynObjectManager()
126
					.createDynObject(
127
							MetadataLocator.getMetadataManager().getDefinition(
128
									DataStore.METADATA_DEFINITION_NAME)));
129
			init(p, null);
130
		}
131
	}
132
	
133
	public WCSProvider(WCSDataParametersImpl params,
134
			AbstractRasterDataStore storeServices) throws NotSupportedExtensionException {
135
		super(params, storeServices, ToolsLocator.getDynObjectManager()
136
				.createDynObject(
137
						MetadataLocator.getMetadataManager().getDefinition(
138
								DataStore.METADATA_DEFINITION_NAME)));
139
		init(params, storeServices);
140
	}
141
	
142
	/**
143
	 * Gets the connector from the URL
144
	 * @return
145
	 * @throws RemoteServiceException
146
	 */
147
	private WCSConnector getConnector() throws RemoteServiceException {
148
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
149
		URL url = null;
150
		try {
151
			url = new URL(p.getHost());
152
		} catch (Exception e) {
153
			throw new RemoteServiceException("Malformed URL",e);
154
		}
155
		try {
156
			return WCSProvider.getConnectorFromURL(url);
157
		} catch (IOException e) {
158
			throw new RemoteServiceException("Error getting the connector",e);
159
		}
160
	}
161
	
162
	/**
163
	 * Crea las referencias al fichero y carga
164
	 * las estructuras con la informaci?n y los metadatos.
165
	 * @param proj Proyecci?n
166
	 * @param param Parametros de carga
167
	 * @throws NotSupportedExtensionException
168
	 */
169
	public void init (DataStoreParameters params,
170
			DataStoreProviderServices storeServices) throws NotSupportedExtensionException {
171
		setParam(params);
172
		
173
		try {
174
			getDataTypeFromServer();
175
		} catch (RasterDriverException e) {
176
			e.printStackTrace();
177
		}
178
		
179
		//Temporal hastq que sepamos el tipo de dato y n?mero de bandas
180
		mustTileRequest = false;
181
		
182
		stats = new RemoteDataStoreStatistics(this);
183
	}
184
	
185
	public static final WCSConnector getConnectorFromURL(URL url) throws IOException {
186
		WCSConnector drv = (WCSConnector) drivers.get(url);
187
		if (drv == null) {
188
			drv = new WCSConnector(url);
189
			drivers.put(url, drv);
190
		}
191
		return drv;
192
	}
193
	
194
	/**
195
	 * Obtiene el objeto que contiene que contiene la interpretaci?n de
196
	 * color por banda
197
	 * @return
198
	 */
199
	public DataStoreColorInterpretation getColorInterpretation() {
200
		if(colorInterpretation == null) {
201
			colorInterpretation = new DataStoreColorInterpretation();
202
			colorInterpretation.initColorInterpretation(getBandCount());
203
			if(getBandCount() == 3) {
204
				colorInterpretation.setColorInterpValue(0, DataStoreColorInterpretation.RED_BAND);
205
				colorInterpretation.setColorInterpValue(1, DataStoreColorInterpretation.GREEN_BAND);
206
				colorInterpretation.setColorInterpValue(2, DataStoreColorInterpretation.BLUE_BAND);
207
			} else {
208
				for (int i = 0; i < getBandCount(); i++) {
209
					colorInterpretation.setColorInterpValue(i, DataStoreColorInterpretation.GRAY_BAND);
210
				}
211
			}
212
		}
213
		return colorInterpretation;
214
	}
215
	
216
	/*
217
	 * (non-Javadoc)
218
	 * @see org.gvsig.fmap.dal.coverage.dataset.RasterDataSet#getAffineTransform()
219
	 */
220
	public AffineTransform getAffineTransform() {
221
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
222
		Point2D resolution = null;
223
		try {
224
			resolution = getConnector().getMaxResolution(p.getCoverageName());
225
			Extent e = getExtent();
226
			ownTransformation = new AffineTransform(
227
					resolution.getX(), 
228
					0, 
229
					0, 
230
					-resolution.getY(), 
231
					e.getULX() - (resolution.getX() / 2),
232
					e.getULY() - (resolution.getY() / 2));
233
			externalTransformation = (AffineTransform) ownTransformation.clone();
234
			return ownTransformation;
235
		} catch (RemoteServiceException e1) {
236
			e1.printStackTrace();
237
		}
238
		return null;
239
	}
240
	
241
	/**
242
	 * Calcula el extent en coordenadas del mundo real
243
	 * @return Extent
244
	 */
245
	public Extent getExtent() {
246
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
247
		try {
248
			Rectangle2D r = getConnector().getFullExtent(p.getCoverageName(), p.getSRSCode());
249
			return new ExtentImpl(r.getX(),  r.getY() + r.getHeight(), r.getX() + r.getWidth(), r.getY());
250
		} catch (RemoteServiceException e1) {
251
			e1.printStackTrace();
252
		} catch (IOException e) {
253
			e.printStackTrace();
254
		}
255
		return null;
256
	}
257

  
258
	
259
	/*
260
	 * (non-Javadoc)
261
	 * @see org.gvsig.raster.impl.provider.RemoteRasterProvider#getLayerExtent(java.lang.String, java.lang.String)
262
	 */
263
	public Rectangle2D getLayerExtent(String layerName, String srs) throws RemoteServiceException {
264
		return null;
265
	}
266

  
267
	/*
268
	 * (non-Javadoc)
269
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#load()
270
	 */
271
	public RasterProvider load() {
272
		return this;
273
	}
274
	
275
	/*
276
	 * (non-Javadoc)
277
	 * @see org.gvsig.raster.impl.provider.RasterProvider#isOpen()
278
	 */
279
	public boolean isOpen() {
280
		return open;
281
	}
282

  
283
	/*
284
	 * (non-Javadoc)
285
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#close()
286
	 */
287
	public void close() {
288
		open = false;
289
	}
290
	
291
	/*
292
	 * (non-Javadoc)
293
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getTransparency()
294
	 */
295
	public Transparency getTransparency() {
296
		if(fileTransparency == null)
297
			fileTransparency = new DataStoreTransparency();
298
		return fileTransparency;
299
	}
300

  
301
	/*
302
	 * (non-Javadoc)
303
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#translateFileName(java.lang.String)
304
	 */
305
	public String translateFileName(String fileName) {
306
		return fileName;
307
	}
308

  
309
	/*
310
	 * (non-Javadoc)
311
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setView(org.gvsig.fmap.dal.coverage.datastruct.Extent)
312
	 */
313
	public void setView(Extent e) {
314
		viewRequest = e;
315
	}
316

  
317
	/*
318
	 * (non-Javadoc)
319
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getView()
320
	 */
321
	public Extent getView() {
322
		return viewRequest;
323
	}
324
	
325
	/*
326
	 * (non-Javadoc)
327
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWidth()
328
	 */
329
	public double getWidth() {
330
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
331
		Point2D resolution = null;
332
		try {
333
			resolution = getConnector().getMaxResolution(p.getCoverageName());
334
			Extent e = getExtent();
335
			return e.width() / resolution.getX(); 
336
		} catch (RemoteServiceException e1) {
337
			e1.printStackTrace();
338
		}
339
		return 0;
340
	}
341

  
342
	/*
343
	 * (non-Javadoc)
344
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getHeight()
345
	 */
346
	public double getHeight() {
347
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
348
		Point2D resolution = null;
349
		try {
350
			resolution = getConnector().getMaxResolution(p.getCoverageName());
351
			Extent e = getExtent();
352
			return e.height() / resolution.getY(); 
353
		} catch (RemoteServiceException e1) {
354
			e1.printStackTrace();
355
		}
356
		return 0;
357
	}
358

  
359
	/*
360
	 * (non-Javadoc)
361
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#readCompleteLine(int, int)
362
	 */
363
	public Object readCompleteLine(int line, int band)
364
		throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
365
		return null;
366
	}
367
	
368
	/**
369
	 * When the remote layer has fixed size this method downloads the file and return its reference. 
370
	 * File layer has in the long side FIXED_SIZE pixels and the bounding box is complete. This file could be
371
	 * useful to build an histogram or calculate statistics. This represents a sample of data.
372
	 * @return
373
	 * @throws RasterDriverException
374
	 */
375
	public File getFileLayer() throws RasterDriverException {
376
		Extent e = getExtent();
377
		Rectangle2D bBox = new Rectangle2D.Double(e.getULX(), e.getLRY(), e.width(), e.height());
378
		WCSStatus wcsStatus = loadWCSStatus(bBox);
379
		
380
		return downloadFile(wcsStatus, e.getULX(), e.getULY(), e.getLRX(), e.getLRY(), 
381
				(int)getWidth(), (int)getHeight());
382
	}
383

  
384
	/**
385
	 * Reads a complete block of data and returns an tridimensional array of the right type. This function is useful
386
	 * to read a file very fast without setting a view. In a WMS service when the size is fixed then it will read the
387
	 * entire image but when the source hasn't pixel size it will read a sample of data. This set of data will have
388
	 * the size defined in FIXED_SIZE. 
389
	 * 
390
	 * @param pos Posici?n donde se empieza  a leer
391
	 * @param blockHeight Altura m?xima del bloque leido
392
	 * @return Object que es un array tridimendional del tipo de datos del raster. (Bandas X Filas X Columnas)
393
	 * @throws InvalidSetViewException
394
	 * @throws FileNotOpenException
395
	 * @throws RasterDriverException
396
	 */
397
	public Object readBlock(int pos, int blockHeight) 
398
	throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
399
		File lastFile = getFileLayer();
400
		BandList bandList = new BandListImpl();
401
		for (int i = 0; i < 3; i++) {
402
			try {
403
				bandList.addBand(new DatasetBandImpl(lastFile.getPath(), pos, Buffer.TYPE_BYTE, 3), pos);
404
			} catch (BandNotFoundInListException e1) {
405
			}
406
		}
407
		bandList.setDrawableBands(new int[]{0, 1, 2});
408

  
409
		try {
410
			GdalProvider driver = new GdalProvider(lastFile.getPath());
411
			return driver.readBlock(pos, blockHeight);
412
		} catch (NotSupportedExtensionException exc) {
413
			throw new RasterDriverException("Error building GdalDriver", exc);
414
		}
415
	}
416

  
417
	/*
418
	 * (non-Javadoc)
419
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getData(int, int, int)
420
	 */
421
	public Object getData(int x, int y, int band)
422
		throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
423
		return null;
424
	}
425
	
426
	/**
427
	 * Gets the georeferencing file name form a raster file
428
	 * @param file
429
	 * a raster file
430
	 * @return
431
	 * a georeferencing file
432
	 */
433
	private String getWorldFile(String file){		
434
		String worldFile = file;
435
		int index = file.lastIndexOf(".");
436
		if (index > 0) {			
437
			worldFile = file.substring(0, index) + getExtensionWorldFile();
438
		} else {
439
			worldFile = file + getExtensionWorldFile();
440
		}
441
		return worldFile;
442
	}
443
	
444
	/**
445
	 * Obtiene la extensi?n del fichero de georreferenciaci?n
446
	 * @return String con la extensi?n del fichero de georreferenciaci?n dependiendo
447
	 * del valor del formato obtenido del servidor. Por defecto asignaremos un .wld
448
	 */
449
	private String getExtensionWorldFile() {
450
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
451
		String extWorldFile = ".wld";
452
		if(p.getFormat().equals("image/tif") || p.getFormat().equals("image/tiff")) {
453
			extWorldFile = ".tfw";
454
		}
455
		return extWorldFile;
456
	}
457
	
458
	private WCSStatus loadWCSStatus(Rectangle2D bBox) {
459
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
460
		WCSStatus wcsStatus = new WCSStatus();
461
		wcsStatus.setCoveraName(p.getCoverageName());
462
		wcsStatus.setSrs(p.getSRSCode());
463
		wcsStatus.setFormat(p.getFormat());
464
		wcsStatus.setOnlineResource(p.getOnlineResource() != null ? (String) p.getOnlineResource().get("GetCoverage") : null);
465
		wcsStatus.setExtent(bBox);
466
		wcsStatus.setHeight(p.getHeight());
467
		wcsStatus.setWidth(p.getWidth());
468
		wcsStatus.setDepth(p.getDepth());
469
		wcsStatus.setParameters(p.getParameter());
470
		wcsStatus.setTime(p.getTime());
471
		return wcsStatus;
472
	}
473
	
474
	/**
475
	 * This function downloads the file and creates the georeferencing file
476
	 * @param wcsStatus
477
	 * @param ulx
478
	 * @param uly
479
	 * @param lrx
480
	 * @param lry
481
	 * @param w
482
	 * @param h
483
	 * @return
484
	 * @throws RasterDriverException
485
	 */
486
	private File downloadFile(WCSStatus wcsStatus, double ulx, double uly, double lrx, double lry, int w, int h) throws RasterDriverException {
487
		try {
488
			lastRequest = getConnector().getCoverage(wcsStatus, ((WCSDataParametersImpl)parameters).getCancellable());
489
		} catch (RemoteServiceException e) {
490
			throw new RasterDriverException(e.getMessage(), e);
491
		}
492
		
493
		String nameWorldFile = getWorldFile(lastRequest.getPath());
494
		try {
495
			fileUtil.createWorldFile(nameWorldFile, new ExtentImpl(ulx, uly, lrx, lry), w, h);
496
		} catch (IOException e) {
497
			throw new RasterDriverException("Error downloading file", e);
498
		}
499

  
500
		return lastRequest;
501
	}
502
	
503
	/**
504
	 * Assigns the list of bands RGB and read a window of data
505
	 * @param rasterBuf
506
	 * @param bandList
507
	 * @param lastFile
508
	 * @param ulx
509
	 * @param uly
510
	 * @param lrx
511
	 * @param lry
512
	 * @return
513
	 * @throws RasterDriverException
514
	 * @throws ProcessInterruptedException
515
	 */
516
	public Buffer getBuffer(Buffer rasterBuf, BandList bandList, File lastFile, 
517
			double ulx, double uly, double lrx, double lry) throws RasterDriverException, ProcessInterruptedException {
518
		try {
519
			//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
520
			String serverName = bandList.getBand(0).getFileName();
521
			for (int i = 0; i < bandList.getBandCount(); i++) {
522
				bandList.getBand(i).setFileName(lastFile.getPath());
523
			}
524
			
525
			GdalProvider driver = new GdalProvider(lastFile.getPath());
526
			Buffer buf = driver.getWindow(new ExtentImpl(ulx, uly, lrx, lry), bandList, rasterBuf);
527
			
528
			for (int i = 0; i < bandList.getBandCount(); i++) {
529
				bandList.getBand(i).setFileName(serverName);
530
			}
531
			
532
			return buf;
533
		} catch (NotSupportedExtensionException e) {
534
			throw new RasterDriverException("Error building GdalDriver", e);
535
		}
536
	}
537
	
538
	/*
539
	 * (non-Javadoc)
540
	 * @see org.gvsig.raster.impl.provider.RasterProvider#isTiled()
541
	 */
542
	public boolean isTiled() {
543
		return mustTileRequest;
544
	}
545
	
546
	/*
547
	 * (non-Javadoc)
548
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.raster.cache.tile.provider.TileListener)
549
	 */
550
	public void getWindow(Extent ex, int bufWidth, int bufHeight, 
551
			BandList bandList, TileListener listener) throws ProcessInterruptedException, RasterDriverException {
552
		 if(mustTileRequest) {
553
			 
554
		 } else {
555
			 Buffer raster = DefaultRasterManager.getInstance().createBuffer(getDataType()[0], bufWidth, bufHeight, 3, true);
556
			 getWindow(ex, bufWidth, bufHeight, bandList, raster, true);
557
			 raster.setDataExtent(ex.toRectangle2D());
558
			 
559
			 TileCacheManager m = TileCacheLocator.getManager();
560
			 org.gvsig.raster.cache.tile.Tile t = m.createTile(-1, 0, 0);
561
			 t.setData(new Object[]{raster});
562
			 t.setUl(new Point2D.Double(ex.getULX(), ex.getULY()));
563
			 t.setLr(new Point2D.Double(ex.getLRX(), ex.getLRY()));
564
			 t.setDownloaderParams("AffineTransform", getAffineTransform());
565
			 t.setDownloaderParams("Tiling", new Boolean(false));
566
			 try {
567
				 listener.tileReady(t);
568
			 } catch (TileGettingException e) {
569
				 throw new RasterDriverException("Error throwing a tile", e);
570
			 }
571

  
572
			 //listener.nextBuffer(raster, null, new ExtentImpl(minX, minY, maxX, maxY), getAffineTransform(), null, false);
573
			 listener.endReading();
574
		 }
575
	}
576

  
577
	/*
578
	 * (non-Javadoc)
579
	 * @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)
580
	 */
581
	public Buffer getWindow(Extent ex, BandList bandList, Buffer rasterBuf) 
582
		throws ProcessInterruptedException, RasterDriverException {
583
		Rectangle2D bBox = ex.toRectangle2D();
584
		WCSStatus wmsStatus = loadWCSStatus(bBox);
585
		
586
		lastRequest = downloadFile(wmsStatus, ex.getULX(), ex.getULY(), ex.getLRX(), ex.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight());
587
		
588
		if (lastRequest == null) {
589
			return rasterBuf;
590
		}
591
		
592
		try {
593
			GdalProvider driver = new GdalProvider(lastRequest.getPath());
594
			/*bandCount = driver.getBandCount();
595
			setDataType(driver.getDataType());
596
			rasterBuf = changeBufferDataType(getDataType()[0], rasterBuf, bandList);*/
597
			
598
			//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
599
			String serverName = bandList.getBand(0).getFileName();
600
			for (int i = 0; i < bandList.getBandCount(); i++) {
601
				bandList.getBand(i).setFileName(lastRequest.getPath());
602
			}
603
			
604
			Buffer buf = driver.getWindow(ex, bandList, rasterBuf);
605
			
606
			for (int i = 0; i < bandList.getBandCount(); i++) {
607
				bandList.getBand(i).setFileName(serverName);
608
			}
609
			driver.close();
610
			return buf;
611
		} catch (NotSupportedExtensionException e) {
612
			throw new RasterDriverException("Error building GdalDriver", e);
613
		}
614
	}
615

  
616
	/*
617
	 * (non-Javadoc)
618
	 * @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)
619
	 */
620
	public Buffer getWindow(double ulx, double uly, double w, double h, 
621
			BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException {
622
		Rectangle2D bBox = new Rectangle2D.Double(ulx, uly, w, h);
623
		WCSStatus wcsStatus = loadWCSStatus(bBox);
624
		
625
		lastRequest = downloadFile(wcsStatus, ulx, uly, ulx + w, uly - h, rasterBuf.getWidth(), rasterBuf.getHeight());
626
		
627
		if (lastRequest == null) {
628
			return rasterBuf;
629
		}
630
		
631
		try {
632
			GdalProvider driver = new GdalProvider(lastRequest.getPath());
633
			/*bandCount = driver.getBandCount();
634
			setDataType(driver.getDataType());
635
			rasterBuf = changeBufferDataType(getDataType()[0], rasterBuf, bandList);*/
636
			
637
			//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
638
			String serverName = bandList.getBand(0).getFileName();
639
			for (int i = 0; i < bandList.getBandCount(); i++) {
640
				bandList.getBand(i).setFileName(lastRequest.getPath());
641
			}
642
			
643
			Buffer buf = driver.getWindow(ulx, uly, w, h, bandList, rasterBuf, adjustToExtent);
644
			
645
			for (int i = 0; i < bandList.getBandCount(); i++) {
646
				bandList.getBand(i).setFileName(serverName);
647
			}
648
			driver.close();
649
			return buf;
650
		} catch (NotSupportedExtensionException e) {
651
			throw new RasterDriverException("Error building GdalDriver", e);
652
		}
653
	}
654

  
655
	/*
656
	 * (non-Javadoc)
657
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(org.gvsig.fmap.dal.coverage.datastruct.Extent, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer, boolean)
658
	 */
659
	public Buffer getWindow(Extent extent, 
660
			int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf, boolean adjustToExtent) throws ProcessInterruptedException, RasterDriverException {
661
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
662
		Rectangle2D bBox = null;
663
		p.setWidth(bufWidth);
664
		p.setHeight(bufHeight);
665
		
666
		/*if(p.getExtent() != null) {
667
			bBox = p.getExtent();
668
			extent = new ExtentImpl(p.getExtent());
669
		} else {*/
670
			bBox = extent.toRectangle2D();
671
		//}
672
		
673
		//extent.toRectangle2D();//new Rectangle2D.Double(ulx, lry, Math.abs(lrx - ulx), Math.abs(lry - uly));
674
		WCSStatus wcsStatus = loadWCSStatus(bBox);
675
		lastRequest = downloadFile(wcsStatus, extent.getULX(), extent.getULY(), extent.getLRX(), extent.getLRY(), rasterBuf.getWidth(), rasterBuf.getHeight());
676
		
677
		if (lastRequest == null) {
678
			return rasterBuf;
679
		}
680
		
681
		try {
682
			GdalProvider driver = new GdalProvider(lastRequest.getPath());
683
			/*bandCount = driver.getBandCount();
684
			setDataType(driver.getDataType());
685
			rasterBuf = changeBufferDataType(getDataType()[0], rasterBuf, bandList);*/
686
			
687
			//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
688
			String serverName = bandList.getBand(0).getFileName();
689
			for (int i = 0; i < bandList.getBandCount(); i++) {
690
				bandList.getBand(i).setFileName(lastRequest.getPath());
691
			}
692
			
693
			Buffer buf = driver.getWindow(extent, bufWidth, bufHeight, bandList, rasterBuf, adjustToExtent);
694

  
695
			for (int i = 0; i < bandList.getBandCount(); i++) {
696
				bandList.getBand(i).setFileName(serverName);
697
			}
698
			driver.close();
699
			return buf;
700
		} catch (NotSupportedExtensionException e) {
701
			throw new RasterDriverException("Error building GdalDriver", e);
702
		}
703
	}
704

  
705
	/*
706
	 * (non-Javadoc)
707
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getWindowRaster(int, int, int, int, org.gvsig.fmap.dal.coverage.datastruct.BandList, org.gvsig.fmap.dal.coverage.dataset.Buffer)
708
	 */
709
	public Buffer getWindow(int x, int y, int w, int h, BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException {
710
		Point2D p1 = rasterToWorld(new Point2D.Double(x, y));
711
		Point2D p2 = rasterToWorld(new Point2D.Double(x + w, y + h));
712
		Rectangle2D bBox = new Rectangle2D.Double(p1.getX(), p1.getY(), Math.abs(p1.getX() - p1.getX()), Math.abs(p1.getY() - p2.getY()));
713
		WCSStatus wcsStatus = loadWCSStatus(bBox);
714
		
715
		lastRequest = downloadFile(wcsStatus, p1.getX(), p1.getY(), p2.getX(), p2.getY(), rasterBuf.getWidth(), rasterBuf.getHeight());
716
		
717
		if (lastRequest == null) {
718
			return rasterBuf;
719
		}
720

  
721
		GdalProvider driver = null;
722
		try {
723
			driver = new GdalProvider(lastRequest.getPath());
724
			/*bandCount = driver.getBandCount();
725
			setDataType(driver.getDataType());
726
			rasterBuf = changeBufferDataType(getDataType()[0], rasterBuf,bandList);*/
727
			
728
			//El nombre de fichero que ha puesto en el bandList es el del servidor y no el del fichero en disco
729
			String serverName = bandList.getBand(0).getFileName();
730
			for (int i = 0; i < bandList.getBandCount(); i++) {
731
				bandList.getBand(i).setFileName(lastRequest.getPath());
732
			}
733
			
734
			Buffer buf = driver.getWindow(0, 0, w, h, rasterBuf.getWidth(), rasterBuf.getHeight(), bandList, rasterBuf);
735

  
736
			for (int i = 0; i < bandList.getBandCount(); i++) {
737
				bandList.getBand(i).setFileName(serverName);
738
			}
739
			driver.close();
740
			return buf;
741
		} catch (NotSupportedExtensionException e) {
742
			throw new RasterDriverException("Error building GdalDriver", e);
743
		}
744
	}
745
	
746
	/**
747
	 * When a WCS provider is opened the information of data type and number of bands is not
748
	 * available. Only after the first time a raster has been downloaded it can be know.
749
	 * @param newDataType
750
	 * @param buf
751
	 * @param bandList
752
	 * @return
753
	 * @throws RasterDriverException 
754
	 */
755
	private void getDataTypeFromServer() throws RasterDriverException {
756
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
757
		Extent ext = getExtent();
758
		Rectangle2D bBox = ext.toRectangle2D();
759
		int w = 0;
760
		int h = 0;
761
		if(ext.width() > ext.height()) {
762
			w = 200;
763
			h = (int)((ext.height() * w) / ext.width());
764
		} else {
765
			h = 200;
766
			w = (int)((ext.width() * h) / ext.height());
767
		}
768
		p.setWidth(w);
769
		p.setHeight(h);
770
		p.setExtent(bBox);
771
		WCSStatus wcsStatus = loadWCSStatus(bBox);
772
		
773
		lastRequest = downloadFile(wcsStatus, ext.getULX(), ext.getULY(), ext.getLRX(), ext.getLRY(), w, h);
774
		GdalProvider driver;
775
		try {
776
			driver = new GdalProvider(lastRequest.getPath());
777
			setDataType(driver.getDataType());
778
			bandCount = driver.getBandCount();
779
			driver.close();
780
		} catch (NotSupportedExtensionException e) {
781
			throw new RasterDriverException("", e);
782
		}
783
	}
784
	
785
	/**
786
	 * When a WCS provider is opened the information of data type and number of bands is not
787
	 * available. Only after the first time a raster has been downloaded it can be know.
788
	 * @param newDataType
789
	 * @param buf
790
	 * @param bandList
791
	 * @return
792
	 */
793
	/*private Buffer changeBufferDataType(int newDataType, Buffer buf, BandList bandList) {
794
		Buffer newBuffer = null;
795
		if(buf.getDataType() != newDataType) {
796
			newBuffer = DefaultRasterManager.getInstance().createReadOnlyBuffer(newDataType, buf.getWidth(), buf.getHeight(), buf.getBandCount()); 
797
			buf.free();
798
		} else 
799
			return buf;
800
		
801
		bandList.clear();
802
		for(int i = 0; i < getBandCount(); i++)
803
			try {
804
				int dataType = getDataType()[i];
805
				DatasetBand band = new DatasetBandImpl(getFName(), i, dataType, getBandCount());
806
				bandList.addBand(band, i);
807
			} catch(BandNotFoundInListException ex) {
808
				//No a?adimos la banda
809
			}
810
		return newBuffer;
811
	}*/
812

  
813
	/*
814
	 * (non-Javadoc)
815
	 * @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)
816
	 */
817
	public Buffer getWindow(int x, int y, int w, int h, int bufWidth, int bufHeight, BandList bandList, Buffer rasterBuf) throws ProcessInterruptedException, RasterDriverException {
818
		return null;
819
	}
820

  
821
	/*
822
	 * (non-Javadoc)
823
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getBlockSize()
824
	 */
825
	public int getBlockSize() {
826
		return 0;
827
	}
828

  
829
	/*
830
	 * (non-Javadoc)
831
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#setAffineTransform(java.awt.geom.AffineTransform)
832
	 */
833
	public void setAffineTransform(AffineTransform t){
834
		
835
	}
836

  
837
	/*
838
	 * (non-Javadoc)
839
	 * @see org.gvsig.raster.impl.provider.RasterProvider#getOverviewCount(int)
840
	 */
841
	public int getOverviewCount(int band) throws BandAccessException, RasterDriverException {
842
		return 0;
843
	}
844

  
845
	/*
846
	 * (non-Javadoc)
847
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewWidth(int, int)
848
	 */
849
	public int getOverviewWidth(int band, int overview) throws BandAccessException, RasterDriverException {
850
		return 0;
851
	}
852

  
853
	/*
854
	 * (non-Javadoc)
855
	 * @see org.gvsig.raster.impl.provider.DefaultRasterProvider#getOverviewHeight(int, int)
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff