Revision 5346

View differences:

org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.32/org.gvsig.raster.wcs.io/src/main/java/org/gvsig/raster/wcs/io/WCSLayerNode.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.util.ArrayList;
27
import java.util.Hashtable;
28

  
29
/**
30
 * Class defining the node of the layer tree of a common WCS service.
31
 * @author jaume
32
 */
33
@SuppressWarnings("unchecked")
34
public class WCSLayerNode {
35
	private String       name                  = null;
36
	private ArrayList    srs                   = null;
37
	private String       title                 = null;
38
	private String       nativeSRS             = null;
39
	private ArrayList    formats               = null;
40
	private Point2D      maxRes                = null;
41
	private int          width                 = 0;
42
	private int          height                = 0;
43
	private ArrayList    timePositions         = null;
44
	private String       description           = null;
45
	private ArrayList    interpolationMethods  = null;
46
	private ArrayList    pList                 = null;
47
	private Hashtable    extents               = null;
48
	private String       latLonBox             = null;
49
	private String       lAbstract             = null;
50
	private ArrayList    children              = new ArrayList();
51
	private boolean      transparency;
52

  
53
	public void setName(String name) {
54
		this.name = name;
55
	}
56

  
57
	public void addAllSrs(ArrayList srs) {
58
		if (this.srs == null)
59
			this.srs = new ArrayList();
60
		this.srs.addAll(srs);
61
	}
62

  
63
	public void setTitle(String title) {
64
		this.title = title;
65
	}
66

  
67
	public void setNativeSRS(String nativeSRS) {
68
		this.nativeSRS = nativeSRS;
69
	}
70

  
71
	public String getName() {
72
		return name;
73
	}
74

  
75
	public void setFormats(ArrayList formats) {
76
		this.formats = formats;
77
	}
78

  
79
	public ArrayList getFormats() {
80
		return formats;
81
	}
82

  
83
	public ArrayList getSRSs() {
84
		if (!srs.contains(nativeSRS)) {
85
			ArrayList l = new ArrayList(srs);
86
			l.add(nativeSRS);
87
			return l;
88
		}
89
		return srs;
90
	}
91

  
92
	public String getTitle() {
93
		return title;
94
	}
95

  
96
	public Rectangle2D getExtent(String srs) {
97
		if ( extents != null ) {
98
			return (Rectangle2D) extents.get(srs);
99
		}
100
		return null;
101
	}
102
	
103
	public void addExtent(String srs, Rectangle2D extent) {
104
		if ( extents == null ) extents = new Hashtable();
105
		extents.put(srs, extent);
106
	}
107

  
108
	public Point2D getMaxRes() {
109
		return maxRes;
110
	}
111
	
112

  
113
	public void setMaxRes(Point2D maxRes) {
114
		this.maxRes = maxRes;
115
	}
116
	
117
	public String toString(){
118
    	String str;
119
    	if (getName()==null)
120
    		str = getTitle();
121
    	else
122
    		str = "["+getName()+"] "+getTitle();
123
        return str;
124
    }
125

  
126
	public void setTimePositions(ArrayList timePositions) {
127
		this.timePositions = timePositions;
128
	}
129
    
130
	public ArrayList getTimePositions() {
131
		return this.timePositions;
132
	}
133

  
134
	public String getDescription() {
135
		return this.description;
136
	}
137
	
138
	public void setDescription(String descr) {
139
		this.description = descr;
140
	}
141

  
142
	public String getLonLatEnvelope() {
143
		return "yet unimplemented";
144
	}
145

  
146
	public void setInterpolationMethods(ArrayList interpolationMethods) {
147
		this.interpolationMethods = interpolationMethods;
148
	}
149
	
150
	public ArrayList getInterpolationMethods() {
151
		return interpolationMethods;
152
	}
153

  
154
	public ArrayList getParameterList() {
155
		return pList;
156
	}
157
	
158
	public void addParameter(FMapWCSParameter p) {
159
		if (pList == null) pList = new ArrayList();
160
		pList.add(p);
161
	}
162
	
163
	/**
164
     * Gets the layer abstract.
165
     * @return Returns the abstract.
166
     */
167
    public String getAbstract() {
168
        return lAbstract;
169
    }
170

  
171
    /**
172
     * Sets the layer abstract.
173
     * @param abstract The abstract to set.
174
     */
175
    public void setAbstract(String _abstract) {
176
        lAbstract = _abstract;
177
    }
178
    
179
    public void setLatLonBox(String _latLonBox) {
180
        latLonBox = _latLonBox;
181
    }
182

  
183
    public String getLatLonBox() {
184
        return latLonBox;
185
    }
186
    
187
    /**
188
     * Gets the list of sons of this layer.
189
     */
190
    public ArrayList getChildren() {
191
        return children;
192
    }
193
    
194
    /**
195
     * Sets the list of sons of this layer.
196
     * @param children
197
     */
198
    public void setChildren(ArrayList children) {
199
        this.children = children;
200
    }
201
    
202
    /**
203
     * @return Returns the transparency.
204
     */
205
    public boolean isTransparent() {
206
        return transparency;
207
    }
208

  
209
    /**
210
     * @param transparency The transparency to set.
211
     */
212
    public void setTransparency(boolean transparency) {
213
        this.transparency = transparency;
214
    }
215

  
216
	public int getWidth() {
217
		return width;
218
	}
219

  
220
	public void setWidth(int width) {
221
		this.width = width;
222
	}
223

  
224
	public int getHeight() {
225
		return height;
226
	}
227

  
228
	public void setHeight(int height) {
229
		this.height = height;
230
	}
231

  
232
}
0 233

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.32/org.gvsig.raster.wcs.io/src/main/java/org/gvsig/raster/wcs/io/FMapWCSParameter.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.util.ArrayList;
25

  
26
/**
27
 * Class abstracting WCS's axis descriptions into FMap
28
 * @author jaume dominguez faus - jaume.dominguez@iver.es
29
 * @TODO add interval parameters support
30
 */
