svn-gvsig-desktop / branches / v10 / extensions / extArcims / src / es / prodevelop / cit / gvsig / arcims / fmap / drivers / FMapRasterArcImsDriver.java @ 20976
History | View | Annotate | Download (7.34 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Prodevelop and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Prodevelop Integraci?n de Tecnolog?as SL
|
34 |
* Conde Salvatierra de ?lava , 34-10
|
35 |
* 46004 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963 510 612
|
39 |
* +34 963 510 968
|
40 |
* gis@prodevelop.es
|
41 |
* http://www.prodevelop.es
|
42 |
*/
|
43 |
package es.prodevelop.cit.gvsig.arcims.fmap.drivers; |
44 |
|
45 |
import es.prodevelop.cit.gvsig.arcims.fmap.layers.ArcImsLayerNode; |
46 |
|
47 |
import org.apache.log4j.Logger; |
48 |
|
49 |
import org.gvsig.remoteClient.arcims.*; |
50 |
import org.gvsig.remoteClient.arcims.exceptions.ArcImsException; |
51 |
import org.gvsig.remoteClient.exceptions.ServerErrorException; |
52 |
import org.gvsig.remoteClient.wms.ICancellable; |
53 |
|
54 |
import java.io.File; |
55 |
|
56 |
import java.net.URL; |
57 |
|
58 |
import java.util.TreeMap; |
59 |
|
60 |
|
61 |
/**
|
62 |
* ArcIMS driver implementation. Requests are passed to the <tt>ArcImsClientP</tt> object.
|
63 |
*
|
64 |
* @see org.gvsig.remoteClient.arcims.ArcImsImageClient ArcImsImageClient
|
65 |
* @author jldominguez
|
66 |
*/
|
67 |
public class FMapRasterArcImsDriver implements ArcImsDriver { |
68 |
private static Logger logger = Logger.getLogger(FMapRasterArcImsDriver.class.getName()); |
69 |
private ArcImsImageClient client;
|
70 |
private String server; |
71 |
private String service; |
72 |
private String serviceType; |
73 |
private boolean connectionDone = false; |
74 |
|
75 |
public FMapRasterArcImsDriver() {
|
76 |
} |
77 |
|
78 |
/**
|
79 |
* The constructor needs the server's URL and the name of the service to be used.
|
80 |
*
|
81 |
* @param host server's URL
|
82 |
* @param service name of the service, chosen among the ones retrieved after a
|
83 |
* request with the parameter <tt>ServiceName=Catalog</tt>
|
84 |
*/
|
85 |
public FMapRasterArcImsDriver(String host, String service, String svcType) { |
86 |
serviceType = svcType; |
87 |
init(host, service); |
88 |
} |
89 |
|
90 |
/**
|
91 |
* This method is called by the constructor and creates the
|
92 |
* <tt>client</tt> oject.
|
93 |
* @param host
|
94 |
* @param service
|
95 |
*/
|
96 |
public void init(String host, String service) { |
97 |
server = host; |
98 |
this.service = service;
|
99 |
client = new ArcImsImageClient(host, service, this.serviceType); |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Gets available layers from the current server and service
|
104 |
*
|
105 |
* @return a TreeMap with available layers
|
106 |
*/
|
107 |
public TreeMap getLayers() { |
108 |
return client.getLayers();
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* Gets the layers available on the server (the class that implements
|
113 |
* this interface will get the service name from the user)
|
114 |
*
|
115 |
* @param server ArcIMS server's URL
|
116 |
*/
|
117 |
public void getCapabilities(URL server, ICancellable cancel) |
118 |
throws ArcImsException {
|
119 |
if (connectionDone) {
|
120 |
return;
|
121 |
} |
122 |
else {
|
123 |
connectionDone = getClient().connect(server, cancel); |
124 |
} |
125 |
|
126 |
if (!connectionDone) {
|
127 |
throw new ArcImsException("connect_error"); |
128 |
} |
129 |
} |
130 |
|
131 |
/**
|
132 |
* Gets the visual information from the layers of
|
133 |
* the required service (that is, the map itself) depending
|
134 |
* on the graphic context (coord. system, view's size, etc)
|
135 |
*
|
136 |
* @param status the graphic context in which the request is performed
|
137 |
* @return the graphic data to be viewed, that is, the map. For the imageservice,
|
138 |
* it will be a <tt>File</tt> object.
|
139 |
*/
|
140 |
public Object getMap(ArcImsStatus status) throws ArcImsException { |
141 |
try {
|
142 |
return client.getMap(status);
|
143 |
} |
144 |
catch (ServerErrorException e) {
|
145 |
logger.error("While getting map ", e);
|
146 |
throw new ArcImsException("ArcIMS Unexpected server error." + |
147 |
e.getMessage()); |
148 |
} |
149 |
} |
150 |
|
151 |
/**
|
152 |
* Gets the layer's available information on a particular xy coordinates
|
153 |
* (usually derived from a mouse click). If it's a raster layer,
|
154 |
* a request will be sent to the server asking for the data associated
|
155 |
* to the elements (polygon, line or point) which cover the clicked
|
156 |
* pixel.
|
157 |
*
|
158 |
* @param status the graphic context in which the request is performed
|
159 |
* (ccord. system, view's dimension etc.)
|
160 |
* @param i x coordinate of the queried pixel
|
161 |
* @param j y coordinate of the queried pixel
|
162 |
* @param max_value maximun number of vector elements whose information
|
163 |
* will be retrieved.
|
164 |
* @return the available information at the given coordinates
|
165 |
*/
|
166 |
public String getFeatureInfo(ArcImsStatus status, int i, int j, |
167 |
int max_value) throws ArcImsException { |
168 |
String r = "No info available."; |
169 |
|
170 |
try {
|
171 |
r = client.getFeatureInfo(status, i, j, max_value); |
172 |
} |
173 |
catch (ArcImsException e) {
|
174 |
logger.error("ArcImsException. ", e);
|
175 |
throw e;
|
176 |
} |
177 |
|
178 |
return r;
|
179 |
} |
180 |
|
181 |
/**
|
182 |
* Given a layer name, gets a node that contains relevant information
|
183 |
* about the layer.
|
184 |
*
|
185 |
* @param layerName the name of the layer
|
186 |
* @return a node with layer's information
|
187 |
*/
|
188 |
public ArcImsLayerNode getLayer(String layerName) { |
189 |
ArcImsLayerNode node = new ArcImsLayerNode();
|
190 |
node.setName(layerName); |
191 |
|
192 |
return node;
|
193 |
} |
194 |
|
195 |
/**
|
196 |
* This method starts a connection with the server and sends
|
197 |
* a <tt>getCapabilities</tt> request.
|
198 |
* @return <b>true</b> if the connection was successful, <b>false</b>
|
199 |
* otherwise (bad or no server URL, for example)
|
200 |
*/
|
201 |
public boolean connect(ICancellable cancel) { |
202 |
if (connectionDone) {
|
203 |
return true; |
204 |
} |
205 |
else {
|
206 |
connectionDone = client.connect(false, cancel);
|
207 |
; |
208 |
|
209 |
return connectionDone;
|
210 |
} |
211 |
} |
212 |
|
213 |
/**
|
214 |
* Gets the <tt>ArcImsClientP</tt> object, onto which requests
|
215 |
* are passed.
|
216 |
*
|
217 |
* @return the object that actually performs requests.
|
218 |
*/
|
219 |
public ArcImsClientP getClient() {
|
220 |
if (client == null) { |
221 |
init(server, service); |
222 |
} |
223 |
|
224 |
return client;
|
225 |
} |
226 |
|
227 |
/**
|
228 |
* This method tells whether this layer is queriable with a call to
|
229 |
* <tt>getFeatureInfo(...)</tt>
|
230 |
*
|
231 |
* @return <b>true</b> if method <tt>getFeatureInfo(...)</tt> can be invoqued,
|
232 |
* <b>false</b> otherwise
|
233 |
*/
|
234 |
public boolean isQueryable() { |
235 |
return client.isQueryable();
|
236 |
} |
237 |
|
238 |
public boolean testFormat(ArcImsStatus status, String imgFormat) { |
239 |
try {
|
240 |
return client.testFromat(status, imgFormat);
|
241 |
} |
242 |
catch (ArcImsException e) {
|
243 |
logger.error("While testing omage format ", e);
|
244 |
} |
245 |
|
246 |
return false; |
247 |
} |
248 |
} |