root / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / fmap / layers / FLyrWFS.java @ 7721
History | View | Annotate | Download (11.7 KB)
1 |
package com.iver.cit.gvsig.fmap.layers; |
---|---|
2 |
|
3 |
import java.awt.geom.Rectangle2D; |
4 |
import java.io.IOException; |
5 |
import java.net.ConnectException; |
6 |
import java.net.MalformedURLException; |
7 |
import java.net.URL; |
8 |
import java.util.HashMap; |
9 |
import java.util.Map; |
10 |
import java.util.Vector; |
11 |
|
12 |
import javax.swing.ImageIcon; |
13 |
|
14 |
import org.cresques.cts.IProjection; |
15 |
import org.cresques.cts.ProjectionPool; |
16 |
import org.cresques.geo.Projection; |
17 |
import org.gvsig.remoteClient.wfs.WFSAttribute; |
18 |
import org.gvsig.remoteClient.wfs.WFSStatus; |
19 |
|
20 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
21 |
import com.iver.andami.PluginServices; |
22 |
import com.iver.cit.gvsig.fmap.DriverException; |
23 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
24 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
25 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
26 |
import com.iver.cit.gvsig.fmap.drivers.WFSException; |
27 |
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver; |
28 |
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriverFactory; |
29 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
30 |
|
31 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
32 |
*
|
33 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
34 |
*
|
35 |
* This program is free software; you can redistribute it and/or
|
36 |
* modify it under the terms of the GNU General Public License
|
37 |
* as published by the Free Software Foundation; either version 2
|
38 |
* of the License, or (at your option) any later version.
|
39 |
*
|
40 |
* This program is distributed in the hope that it will be useful,
|
41 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
42 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
43 |
* GNU General Public License for more details.
|
44 |
*
|
45 |
* You should have received a copy of the GNU General Public License
|
46 |
* along with this program; if not, write to the Free Software
|
47 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
48 |
*
|
49 |
* For more information, contact:
|
50 |
*
|
51 |
* Generalitat Valenciana
|
52 |
* Conselleria d'Infraestructures i Transport
|
53 |
* Av. Blasco Ib??ez, 50
|
54 |
* 46010 VALENCIA
|
55 |
* SPAIN
|
56 |
*
|
57 |
* +34 963862235
|
58 |
* gvsig@gva.es
|
59 |
* www.gvsig.gva.es
|
60 |
*
|
61 |
* or
|
62 |
*
|
63 |
* IVER T.I. S.A
|
64 |
* Salamanca 50
|
65 |
* 46005 Valencia
|
66 |
* Spain
|
67 |
*
|
68 |
* +34 963163400
|
69 |
* dac@iver.es
|
70 |
*/
|
71 |
/* CVS MESSAGES:
|
72 |
*
|
73 |
* $Id: FLyrWFS.java 7721 2006-10-02 09:09:45Z jorpiell $
|
74 |
* $Log$
|
75 |
* Revision 1.12 2006-10-02 09:09:45 jorpiell
|
76 |
* Cambios del 10 copiados al head
|
77 |
*
|
78 |
* Revision 1.10.2.3 2006/09/29 14:12:53 luisw2
|
79 |
* CRSFactory.getCRS substitutes ProjectionPool.get
|
80 |
*
|
81 |
* Revision 1.10.2.2 2006/09/28 08:54:01 jorpiell
|
82 |
* Ya se puede reproyectar
|
83 |
*
|
84 |
* Revision 1.10.2.1 2006/09/26 07:36:24 jorpiell
|
85 |
* El WFS no reproyectaba porque no se le asignaba a la capa un sistema de referencia. Ahora ya se hace.
|
86 |
*
|
87 |
* Revision 1.10 2006/09/05 15:41:52 jorpiell
|
88 |
* A?adida la funcionalidad de cargar WFS desde el cat?logo
|
89 |
*
|
90 |
* Revision 1.9 2006/07/05 12:05:41 jorpiell
|
91 |
* Se ha modificado para que avise si se han recuperado las mismas features que marca el campo buffer
|
92 |
*
|
93 |
* Revision 1.8 2006/06/21 12:52:10 jorpiell
|
94 |
* A?adido un icono para la capa WFS
|
95 |
*
|
96 |
* Revision 1.7 2006/06/21 12:35:45 jorpiell
|
97 |
* Se ha a?adido la ventana de propiedades. Esto implica a?adir listeners por todos los paneles. Adem?s no se muestra la geomatr?a en la lista de atributos y se muestran ?nicamnete los que se van a descargar
|
98 |
*
|
99 |
* Revision 1.6 2006/06/15 11:17:06 jorpiell
|
100 |
* Se ha encontrado la forma de comprobar cuando se prodicia un error de parseo al hacer un hasnext (en la feature). Se atrapa y se lanza la excepci?n hacia arriba
|
101 |
*
|
102 |
* Revision 1.5 2006/06/14 07:57:19 jorpiell
|
103 |
* Ya no se usa la estrategia ni se usa geotools para hacer el getFeature. Ahora se usa ?nicamente para el parseo de GML
|
104 |
*
|
105 |
* Revision 1.4 2006/06/05 16:49:31 caballero
|
106 |
* poder editar y exportar
|
107 |
*
|
108 |
* Revision 1.3 2006/05/25 10:31:55 jorpiell
|
109 |
* Se ha renombrado la clase WFSFields por WFSAttributes porque era algo confusa
|
110 |
*
|
111 |
* Revision 1.2 2006/05/23 13:21:59 jorpiell
|
112 |
* Si hay alg?n problema en la carga se muestra un mensaje de error
|
113 |
*
|
114 |
* Revision 1.1 2006/05/19 12:54:11 jorpiell
|
115 |
* Creada la capa WFS
|
116 |
*
|
117 |
*
|
118 |
*/
|
119 |
/**
|
120 |
* FMap's WFS Layer class.
|
121 |
*
|
122 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
123 |
*/
|
124 |
public class FLyrWFS extends FLyrVect{ |
125 |
private URL host = null; |
126 |
private String onlineResource = null; |
127 |
private String name = null; |
128 |
private String layerName = null; |
129 |
private String userName = null; |
130 |
private String password = null; |
131 |
private WFSAttribute[] fields = null; |
132 |
private int numfeatures = 100; |
133 |
private int timeout = 10000; |
134 |
private String srs = null; |
135 |
private FMapWFSDriver wfsDriver = null; |
136 |
private VectorialAdapter vectorialAdapter = null; |
137 |
private WFSLayerNode wfsLayerNode = null; |
138 |
|
139 |
/**
|
140 |
* Constructor
|
141 |
*/
|
142 |
public FLyrWFS(){
|
143 |
super();
|
144 |
} |
145 |
|
146 |
/**
|
147 |
* Constructor to load a new layer from a catalog
|
148 |
* search
|
149 |
* @param args
|
150 |
* Params to load a new layer
|
151 |
* @throws WFSException
|
152 |
* @throws IOException
|
153 |
* @throws MalformedURLException
|
154 |
* @throws ConnectException
|
155 |
* @throws DriverIOException
|
156 |
*/
|
157 |
public FLyrWFS(Map args) throws WFSException, ConnectException, MalformedURLException, IOException, DriverIOException{ |
158 |
String[] sLayer = (String[])args.get("layer"); |
159 |
String user = (String)args.get("user"); |
160 |
String pwd = (String)args.get("pwd"); |
161 |
String host = (String)args.get("host"); |
162 |
String projection = (String)args.get("projection"); |
163 |
|
164 |
FMapWFSDriver driver = FMapWFSDriverFactory.getFMapDriverForURL(new URL(host)); |
165 |
WFSLayerNode[] layers = driver.getLayerList();
|
166 |
WFSLayerNode layer = driver.getLayerInfo(sLayer[0]);
|
167 |
|
168 |
layer.setSelectedFields(layer.getFields()); |
169 |
|
170 |
WFSAttribute[] atts = new WFSAttribute[layer.getFields().size()]; |
171 |
for (int i=0 ; i<atts.length ; i++){ |
172 |
atts[i] = (WFSAttribute)layer.getFields().get(i); |
173 |
} |
174 |
|
175 |
setHost(host); |
176 |
setName(sLayer[0]);
|
177 |
setLayerName(sLayer[0]);
|
178 |
setWfsLayerNode(layer); |
179 |
setFields(atts); |
180 |
setUserName(user); |
181 |
setPassword(pwd); |
182 |
setNumfeatures(10000);
|
183 |
setTimeout(10000);
|
184 |
setWfsDriver(driver); |
185 |
setProjection(CRSFactory.getCRS(projection)); |
186 |
|
187 |
load(); |
188 |
} |
189 |
|
190 |
|
191 |
/**
|
192 |
* Loads the features from the server
|
193 |
*/
|
194 |
public void load() throws DriverIOException{ |
195 |
WFSAdapter adapter = new WFSAdapter();
|
196 |
try {
|
197 |
wfsDriver.getFeature(getWFSStatus()); |
198 |
|
199 |
adapter.setDriver((VectorialDriver) wfsDriver); |
200 |
setSource(adapter); |
201 |
|
202 |
|
203 |
setLegend(LegendFactory.createSingleSymbolLegend( |
204 |
getShapeType())); |
205 |
} catch (Exception e){ |
206 |
e.printStackTrace(); |
207 |
throw new DriverIOException(e.getMessage()); |
208 |
} |
209 |
} |
210 |
|
211 |
/**
|
212 |
* Gets the WFS Status
|
213 |
* @return
|
214 |
*/
|
215 |
private WFSStatus getWFSStatus(){
|
216 |
WFSStatus status = new WFSStatus(getLayerName());
|
217 |
status.setUserName(getUserName()); |
218 |
status.setPassword(getPassword()); |
219 |
status.setBuffer(getNumfeatures()); |
220 |
status.setTimeout(getTimeout()); |
221 |
status.setFields(getFieldNames()); |
222 |
status.setOnlineResource(getOnlineResource()); |
223 |
status.setSrs(getSrs()); |
224 |
return status;
|
225 |
} |
226 |
|
227 |
/**
|
228 |
* Adds the vectorial adapter to the layer
|
229 |
* @param vectorialAdapter
|
230 |
*/
|
231 |
public void setSource(VectorialAdapter vectorialAdapter) { |
232 |
this.vectorialAdapter = vectorialAdapter;
|
233 |
super.setSource(vectorialAdapter);
|
234 |
} |
235 |
|
236 |
/**
|
237 |
* @return Returns the layerName.
|
238 |
*/
|
239 |
public String getLayerName() { |
240 |
return layerName;
|
241 |
} |
242 |
/**
|
243 |
* @param layerName The layerName to set.
|
244 |
*/
|
245 |
public void setLayerName(String layerName) { |
246 |
this.layerName = layerName;
|
247 |
} |
248 |
/**
|
249 |
* @return Returns the numfeatures.
|
250 |
*/
|
251 |
public int getNumfeatures() { |
252 |
return numfeatures;
|
253 |
} |
254 |
/**
|
255 |
* @param numfeatures The numfeatures to set.
|
256 |
*/
|
257 |
public void setNumfeatures(int numfeatures) { |
258 |
this.numfeatures = numfeatures;
|
259 |
} |
260 |
|
261 |
/**
|
262 |
* @return Returns the pwd.
|
263 |
*/
|
264 |
public String getPassword() { |
265 |
return password;
|
266 |
} |
267 |
/**
|
268 |
* @param pwd The pwd to set.
|
269 |
*/
|
270 |
public void setPassword(String password) { |
271 |
this.password = password;
|
272 |
} |
273 |
/**
|
274 |
* @return Returns the timeout.
|
275 |
*/
|
276 |
public int getTimeout() { |
277 |
return timeout;
|
278 |
} |
279 |
/**
|
280 |
* @param timeout The timeout to set.
|
281 |
*/
|
282 |
public void setTimeout(int timeout) { |
283 |
this.timeout = timeout;
|
284 |
} |
285 |
/**
|
286 |
* @return Returns the user.
|
287 |
*/
|
288 |
public String getUserName() { |
289 |
return userName;
|
290 |
} |
291 |
/**
|
292 |
* @param user The user to set.
|
293 |
*/
|
294 |
public void setUserName(String userName) { |
295 |
this.userName = userName;
|
296 |
} |
297 |
/**
|
298 |
* @return Returns the fields.
|
299 |
*/
|
300 |
public WFSAttribute[] getFields() { |
301 |
return fields;
|
302 |
} |
303 |
|
304 |
/**
|
305 |
* Return the attributes name
|
306 |
* @return
|
307 |
*/
|
308 |
public String[] getFieldNames(){ |
309 |
String[] attributes = new String[fields.length]; |
310 |
for (int i=0 ; i<fields.length ; i++){ |
311 |
attributes[i] = fields[i].getName(); |
312 |
} |
313 |
return attributes;
|
314 |
} |
315 |
|
316 |
/**
|
317 |
* @param fields The fields to set.
|
318 |
*/
|
319 |
public void setFields(WFSAttribute[] fields) { |
320 |
this.fields = fields;
|
321 |
} |
322 |
/**
|
323 |
* @return Returns the name.
|
324 |
*/
|
325 |
public String getName() { |
326 |
return name;
|
327 |
} |
328 |
/**
|
329 |
* @param name The name to set.
|
330 |
*/
|
331 |
public void setName(String name) { |
332 |
this.name = name;
|
333 |
} |
334 |
/**
|
335 |
* @return Returns the host.
|
336 |
*/
|
337 |
public URL getHost() { |
338 |
return host;
|
339 |
} |
340 |
/**
|
341 |
* @param host The host to set.
|
342 |
*/
|
343 |
public void setHost(URL host) { |
344 |
this.host = host;
|
345 |
} |
346 |
|
347 |
/**
|
348 |
* @return Returns the wfs.
|
349 |
*/
|
350 |
public FMapWFSDriver getWfsDriver() {
|
351 |
return wfsDriver;
|
352 |
} |
353 |
|
354 |
/**
|
355 |
* @param wfs The wfs to set.
|
356 |
*/
|
357 |
public void setWfsDriver(FMapWFSDriver wfs) { |
358 |
this.wfsDriver = wfs;
|
359 |
} |
360 |
|
361 |
|
362 |
/*
|
363 |
* (non-Javadoc)
|
364 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#getStrategy()
|
365 |
*/
|
366 |
// public Strategy getStrategy() {
|
367 |
// if (wfsStrategy == null){
|
368 |
// wfsStrategy = new WFSStrategy(this);
|
369 |
// }
|
370 |
// return wfsStrategy;
|
371 |
// }
|
372 |
|
373 |
/*
|
374 |
* (non-Javadoc)
|
375 |
* @see com.iver.cit.gvsig.fmap.layers.FLayer#getFullExtent()
|
376 |
*/
|
377 |
public Rectangle2D getFullExtent() throws DriverException { |
378 |
try {
|
379 |
Rectangle2D extent = wfsDriver.getFullExtent();
|
380 |
if (getCoordTrans() != null){ |
381 |
return getCoordTrans().convert(extent);
|
382 |
} |
383 |
return extent;
|
384 |
} catch (IOException e) { |
385 |
throw new DriverException(e.toString()); |
386 |
} |
387 |
} |
388 |
|
389 |
/**
|
390 |
* @return Returns the onlineResource.
|
391 |
*/
|
392 |
public String getOnlineResource() { |
393 |
return onlineResource;
|
394 |
} |
395 |
|
396 |
/**
|
397 |
* @param onlineResource The onlineResource to set.
|
398 |
*/
|
399 |
public void setOnlineResource(String onlineResource) { |
400 |
this.onlineResource = onlineResource;
|
401 |
} |
402 |
|
403 |
public HashMap getProperties() { |
404 |
HashMap info = new HashMap(); |
405 |
info.put("name", getName());
|
406 |
info.put("layerName", getLayerName());
|
407 |
info.put("layerText", getLayerText());
|
408 |
info.put("attributes", getFields());
|
409 |
info.put("host", getHost());
|
410 |
info.put("wfsLayerNode", getWfsLayerNode());
|
411 |
WFSStatus status = new WFSStatus(getLayerName());
|
412 |
status.setBuffer(getNumfeatures()); |
413 |
status.setTimeout(getTimeout()); |
414 |
status.setUserName(getUserName()); |
415 |
status.setPassword(getPassword()); |
416 |
info.put("status",status);
|
417 |
return info;
|
418 |
|
419 |
} |
420 |
|
421 |
/**
|
422 |
* @return Returns the wfsLayerNode.
|
423 |
*/
|
424 |
public WFSLayerNode getWfsLayerNode() {
|
425 |
return wfsLayerNode;
|
426 |
} |
427 |
|
428 |
/**
|
429 |
* @param wfsLayerNode The wfsLayerNode to set.
|
430 |
*/
|
431 |
public void setWfsLayerNode(WFSLayerNode wfsLayerNode) { |
432 |
this.wfsLayerNode = wfsLayerNode;
|
433 |
} |
434 |
|
435 |
public void setHost(String host2) { |
436 |
try {
|
437 |
setHost(new URL(host2)); |
438 |
} catch (MalformedURLException e) { |
439 |
// TODO Auto-generated catch block
|
440 |
e.printStackTrace(); |
441 |
} |
442 |
} |
443 |
|
444 |
public ImageIcon getTocImageIcon() { |
445 |
return new ImageIcon(PluginServices.getPluginServices("com.iver.cit.gvsig.wfs2").getClassLoader().getResource("images/icoLayer.png")); |
446 |
} |
447 |
|
448 |
/*
|
449 |
* (non-Javadoc)
|
450 |
* @see com.iver.cit.gvsig.fmap.layers.FLyrVect#isPropertiesMenuVisible()
|
451 |
*/
|
452 |
public boolean isPropertiesMenuVisible(){ |
453 |
return false; |
454 |
} |
455 |
|
456 |
public String getSrs() { |
457 |
return srs;
|
458 |
} |
459 |
|
460 |
public void setSrs(String srs) { |
461 |
this.srs = srs;
|
462 |
} |
463 |
} |