31
@SuppressWarnings("unchecked")
32
public class FMapWCSParameter {
33
	public static final int VALUE_LIST = 0;
34
	public static final int INTERVAL = 1;
35
	private String name;
36
	private int type;
37
	private ArrayList valueList;
38
	private String label;
39

  
40
	public void setName(String name) {
41
		this.name = name;
42
	}
43

  
44
	public void setType(int type) {
45
		this.type = type;
46
	}
47

  
48
	public int getType() {
49
		return type;
50
	}
51

  
52
	public void setValueList(ArrayList singleValues) {
53
		this.valueList = singleValues;
54
	}
55

  
56
	public void setLabel(String label) {
57
		this.label = label;
58
	}
59

  
60
	public String toString() {
61
		return (label!=null) ? label : name;
62
	}
63

  
64
	public ArrayList getValueList() {
65
		return valueList;
66
	}
67

  
68
	public String getName() {
69
		return name;
70
	}
71
}
0 72

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.32/org.gvsig.raster.wcs.io/src/main/java/org/gvsig/raster/wcs/io/WCSServerExplorer.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.wcs.io;
29

  
30
import java.awt.geom.Point2D;
31
import java.io.IOException;
32
import java.io.InputStream;
33
import java.net.MalformedURLException;
34
import java.net.URI;
35
import java.net.URISyntaxException;
36
import java.net.URL;
37
import java.net.URLConnection;
38
import java.util.Hashtable;
39
import java.util.List;
40

  
41
import org.slf4j.Logger;
42
import org.slf4j.LoggerFactory;
43

  
44
import org.gvsig.compat.net.ICancellable;
45
import org.gvsig.fmap.dal.DALLocator;
46
import org.gvsig.fmap.dal.DataManager;
47
import org.gvsig.fmap.dal.DataServerExplorerParameters;
48
import org.gvsig.fmap.dal.DataStoreParameters;
49
import org.gvsig.fmap.dal.NewDataStoreParameters;
50
import org.gvsig.fmap.dal.coverage.exception.ConnectException;
51
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
52
import org.gvsig.fmap.dal.coverage.store.RasterDataServerExplorer;
53
import org.gvsig.fmap.dal.exception.DataException;
54
import org.gvsig.fmap.dal.exception.InitializeException;
55
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
56
import org.gvsig.fmap.dal.spi.DataServerExplorerProvider;
57
import org.gvsig.fmap.dal.spi.DataServerExplorerProviderServices;
58
import org.gvsig.i18n.Messages;
59

  
60
/**
61
 * Explorer for a WCS server
62
 * @author Nacho Brodin (nachobrodin@gmail.com)
63
 */
