svn-gvsig-desktop / trunk / extensions / extWFS2 / src / com / iver / cit / gvsig / fmap / layers / FLyrWFSFactory.java @ 34392
History | View | Annotate | Download (4.89 KB)
1 |
package com.iver.cit.gvsig.fmap.layers; |
---|---|
2 |
|
3 |
import java.awt.Component; |
4 |
import java.net.URL; |
5 |
|
6 |
import javax.swing.JOptionPane; |
7 |
|
8 |
import org.apache.log4j.Logger; |
9 |
import org.cresques.cts.IProjection; |
10 |
|
11 |
import com.iver.andami.PluginServices; |
12 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
13 |
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
14 |
import com.iver.cit.gvsig.fmap.drivers.wfs.FMapWFSDriver; |
15 |
import com.iver.cit.gvsig.project.documents.view.gui.BaseView; |
16 |
|
17 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
18 |
*
|
19 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
20 |
*
|
21 |
* This program is free software; you can redistribute it and/or
|
22 |
* modify it under the terms of the GNU General Public License
|
23 |
* as published by the Free Software Foundation; either version 2
|
24 |
* of the License, or (at your option) any later version.
|
25 |
*
|
26 |
* This program is distributed in the hope that it will be useful,
|
27 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
28 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
29 |
* GNU General Public License for more details.
|
30 |
*
|
31 |
* You should have received a copy of the GNU General Public License
|
32 |
* along with this program; if not, write to the Free Software
|
33 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
34 |
*
|
35 |
* For more information, contact:
|
36 |
*
|
37 |
* Generalitat Valenciana
|
38 |
* Conselleria d'Infraestructures i Transport
|
39 |
* Av. Blasco Ib??ez, 50
|
40 |
* 46010 VALENCIA
|
41 |
* SPAIN
|
42 |
*
|
43 |
* +34 963862235
|
44 |
* gvsig@gva.es
|
45 |
* www.gvsig.gva.es
|
46 |
*
|
47 |
* or
|
48 |
*
|
49 |
* IVER T.I. S.A
|
50 |
* Salamanca 50
|
51 |
* 46005 Valencia
|
52 |
* Spain
|
53 |
*
|
54 |
* +34 963163400
|
55 |
* dac@iver.es
|
56 |
*/
|
57 |
/* CVS MESSAGES:
|
58 |
*
|
59 |
* $Id: FLyrWFSFactory.java 13632 2007-09-11 16:00:50Z jorpiell $
|
60 |
* $Log$
|
61 |
* Revision 1.2.2.6 2007-09-11 16:00:50 jorpiell
|
62 |
* If the SRS is not supported by gvSIG, an information message is showed
|
63 |
*
|
64 |
* Revision 1.2.2.5 2007/04/03 10:24:25 jorpiell
|
65 |
* La transformaci?n de coordenadas que se usa para reproyactar no debe ponerse en la capa a pi?on fijo.
|
66 |
*
|
67 |
* Revision 1.2.2.4 2007/01/04 10:06:25 jcampos
|
68 |
* Upgrade new version
|
69 |
*
|
70 |
* Revision 1.2.2.3 2006/11/17 11:28:45 ppiqueras
|
71 |
* Corregidos bugs y a?adida nueva funcionalidad.
|
72 |
*
|
73 |
* Revision 1.3 2006/11/16 16:57:05 jorpiell
|
74 |
* Se inserta en adapter
|
75 |
*
|
76 |
* Revision 1.2 2006/11/06 13:58:03 jorpiell
|
77 |
* Al crear una nueva capa se declara como activa. De esa forma se pueden aplicar tantos filtros como queramos
|
78 |
*
|
79 |
* Revision 1.1 2006/10/31 09:38:15 jorpiell
|
80 |
* Se ha creado una factoria para crear la capa. De ese modo no se repite c?digo desde le panel de propiedades y desde el panel de la capa
|
81 |
*
|
82 |
*
|
83 |
*/
|
84 |
/**
|
85 |
* @author Jorge Piera Llodr? (piera_jor@gva.es)
|
86 |
*/
|
87 |
public class FLyrWFSFactory { |
88 |
|
89 |
/**
|
90 |
*
|
91 |
* @param layer
|
92 |
* @param host
|
93 |
* @param onlineResource
|
94 |
* @param driver
|
95 |
* @param loadLayer
|
96 |
* If the layer has to be loaded
|
97 |
* @param firstLoad
|
98 |
* If is the first time that the layer is loaded
|
99 |
* @return
|
100 |
*/
|
101 |
public FLyrWFS getFLyrWFS(FLayer layer,
|
102 |
URL host,
|
103 |
String onlineResource,
|
104 |
FMapWFSDriver driver, |
105 |
boolean loadLayer,
|
106 |
boolean firstLoad){
|
107 |
FLyrWFS wfsLayer = (FLyrWFS)layer; |
108 |
wfsLayer.setHost(host); |
109 |
wfsLayer.setWfsDriver(driver); |
110 |
// Sets the WFS adapter
|
111 |
WFSAdapter adapter = new WFSAdapter();
|
112 |
adapter.setDriver((VectorialDriver) driver); |
113 |
wfsLayer.setSource(adapter); |
114 |
wfsLayer.setOnlineResource(onlineResource); |
115 |
BaseView activeView = |
116 |
(BaseView) PluginServices.getMDIManager().getActiveWindow(); |
117 |
//The SRS original
|
118 |
IProjection projection = CRSFactory.getCRS(getSRS(wfsLayer.getSrs())); |
119 |
wfsLayer.setProjection(projection); |
120 |
if (loadLayer){
|
121 |
try {
|
122 |
if ((projection == null) && (firstLoad)){ |
123 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
124 |
PluginServices.getText(this,"wfs_srs_unknown")); |
125 |
} |
126 |
wfsLayer.load(); |
127 |
if (wfsLayer.getNumfeatures() == wfsLayer.getWfsDriver().getRowCount()) {
|
128 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
129 |
PluginServices.getText(this,"maxFeatures_aviso")); |
130 |
} |
131 |
} catch (Exception e) { |
132 |
// TODO Auto-generated catch block
|
133 |
Logger.getLogger(getClass().getName()).error(e.getMessage());
|
134 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), |
135 |
PluginServices.getText(this,"cantLoad")); |
136 |
return null; |
137 |
} |
138 |
} |
139 |
wfsLayer.setActive(true);
|
140 |
return wfsLayer;
|
141 |
} |
142 |
|
143 |
/**
|
144 |
* Removing the URN prefix
|
145 |
* @param srs
|
146 |
* @return
|
147 |
*/
|
148 |
private String getSRS(String srs){ |
149 |
if (srs == null){ |
150 |
return null; |
151 |
} |
152 |
if ((srs.startsWith("urn:x-ogc:def:crs:")) || srs.startsWith("urn:ogc:def:crs:")){ |
153 |
String newString = srs.substring(srs.lastIndexOf(":") + 1, srs.length()); |
154 |
if (srs.indexOf("EPSG") > 0){ |
155 |
if (newString.indexOf("EPSG") < 0){ |
156 |
newString = "EPSG:" + newString;
|
157 |
} |
158 |
} |
159 |
return newString;
|
160 |
} |
161 |
if (srs.toLowerCase().startsWith("crs:")){ |
162 |
return srs.substring(4, srs.length()); |
163 |
} |
164 |
return srs;
|
165 |
} |
166 |
|
167 |
} |