64
public class WCSServerExplorer implements RasterDataServerExplorer, DataServerExplorerProvider {
65
	private WCSConnector                connector                = null;
66
	private WCSServerExplorerParameters parameters               = null;
67
	private static final Logger         logger                    = LoggerFactory.getLogger(WCSServerExplorer.class);
68

  
69

  
70
	public WCSServerExplorer(
71
			WCSServerExplorerParameters parameters,
72
			DataServerExplorerProviderServices services)
73
			throws InitializeException {
74
		this.parameters = parameters;
75
	}
76

  
77
	/**
78
	 * Gets the provider's name
79
	 * @return
80
	 */
81
	public String getDataStoreProviderName() {
82
		return WCSProvider.NAME;
83
	}
84

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

  
89
	public boolean add(String provider, NewDataStoreParameters parameters,
90
			boolean overwrite) throws DataException {
91
		return false;
92
	}
93

  
94
	public boolean canAdd() {
95
		return false;
96
	}
97

  
98
	public boolean canAdd(String storeName) throws DataException {
99
		return false;
100
	}
101

  
102
	public NewDataStoreParameters getAddParameters(String storeName)
103
			throws DataException {
104
		return null;
105
	}
106

  
107
	public List getDataStoreProviderNames() {
108
		return null;
109
	}
110

  
111
	public DataServerExplorerParameters getParameters() {
112
		return parameters;
113
	}
114

  
115
	public List list() throws DataException {
116
		return null;
117
	}
118

  
119
	public List list(int mode) throws DataException {
120
		return null;
121
	}
122

  
123
	public void remove(DataStoreParameters parameters) throws DataException {
124

  
125
	}
126

  
127
	public void dispose() {
128

  
129
	}
130

  
131
	public String getProviderName() {
132
		return null;
133
	}
134

  
135
	/**
136
	 * Gets the online resources
137
	 * @return
138
	 */
139
	public Hashtable getOnlineResources() {
140
		return null;
141
	}
142

  
143
	//**********************************************
144
	//Connector
145
	//**********************************************
146

  
147
	public DataStoreParameters getStoredParameters() {
148
		DataManager manager = DALLocator.getDataManager();
149
		WCSDataParametersImpl params = null;
150
		try {
151
			params = (WCSDataParametersImpl) manager.createStoreParameters(this.getDataStoreProviderName());
152

  
153
		} catch (InitializeException e) {
154
            logger.warn("Can't get DataStoreParameters from WCSServerExplorer", e);
155
		} catch (ProviderNotRegisteredException e) {
156
            logger.warn("Can't get DataStoreParameters from WCSServerExplorer", e);
157
		}
158
		String host = parameters.getHost();
159
		URI hostURI;
160
        try {
161
            hostURI = new URI(host);
162
            params.setURI(hostURI);
163
        } catch (URISyntaxException e) {
164
            logger.warn("Can't create URI from"+host, e);
165
        }
166
		return params;
167
	}
168

  
169
	/**
170
	 * Connects to the server and throws a getCapabilities. This loads
171
	 * the basic information to make requests.
172
	 * @throws RemoteServiceException
173
	 */
174
	public void connect(ICancellable cancellable) throws ConnectException {
175
		URL url = null;
176
		boolean override = false;
177

  
178
		try {
179
			url = new URL(parameters.getHost());
180
		} catch (Exception e) {
181
			throw new ConnectException(Messages.getText("malformed_url"), e);
182
		}
183
        try {
184
        	connector = WCSProvider.getConnectorFromURL(url);
185
        	if (!connector.connect(override, cancellable))
186
        		throw new ConnectException(Messages.getText("error_connecting"));
187
        } catch (IOException e) {
188
			throw new ConnectException(Messages.getText("error_connecting"), e);
189
		}
190

  
191
	}
192

  
193
	/**
194
	 * Checks if the network and host are reachable
195
	 * @param timeout for the host
196
	 * @return true if both are reachable and false if they are not
197
	 */
198
	public boolean isHostReachable(int timeout) {
199
		URL url = null;
200
		try {
201
			url = new URL(parameters.getHost());
202
			URLConnection con = url.openConnection();
203
			if(con == null)
204
				return false;
205
			con.connect();
206
			InputStream stream = con.getInputStream();
207
			if(stream == null)
208
				return false;
209
		} catch (MalformedURLException e) {
210
			return false;
211
		} catch (IOException e) {
212
			return false;
213
		}
214

  
215
		return true;
216
	}
217

  
218
	/**
219
	 * Checks if the network and host are reachable
220
	 * @return true if both are reachable and false if they are not
221
	 */
222
	public boolean isHostReachable() {
223
		int timeout = 10000;
224
		return isHostReachable(timeout);
225
	}
226

  
227
	/**
228
	 * Returns true if this provider is connected to the server
229
	 * @return
230
	 */
231
	public boolean isConnected() {
232
		if(connector != null)
233
			return true;
234
		return false;
235
	}
236

  
237
	/**
238
	 * Gets the description of this service
239
	 * @return
240
	 */
241
	public String getAbstract() {
242
		if(connector != null)
243
			return connector.getDescription();
244
		return null;
245
	}
246

  
247
	/**
248
	 * Gets the server title
249
	 * @return
250
	 */
251
	public String getServerType() {
252
		if (getVersion() == null)
253
			return "WCS";
254
        return "WCS "+ getVersion();
255
	}
256

  
257
	/**
258
	 * Gets the protocol supported by the server
259
	 * @return
260
	 */
261
	public String getVersion() {
262
		if(connector != null) {
263
			return (connector.getVersion() == null) ? "" : connector.getVersion();
264
		}
265
		return null;
266
	}
267

  
268
	/**
269
	 * Gets the host URI
270
	 * @return
271
	 */
272
	public String getHost() {
273
		return parameters.getHost();
274
	}
275

  
276
	/**
277
	 * Gets the title
278
	 * @return
279
	 */
280
	public String getTitle() {
281
		return null;
282
	}
283

  
284
	public DataServerExplorerProviderServices getServerExplorerProviderServices() {
285
		return null;
286
	}
287

  
288
	public Point2D getMaxResolution(String layerName) {
289
		return connector.getMaxResolution(layerName);
290
	}
291

  
292
	/**
293
	 * Gets the coverage list
294
	 * @return
295
	 */
296
	public WCSLayerNode[] getCoverageList() {
297
		return connector.getLayerList();
298
	}
299

  
300
	/**
301
	 * Gets a layer searching by its name
302
	 * @return
303
	 */
304
	public WCSLayerNode getCoverageByName(String name) {
305
		WCSLayerNode[] list = getCoverageList();
306
		for (int i = 0; i < list.length; i++) {
307
			if(list[i].getName().compareTo(name) == 0)
308
				return list[i];
309
		}
310
		return null;
311
	}
312
}
0 313

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.32/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.BufferedOutputStream;
27
import java.io.DataInputStream;
28
import java.io.DataOutputStream;
29
import java.io.File;
30
import java.io.FileOutputStream;
31
import java.io.IOException;
32
import java.io.OutputStreamWriter;
33
import java.net.ConnectException;
34
import java.net.HttpURLConnection;
35
import java.net.URL;
36
import java.security.KeyManagementException;
37
import java.security.NoSuchAlgorithmException;
38
import java.util.ArrayList;
39
import java.util.Hashtable;
40
import java.util.Iterator;
41
import java.util.Set;
42
import java.util.prefs.Preferences;
43

  
44
import javax.net.ssl.HttpsURLConnection;
45
import javax.net.ssl.SSLContext;
46
import javax.net.ssl.TrustManager;
47
import javax.net.ssl.X509TrustManager;
48

  
49
import org.gvsig.compat.net.ICancellable;
50
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
51
import org.gvsig.remoteclient.exceptions.ServerErrorException;
52
import org.gvsig.remoteclient.exceptions.WCSException;
53
import org.gvsig.remoteclient.utils.BoundaryBox;
54
import org.gvsig.remoteclient.wcs.WCSClient;
55
import org.gvsig.remoteclient.wcs.WCSCoverage;
56
import org.gvsig.remoteclient.wcs.WCSStatus;
57
import org.gvsig.remoteclient.wcs.WCSCoverage.AxisDescription;
58
import org.gvsig.remoteclient.wcs.WCSCoverage.RectifiedGrid;
59

  
60
/**
61
 * Connector between a WCS data provider and a WCSClient. 
62
 *
63
 * @author Nacho Brodin (nachobrodin@gmail.com)
64
 */
65
public class WCSConnector  {
66
	private WCSClient                         client;
67
	private Hashtable<String, WCSLayerNode>   coverages;
68
    private WCSLayerNode[]                    layerList;
69
    
70
    public WCSConnector(URL url) throws ConnectException, IOException {
71
    	client = new WCSClient(url.toString());
72
    }
73

  
74
	/**
75
	 * Returns the string "WCSDriver", which is the driver's name.
76
	 * @return String
77
	 */
78
	public String getName() { 
79
		return "WCSDriver"; 
80
	}
81

  
82
	/**
83
	 * Sets the server that we want to connect to.
84
	 *
85
	 * @param host
86
	 * @throws IOException
87
	 */
88
	public void setHost(String host) throws IOException{
89
		client = new WCSClient(host);
90
	}
91

  
92

  
93
	/**
94
	 * Returns a human-readable string containing the server's name.
95
	 *
96
	 * @return String
97
	 */
98
	public String getLabel() {
99
		return client.getServiceTitle();
100
	}
101

  
102
	/**
103
	 * Returns a string containing the server's WCS version number.
104
	 *
105
	 * @return String
106
	 */
107
	public String getVersion(){
108
		return client.getVersion();
109
	}
110

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

  
125
	/**
126
	 * Returns the layer descriptor for a given coverage name.
127
	 * @param layerName
128
	 * @return WCSLayer
129
	 */
130
	public WCSLayerNode getLayer(String layerName) {
131
		getLayerList();
132
		return (WCSLayerNode) getCoverages().get(layerName);
133
	}
134
	
135
	private Hashtable<String, WCSLayerNode> getCoverages() {
136
		if(coverages == null || coverages.isEmpty()) {
137
			getLayerList();
138
		}
139
		return coverages;
140
	}
141

  
142
	/**
143
	 * Returns an array of WCSLayer's with the descriptors of all coverages
144
	 * @return WCSLayer[]
145
	 */
146
	public WCSLayerNode[] getLayerList() {
147
		if (coverages == null || coverages.isEmpty()) {
148
			// the WCSLayer collection will be built
149
			coverages = new Hashtable<String, WCSLayerNode>();
150
			Hashtable wcsCoverages  = client.getCoverageList();
151
			int sz = wcsCoverages.size();
152

  
153
			// Create an array with the WCSCoverages
154
			WCSCoverage[] coverageList = new WCSCoverage[sz];
155
			Iterator it = wcsCoverages.keySet().iterator();
156
			int i = 0;
157
			while (it.hasNext()) {
158
				coverageList[i] = (WCSCoverage) wcsCoverages.get(it.next());
159
				i++;
160
			}
161

  
162
			// Create a WCSLayer array from the previous WCSCoverage array
163
			layerList = new WCSLayerNode[sz];
164
			for (int j = 0; j < layerList.length; j++) {
165
				WCSLayerNode lyr = new WCSLayerNode();
166
				WCSCoverage cov = coverageList[j];
167
				// name
168
				lyr.setName(cov.getName());
169

  
170
				// title
171
				lyr.setTitle(cov.getTitle());
172

  
173
				// description
174
				lyr.setDescription(cov.getAbstract());
175

  
176
				// srs
177
				lyr.addAllSrs(cov.getAllSrs());
178

  
179
				// native srs
180
				lyr.setNativeSRS(cov.getNativeSRS());
181

  
182
				// extents
183
				Set k = cov.getBBoxes().keySet();
184
				if (!k.isEmpty()) {
185
					it = k.iterator();
186
					while (it.hasNext()) {
187
						String srs = (String) it.next();
188
						BoundaryBox bBox = cov.getBbox(srs);
189
						Rectangle2D r = new Rectangle2D.Double(
190
								bBox.getXmin(),
191
								bBox.getYmin(),
192
								bBox.getXmax() - bBox.getXmin(),
193
								bBox.getYmax() - bBox.getYmin()
194
						);
195
						lyr.addExtent(srs, r);
196
					}
197
				}
198

  
199
				// formats
200
				lyr.setFormats(cov.getFormats());
201

  
202
				// time positions
203
				lyr.setTimePositions(cov.getTimePositions());
204
				
205
				RectifiedGrid rf = cov.getRectifiedGrid();
206
				if(rf != null){
207
					int w = rf.getHighGridEnvelopLimits()[0][0] - rf.getLowGridEnvelopLimits()[0][0];
208
					int h = rf.getHighGridEnvelopLimits()[0][1] - rf.getLowGridEnvelopLimits()[0][1];
209
					
210
					lyr.setWidth(w);
211
					lyr.setHeight(h);
212
				}
213
				
214
				// max res
215
				lyr.setMaxRes(new Point2D.Double(cov.getResX(), cov.getResY()));
216

  
217
				// interpolations
218
				lyr.setInterpolationMethods(cov.getInterpolationMethods());
219

  
220
				// parameters
221
				k = cov.axisPool.keySet();
222
				if (!k.isEmpty()) {
223
					it = k.iterator();
224
					while (it.hasNext()) {
225
						AxisDescription ad = (AxisDescription) cov.axisPool.get(it.next());
226
						FMapWCSParameter p = new FMapWCSParameter();
227
						p.setName(ad.getName());
228
						p.setLabel(ad.getLabel());
229
						p.setType(ad.getInterval() == null ? FMapWCSParameter.VALUE_LIST : FMapWCSParameter.INTERVAL);
230
						if (p.getType() == FMapWCSParameter.VALUE_LIST) {
231
							p.setValueList(ad.getSingleValues());
232
						} /*else {
233
							p.setInterval(ad.getInterval());
234
						}*/
235
						lyr.addParameter(p);
236
					}
237
				}
238
				layerList[j] = lyr;
239
				coverages.put(lyr.getName(), lyr);
240
			}
241
		}
242
		return layerList;
243
	}
244

  
245
	/**
246
	 * Establishes the connection to the WCS server. Connecting to a WCS is
247
	 * an abstraction.<br>
248
	 * <p>
249
	 * Actually, it sends a GetCapabilities and a general DescribeCoverage
250
	 * request (not a coverage-specific DescribeCoverage request) to read the
251
	 * necessary data for building further GetCoverage requests.
252
	 * </p>
253
	 * @param override
254
	 * @throws IOException.
255
	 */
256
	public boolean connect(boolean override, ICancellable cancel)
257
			throws IOException {
258
		coverages = null;
259
		setHost(client.getHost());
260
		return client.connect(override, cancel);
261
	}
262

  
263
	/**
264
	 * No close operation is needed since WCS service it is a non-session based
265
	 * protocol. So, this does nothing and you can omit it.<br>
266
	 */
267
	public void close() {
268
//		connected = false;
269
	}
270

  
271
	/**
272
	 * Returns the label of an specific coverage given by the coverage name
273
	 * @param coverage name (string)
274
	 * @return string
275
	 */
276
	public String getLabel(String coverageName) {
277
		return client.getLabel(coverageName);
278
	}
279

  
280
	/**
281
	 * Returns the coverage's MAX extent from the server.
282
	 * @return Rectangle2D
283
	 * @throws IOException
284
	 */
285
	public Rectangle2D getFullExtent(String coverageName, String srs)
286
			throws IOException {
287
		return client.getExtent(coverageName, srs);
288
	}
289

  
290
	/**
291
	 * Returns the max resolution of a specific coverage given by the coverage's name.
292
	 * @param coverage name (string)
293
	 * @return double
294
	 */
295
	public Point2D getMaxResolution(String coverageName) {
296
		if (getCoverages().containsKey(coverageName)) {
297
			return ((WCSLayerNode) getCoverages().get(coverageName)).getMaxRes();
298
		}
299
		return null;
300
	}
301
	
302
	/**
303
	 * Gets the maximum width in pixels of this coverage
304
	 * @param coverageName
305
	 * @return
306
	 */
307
	public int getWidth(String coverageName) {
308
		if (getCoverages().containsKey(coverageName)) {
309
			return ((WCSLayerNode) getCoverages().get(coverageName)).getWidth();
310
		}
311
		return 0;
312
	}
313

  
314
	/**
315
	 * Gets the maximum height in pixels of this coverage
316
	 * @param coverageName
317
	 * @return
318
	 */
319
	public int getHeight(String coverageName) {
320
		if (getCoverages().containsKey(coverageName)) {
321
			return ((WCSLayerNode) getCoverages().get(coverageName)).getHeight();
322
		}
323
		return 0;
324
	}
325

  
326
	/**
327
	 * Returns an ArrayList containing a set of Strings with the coverage's SRSs.
328
	 * @param coverage name (string)
329
	 * @return ArrayList
330
	 */
331
	public ArrayList getSRSs(String coverageName) {
332
		if (getCoverages().containsKey(coverageName)) {
333
			return ((WCSLayerNode) getCoverages().get(coverageName)).getSRSs();
334
		}
335
		return null;
336
	}
337

  
338
	/**
339
	 * Returns a String containing a description of an specific coverage.
340
	 * @param coverage name (string)
341
	 * @return string
342
	 */
343
	public String getCoverageDescription(String coverageName) {
344
		if (getCoverages().containsKey(coverageName)) {
345
			return ((WCSLayerNode) getCoverages().get(coverageName)).getDescription();
346
		}
347
		return null;
348
	}
349

  
350
	/**
351
	 * Returns an ArrayList containing strings for the time positions of an
352
	 * specific coverage given by the coverage's name.
353
	 * @param coverage name (string)
354
	 * @return ArrayList
355
	 */
356
	public ArrayList getTimes(String coverageName) {
357
		if (getCoverages().containsKey(coverageName)) {
358
			return ((WCSLayerNode) getCoverages().get(coverageName)).getTimePositions();
359
		}
360
		return null;
361
	}
362

  
363
	/**
364
	 * Sends a GetCoverage request to the client.
365
	 * @param status
366
	 * @return
367
	 * @throws WCSException
368
	 */
369
	public File getCoverage(WCSStatus status, ICancellable cancel) throws RemoteServiceException {
370
		try {
371
			return client.getCoverage(status, cancel);
372
		} catch (ServerErrorException e) {
373
			throw new RemoteServiceException(getName(), e);
374
		} catch (org.gvsig.remoteclient.exceptions.WCSException e) {
375
			throw new RemoteServiceException(e.getMessage(), e);
376
		}
377
	}
378
	
379
	/**
380
	 * Sends a GetCoverage request to the client.
381
	 * @param status
382
	 * @return
383
	 * @throws WCSException
384
	 */
385
	public void getCoverageURL(WCSStatus status, ICancellable cancel, File file) throws RemoteServiceException {
386
		try {
387
			URL url = client.getCoverageURL(status, cancel);
388
			downloadFile(url, file, cancel);
389
			String exceptionMessage = client.getExceptionMessage(file);
390
			if(exceptionMessage != null)
391
				throw new RemoteServiceException(exceptionMessage);
392
		} catch(IOException e) {
393
			throw new RemoteServiceException("WCS: error downloading the file. File:" + file.getAbsolutePath() + "...." + e.getMessage(),e);
394
		} catch (ServerErrorException e) {
395
			throw new RemoteServiceException("WCS Unexpected server error."+e.getMessage(),e);
396
//		}  catch (org.gvsig.remoteclient.exceptions.WMSException e) {
397
//			throw new RemoteServiceException(e.getMessage());
398
		}
399
	}
400
	
401
	public void downloadFile(URL url, File dstFile, ICancellable cancel) throws IOException {
402
		Preferences prefs = Preferences.userRoot().node( "gvsig.downloader" );
403
		// by default 1 minute (60000 milliseconds.
404
		int timeout = prefs.getInt("timeout", 60000);
405

  
406
		DataOutputStream dos;
407
		DataInputStream is;
408
		OutputStreamWriter os = null;
409
		HttpURLConnection connection = null;
410
		//If the used protocol is HTTPS
411
		if (url.getProtocol().equals("https")) {
412
			try {
413
				disableHttsValidation();
414
			} catch (KeyManagementException e) {
415
				e.printStackTrace();
416
			} catch (NoSuchAlgorithmException e) {
417
				e.printStackTrace();
418
			}
419
		}
420
		connection = (HttpURLConnection)url.openConnection();
421
		connection.setConnectTimeout(timeout);
422
		is = new DataInputStream(url.openStream());
423

  
424
		dos = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(dstFile)));
425
		byte[] buffer = new byte[1024 * 4];
426

  
427

  
428
		long readed = 0;
429
		for (int i = is.read(buffer); i > 0; i = is.read(buffer)){
430
			dos.write(buffer, 0, i);
431
			readed += i;
432
			if(cancel != null && cancel.isCanceled())
433
				return;
434
		}
435
		if(os != null) {
436
			os.close();
437
		}
438
		dos.close();
439
		is.close();
440
		is = null;
441
		dos = null;
442
	}
443

  
444
	/**
445
	 * This method disables the Https certificate validation.
446
	 * @throws KeyManagementException
447
	 * @throws NoSuchAlgorithmException
448
	 */
449
	private void disableHttsValidation() throws KeyManagementException, NoSuchAlgorithmException{
450
		// Create a trust manager that does not validate certificate chains
451
		TrustManager[] trustAllCerts = new TrustManager[] {
452
				new X509TrustManager() {
453
					public java.security.cert.X509Certificate[] getAcceptedIssuers() {
454
						return null;
455
					}
456
					public void checkClientTrusted(
457
							java.security.cert.X509Certificate[] certs, String authType) {
458
					}
459
					public void checkServerTrusted(
460
							java.security.cert.X509Certificate[] certs, String authType) {
461
					}
462
				}
463
		};
464

  
465
		// Install the all-trusting trust manager
466
		SSLContext sc = SSLContext.getInstance("SSL");
467
		sc.init(null, trustAllCerts, new java.security.SecureRandom());
468
		HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
469
	}
470
   
471
}
0 472

  
org.gvsig.raster.wcs/tags/org.gvsig.raster.wcs-2.2.32/org.gvsig.raster.wcs.io/src/main/java/org/gvsig/raster/wcs/io/WCSProvider.java
1
package org.gvsig.raster.wcs.io;
2

  
3
import java.awt.Rectangle;
4
import java.awt.geom.AffineTransform;
5
import java.awt.geom.NoninvertibleTransformException;
6
import java.awt.geom.Point2D;
7
import java.awt.geom.Rectangle2D;
8
import java.io.File;
9
import java.io.IOException;
10
import java.net.URI;
11
import java.net.URISyntaxException;
12
import java.net.URL;
13
import java.util.ArrayList;
14
import java.util.Hashtable;
15

  
16
import org.apache.commons.io.FilenameUtils;
17
import org.apache.commons.lang3.StringUtils;
18
import org.slf4j.Logger;
19
import org.slf4j.LoggerFactory;
20

  
21
import org.gvsig.fmap.dal.DALLocator;
22
import org.gvsig.fmap.dal.DataStore;
23
import org.gvsig.fmap.dal.DataStoreParameters;
24
import org.gvsig.fmap.dal.coverage.RasterLocator;
25
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
26
import org.gvsig.fmap.dal.coverage.datastruct.BandList;
27
import org.gvsig.fmap.dal.coverage.datastruct.Extent;
28
import org.gvsig.fmap.dal.coverage.exception.BandAccessException;
29
import org.gvsig.fmap.dal.coverage.exception.BandNotFoundInListException;
30
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
31
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException;
32
import org.gvsig.fmap.dal.coverage.exception.InvalidSourceException;
33
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException;
34
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
35
import org.gvsig.fmap.dal.coverage.exception.QueryException;
36
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
37
import org.gvsig.fmap.dal.coverage.exception.RemoteServiceException;
38
import org.gvsig.fmap.dal.coverage.store.RasterQuery;
39
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation;
40
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
41
import org.gvsig.fmap.dal.coverage.store.props.Transparency;
42
import org.gvsig.fmap.dal.exception.InitializeException;
43
import org.gvsig.fmap.dal.exception.OpenException;
44
import org.gvsig.fmap.dal.exception.ProviderNotRegisteredException;
45
import org.gvsig.fmap.dal.spi.DataManagerProviderServices;
46
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
47
import org.gvsig.metadata.MetadataLocator;
48
import org.gvsig.raster.cache.tile.provider.TileServer;
49
import org.gvsig.raster.impl.buffer.SpiRasterQuery;
50
import org.gvsig.raster.impl.datastruct.BandListImpl;
51
import org.gvsig.raster.impl.datastruct.DatasetBandImpl;
52
import org.gvsig.raster.impl.datastruct.ExtentImpl;
53
import org.gvsig.raster.impl.provider.AbstractRasterProvider;
54
import org.gvsig.raster.impl.provider.RasterProvider;
55
import org.gvsig.raster.impl.provider.RemoteRasterProvider;
56
import org.gvsig.raster.impl.store.DefaultRasterStore;
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.raster.impl.store.properties.RemoteDataStoreStatistics;
61
import org.gvsig.raster.impl.store.properties.RemoteStoreHistogram;
62
import org.gvsig.raster.util.DefaultProviderServices;
63
import org.gvsig.raster.wcs.io.downloader.WCSTileServer;
64
import org.gvsig.remoteclient.wcs.WCSStatus;
65
import org.gvsig.tools.ToolsLocator;
66
/**
67
 * Clase que representa al driver de acceso a datos de wcs.
68
 *
69
 * @author Nacho Brodin (nachobrodin@gmail.com)
70
 */
71
public class WCSProvider extends AbstractRasterProvider implements RemoteRasterProvider {
72
	public static String                NAME                     = "Wcs Store";
73
	public static String                DESCRIPTION              = "Wcs Raster file";
74
	public static final String          METADATA_DEFINITION_NAME = "WcsStore";
75

  
76
	private Extent                      viewRequest              = null;
77
	private static Hashtable<URL, WCSConnector>
78
	drivers                  = new Hashtable<URL, WCSConnector> ();
79
	private boolean                     open                     = false;
80
	private DataStoreTransparency       fileTransparency         = null;
81
	private File                        lastRequest              = null;
82
	private AbstractRasterProvider      lastRequestProvider      = null;
83
	private static final Logger         logger                    = LoggerFactory.getLogger(WCSProvider.class);
84

  
85
	public static void register() {
86
		DataManagerProviderServices dataman = (DataManagerProviderServices) DALLocator.getDataManager();
87
		if (dataman != null && !dataman.getStoreProviders().contains(NAME)) {
88
			dataman.registerStoreProvider(NAME,
89
					WCSProvider.class, WCSDataParametersImpl.class);
90
		}
91

  
92
		if (!dataman.getExplorerProviders().contains(NAME)) {
93
			dataman.registerExplorerProvider(NAME, WCSServerExplorer.class, WCSServerExplorerParameters.class);
94
		}
95
		dataman.registerStoreFactory(NAME, DefaultStoreFactory.class);
96
	}
97

  
98
	public WCSProvider() throws NotSupportedExtensionException {
99
		super();
100
	}
101

  
102
	/**
103
	 * Constructor. Abre el dataset.
104
	 * @throws OpenException
105
	 * @throws NotSupportedExtensionException
106
     * @deprecated use {@link #WCSProvider(URI)}, this constructor will be removed in gvSIG 2.5
107
     */
108
	public WCSProvider(String params) throws InitializeException, OpenException {
109
		super(params);
110
        logger.info("Deprecated use of WCSProvider constructor");
111
		if(params instanceof String) {
112
			WCSDataParametersImpl p = new WCSDataParametersImpl();
113
            try {
114
                p.setURI(new URI((String) params));
115
            } catch (URISyntaxException e) {
116
                throw new OpenException("Can't create URI from" + (String) params, e);
117
            }
118
            super.init(p, null, ToolsLocator.getDynObjectManager()
119
					.createDynObject(
120
							MetadataLocator.getMetadataManager().getDefinition(
121
									DataStore.METADATA_DEFINITION_NAME)));
122
			init(p, null);
123
		}
124
	}
125

  
126
    public WCSProvider(URI uri) throws InitializeException, OpenException {
127
        super(uri);
128
        WCSDataParametersImpl p = new WCSDataParametersImpl();
129
            p.setURI(uri);
130
        super.init(
131
            p,
132
            null,
133
            ToolsLocator.getDynObjectManager().createDynObject(
134
                MetadataLocator.getMetadataManager().getDefinition(DataStore.METADATA_DEFINITION_NAME)));
135
        init(p, null);
136
    }
137

  
138
	public WCSProvider(WCSDataParametersImpl params,
139
			DataStoreProviderServices storeServices) throws InitializeException {
140
		super(params, storeServices, ToolsLocator.getDynObjectManager()
141
				.createDynObject(
142
						MetadataLocator.getMetadataManager().getDefinition(
143
								DataStore.METADATA_DEFINITION_NAME)));
144
		init(params, storeServices);
145
	}
146

  
147
	/**
148
	 * Gets the connector from the URL
149
	 * @return
150
	 * @throws RemoteServiceException
151
	 */
152
	public WCSConnector getConnector() throws RemoteServiceException {
153
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
154
		URL url = null;
155
		try {
156
			url = p.getURI().toURL();
157
		} catch (Exception e) {
158
			throw new RemoteServiceException("Malformed URL",e);
159
		}
160
		try {
161
			return WCSProvider.getConnectorFromURL(url);
162
		} catch (IOException e) {
163
			throw new RemoteServiceException("Error getting the connector",e);
164
		}
165
	}
166

  
167
	/**
168
	 * Crea las referencias al fichero y carga
169
	 * las estructuras con la informaci?n y los metadatos.
170
	 * @param proj Proyecci?n
171
	 * @param param Parametros de carga
172
	 * @throws NotSupportedExtensionException
173
	 * @throws RasterDriverException
174
	 */
175
	public void init (DataStoreParameters params,
176
			DataStoreProviderServices storeServices) throws InitializeException {
177
		setParam(storeServices, params);
178
		open = true;
179
		try {
180
			loadInitialInfo();
181
		} catch (RasterDriverException e) {
182
			throw new InitializeException(e.getMessage(), e);
183
		}
184

  
185
		stats = new RemoteDataStoreStatistics(this);
186
	}
187

  
188
	public static final WCSConnector getConnectorFromURL(URL url) throws IOException {
189
		WCSConnector drv = (WCSConnector) drivers.get(url);
190
		if (drv == null) {
191
			drv = new WCSConnector(url);
192
			drivers.put(url, drv);
193
		}
194
		return drv;
195
	}
196

  
197
	/**
198
	 * Obtiene el objeto que contiene que contiene la interpretaci?n de
199
	 * color por banda
200
	 * @return
201
	 */
202
	public ColorInterpretation getColorInterpretation() {
203
		if(super.getColorInterpretation() == null) {
204
			ColorInterpretation colorInterpretation = new DataStoreColorInterpretation();
205
			colorInterpretation.initColorInterpretation(getBandCount());
206
			if(getBandCount() == 3) {
207
				colorInterpretation = DataStoreColorInterpretation.createRGBInterpretation();
208
			} else {
209
				for (int i = 0; i < getBandCount(); i++) {
210
					colorInterpretation.setColorInterpValue(i, DataStoreColorInterpretation.GRAY_BAND);
211
				}
212
			}
213
			setColorInterpretation(colorInterpretation);
214
		}
215
		return super.getColorInterpretation();
216
	}
217

  
218
	/**
219
	 * Gets WCS parameters
220
	 * @return
221
	 */
222
	public WCSDataParameters getParameters() {
223
		return (WCSDataParameters)parameters;
224
	}
225

  
226
	public AffineTransform getAffineTransform() {
227
		Extent e = getExtent();
228
		double resolutionX = e.width() / getWidth();
229
		double resolutionY = e.height() / getHeight();
230

  
231

  
232
		ownTransformation = new AffineTransform(
233
				resolutionX,                        // ESCALADO en X
234
				0,                                  // CIZALLAMIENTO de la Y
235
				0,                                  // CIZALLAMIENTO de la X
236
				-resolutionY,                       // ESCALADO en Y
237
				e.getULX() - (resolutionX / 2),     // TRASLACION en X
238
				e.getULY() - (resolutionY / 2));    // TRASLACION en Y
239

  
240
		externalTransformation = (AffineTransform) ownTransformation.clone();
241
		return ownTransformation;
242
	}
243

  
244
	/**
245
	 * Calcula el extent en coordenadas del mundo real
246
	 * @return Extent
247
	 */
248
	public Extent getExtent() {
249
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
250
		try {
251
			p.setFormat("image/tiff");
252
			if(p.getSRSCode() == null){
253
				WCSConnector connector = WCSProvider.getConnectorFromURL(p.getURI().toURL());
254
				ArrayList srs = connector.getSRSs(p.getCoverageName());
255
				if(!srs.isEmpty() && !StringUtils.isBlank((String)srs.get(0))){
256
					p.setSRSID((String) srs.get(0));
257
				}else{
258
					return null;
259
				}
260
			}
261
			Rectangle2D r = getConnector().getFullExtent(p.getCoverageName(), p.getSRSCode());
262
			if(r == null)
263
				return null;
264
			return new ExtentImpl(r.getX(),  r.getY() + r.getHeight(), r.getX() + r.getWidth(), r.getY());
265
		} catch (RemoteServiceException e1) {
266
			e1.printStackTrace();
267
		} catch (IOException e) {
268
			e.printStackTrace();
269
		}
270
		return null;
271
	}
272

  
273
	public Rectangle2D getLayerExtent(String layerName, String srs) throws RemoteServiceException {
274
		return null;
275
	}
276

  
277
	public RasterProvider load() {
278
		return this;
279
	}
280

  
281
	public boolean isOpen() {
282
		return open;
283
	}
284

  
285
	public void close() {
286
		open = false;
287
	}
288

  
289
	public Transparency getTransparency() {
290
		if(fileTransparency == null)
291
			fileTransparency = new DataStoreTransparency(getColorInterpretation());
292
		return fileTransparency;
293
	}
294

  
295
	public URI translateURI(URI uri) {
296
		return uri;
297
	}
298

  
299
	public void setView(Extent e) {
300
		viewRequest = e;
301
	}
302

  
303
	public Extent getView() {
304
		return viewRequest;
305
	}
306

  
307
	public double getWidth() {
308
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
309
		try {
310
			return getConnector().getWidth(p.getCoverageName());
311
		} catch (RemoteServiceException e) {
312
			e.printStackTrace();
313
		}
314
		return 0;
315
	}
316

  
317
	public double getHeight() {
318
		WCSDataParametersImpl p = (WCSDataParametersImpl)parameters;
319
		try {
320
			return getConnector().getHeight(p.getCoverageName());
321
		} catch (RemoteServiceException e) {
322
			e.printStackTrace();
323
		}
324
		return 0;
325
	}
326

  
327
	public Object readCompleteLine(int line, int band)
328
			throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
329
		return null;
330
	}
331

  
332
	/**
333
	 * When the remote layer has fixed size this method downloads the file and return its reference.
334
	 * File layer has in the long side FIXED_SIZE pixels and the bounding box is complete. This file could be
335
	 * useful to build an histogram or calculate statistics. This represents a sample of data.
336
	 * @return
337
	 * @throws RasterDriverException
338
	 */
339
	public File getFileLayer() throws RasterDriverException {
340
		Extent e = getExtent();
341
		Rectangle2D bBox = new Rectangle2D.Double(e.getULX(), e.getLRY(), e.width(), e.height());
342
		WCSStatus wcsStatus = loadWCSStatus(bBox);
343

  
344
		return downloadFile(wcsStatus, e, (int)getWidth(), (int)getHeight());
345
	}
346

  
347
	/**
348
	 * Reads a complete block of data and returns an tridimensional array of the right type. This function is useful
349
	 * to read a file very fast without setting a view. In a WCS service when the size is fixed then it will read the
350
	 * entire image but when the source hasn't pixel size it will read a sample of data. This set of data will have
351
	 * the size defined in FIXED_SIZE.
352
	 *
353
	 * @param pos Posici?n donde se empieza  a leer
354
	 * @param blockHeight Altura m?xima del bloque leido
355
	 * @return Object que es un array tridimendional del tipo de datos del raster. (Bandas X Filas X Columnas)
356
	 * @throws InvalidSetViewException
357
	 * @throws FileNotOpenException
358
	 * @throws RasterDriverException
359
	 */
360
	public Object readBlock(int pos, int blockHeight, double scale)
361
			throws InvalidSetViewException, FileNotOpenException, RasterDriverException, ProcessInterruptedException {
362
		File lastFile = getFileLayer();
363
		BandList bandList = new BandListImpl();
364
		for (int i = 0; i < 3; i++) {
365
			try {
366
				bandList.addBand(new DatasetBandImpl(lastFile.getPath(), pos, Buffer.TYPE_BYTE, 3));
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff