Revision 1894

View differences:

branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/wfs/IWFSDriver.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. 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
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package com.iver.cit.gvsig.fmap.drivers.wfs;
42
import java.awt.geom.Rectangle2D;
43
import java.net.URL;
44
import java.sql.Connection;
45

  
46
import com.iver.cit.gvsig.fmap.DriverException;
47
import com.iver.cit.gvsig.fmap.core.IFeature;
48
import com.iver.cit.gvsig.fmap.core.IGeometry;
49
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
50
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
51

  
52
public interface IWFSDriver extends  VectorialDriver {
53
    /**
54
     * @param conn
55
     * @param tableName
56
     * @param fields (Todos los campos, el primero ha de ser el de las geometr?as
57
     * @param whereClause
58
     * @param id_FID_field El identificador del campo que contiene una clave ?nica. 1=> primer campo, 2 => segundo campo, etc
59
     * 
60
     */
61
    public void setData(int id_FID_field);
62
    public Rectangle2D getFullExtent();
63
    public int getShapeType();
64
    public IGeometry getShape(int index);
65
    public URL getHost();
66
    //public IFeatureIterator getFeatureIterator(String sql) throws DriverException;
67
    public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) throws DriverException;
68
	//public String getFields();
69
	//public String getWhereClause();
70
	public void close();
71
    public void open() throws com.iver.cit.gvsig.fmap.DriverException;
72
    /**
73
     * @param FID
74
     * @return el n?mero de registro asociado a ese FID. Se usa dentro
75
     * del DBStrategy para averig?ar si un Feature est? seleccionado
76
     * o no.
77
     */
78
    public int getRowIndexByFID(IFeature FID);
79
    
80
    
81
}
0 82

  
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/wfs/WFSFeatureIterator.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. 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
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package com.iver.cit.gvsig.fmap.drivers.wfs;
42

  
43
import java.io.IOException;
44
import java.sql.SQLException;
45
import java.util.ArrayList;
46
import java.util.Date;
47
import java.util.NoSuchElementException;
48

  
49
import org.geotools.data.FeatureReader;
50
import org.geotools.feature.DefaultFeature;
51
import org.geotools.feature.Feature;
52
import org.geotools.feature.IllegalAttributeException;
53

  
54
import com.hardcode.gdbms.engine.values.Value;
55
import com.hardcode.gdbms.engine.values.ValueFactory;
56
import com.iver.cit.gvsig.fmap.core.IFeature;
57
import com.iver.cit.gvsig.fmap.core.IGeometry;
58
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
59
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
60
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
61

  
62
public class WFSFeatureIterator implements IFeatureIterator{
63
	//private IFeature[] features=null;
64
	private FeatureReader featureReader;
65
	//private ArrayList features;
66
	//private int index=-1;
67
	//private int pos=0;
68
	public WFSFeatureIterator(FeatureReader fr){
69
		featureReader=fr;
70
	}
71
	/*public WFSFeatureIterator(ArrayList l){
72
		features=l;
73
	}*/
74
	public boolean hasNext(){
75
		/*if (features !=null){
76
			if (index<features.size()-1)
77
				return true;
78
			else{
79
				index=-1;
80
				features=null;
81
				return false;
82
			}
83
		}*/
84
		try {
85
			if (featureReader.hasNext()){
86
				return true;
87
			}else{
88
				featureReader.close();
89
				
90
				return false;
91
			}
92
		} catch (IOException e) {
93
			e.printStackTrace();
94
		}
95
		return false;
96
	}
97

  
98
	public IFeature next() throws SQLException {
99
	/*	if (features !=null){
100
			return (IFeature)features.get(++index);
101
		}*/
102
		Feature feature=null;
103
		try {
104
			feature = featureReader.next();
105
		} catch (NoSuchElementException e) {
106
			e.printStackTrace();
107
		} catch (IOException e) {
108
			e.printStackTrace();
109
		} catch (IllegalAttributeException e) {
110
			e.printStackTrace();
111
		}
112
		Object[] attr=null;
113
		attr=feature.getAttributes(attr);
114
		Value[] values=getValues(attr);
115
		
116
		IGeometry g=ShapeFactory.createGeometry(FConverter.jts_to_java2d(feature.getDefaultGeometry()));
117
		return new WFSFeature(g,values,feature.getID());
118
	}
119
	private Value[] getValues(Object[] attr) {
120
		Value[] values=new Value[attr.length];
121
		for (int i=1;i<attr.length;i++){
122
			if (attr[i]!=null){
123
				if (attr[i] instanceof Double){
124
					values[i]=ValueFactory.createValue(((Double)attr[i]).doubleValue());
125
				}else if (attr[i] instanceof String){
126
					values[i]=ValueFactory.createValue(String.valueOf(attr[i]));
127
				}else if (attr[i] instanceof Long){
128
					values[i]=ValueFactory.createValue(((Long)attr[i]).longValue());
129
				}else if (attr[i] instanceof Integer){
130
					values[i]=ValueFactory.createValue(((Integer)attr[i]).intValue());
131
				}else if (attr[i] instanceof Float){
132
					values[i]=ValueFactory.createValue(((Float)attr[i]).floatValue());
133
				}else if (attr[i] instanceof Short){
134
					values[i]=ValueFactory.createValue(((Short)attr[i]).shortValue());
135
				}else if (attr[i] instanceof Boolean){
136
					values[i]=ValueFactory.createValue(((Boolean)attr[i]).booleanValue());
137
				}else if (attr[i] instanceof Date){
138
					values[i]=ValueFactory.createValue(((Date)attr[i]));
139
				}
140
			//	System.out.println("class = "+attr[i].getClass());
141
					
142
			}else{
143
				values[i]=ValueFactory.createValue("");
144
			}
145
		}
146
		return values;
147
	}
148
	
149
}
0 150

  
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/wfs/WFSDriver.java
40 40
 */
41 41
package com.iver.cit.gvsig.fmap.drivers.wfs;
42 42

  
43
import java.awt.geom.Rectangle2D;
43 44
import java.io.IOException;
45
import java.net.MalformedURLException;
44 46
import java.net.ProtocolException;
47
import java.net.URL;
48
import java.sql.ResultSet;
49
import java.sql.SQLException;
50
import java.sql.Statement;
51
import java.sql.Types;
52
import java.util.ArrayList;
53
import java.util.HashMap;
54
import java.util.Hashtable;
55
import java.util.Map;
56
import java.util.NoSuchElementException;
45 57

  
58
import org.geotools.data.DataStore;
59
import org.geotools.data.DefaultFIDReader;
60
import org.geotools.data.DefaultQuery;
61
import org.geotools.data.FeatureReader;
62
import org.geotools.data.FeatureSource;
63
import org.geotools.data.Query;
64
import org.geotools.data.Transaction;
65
import org.geotools.data.ows.BoundingBox;
66
import org.geotools.data.wfs.WFSDataStoreFactory;
67
import org.geotools.factory.FactoryConfigurationError;
68
import org.geotools.feature.AttributeType;
69
import org.geotools.feature.DefaultFeature;
70
import org.geotools.feature.Feature;
71
import org.geotools.feature.IllegalAttributeException;
72
import org.geotools.filter.BBoxExpressionImpl;
73
import org.geotools.filter.FidFilter;
74
import org.geotools.filter.FidFilterImpl;
75
import org.geotools.filter.Filter;
76
import org.geotools.filter.FilterFactory;
77
import org.geotools.filter.FilterFactoryImpl;
78
import org.geotools.filter.IllegalFilterException;
79
import org.postgis.PGbox3d;
80

  
81
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
82
import com.hardcode.gdbms.engine.values.StringValue;
83
import com.hardcode.gdbms.engine.values.Value;
84
import com.hardcode.gdbms.engine.values.ValueFactory;
85
import com.iver.cit.gvsig.fmap.DriverException;
86
import com.iver.cit.gvsig.fmap.core.FShape;
87
import com.iver.cit.gvsig.fmap.core.IFeature;
46 88
import com.iver.cit.gvsig.fmap.core.IGeometry;
89
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
90
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
91
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
92
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
93
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
47 94
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
95
import com.iver.cit.gvsig.fmap.drivers.jdbc.mysql.MySqlFeatureIterator;
96
import com.vividsolutions.jts.geom.Envelope;
48 97

  
49
public interface WFSDriver extends  VectorialDriver {
50
    void describeFeatureType() throws IOException, WFSException, ProtocolException;
98
public class WFSDriver implements IWFSDriver,ObjectDriver {
99
	private Rectangle2D fullExtent=null;
100
	private Rectangle2D extent=null;
101
	private DataStore ds;
102
	//private FeatureReader fr;
103
	private String urlS="http://localhost:8080/geoserver/wfs";
104
	private String versionS="version=1.0.0";
105
	private String requestS="request=getcapabilities";
106
	private String serviceS="service=wfs";
107
	private Hashtable hashRelate;
108
	///private Hashtable indexFID;
109
	protected int idFID_FieldName;
110
	private int numReg=-1;
111
	private int numField=-1;
112
	private AttributeType[] attributes;
113
	//private FeatureReader fr;
114
	private ArrayList typeNames=new ArrayList();
115
	private ArrayList features=new ArrayList();
116
	
117
	public Rectangle2D getFullExtent() {
118
		return fullExtent;
119
	}
51 120

  
52
    IGeometry[] getFeature() throws IOException, WFSException, ProtocolException;
121
	public int getShapeType() {
122
		return FShape.MULTI;
123
	}
124
	private Filter createFidFilter(String[] fids) {
125
		 FidFilter filter = FilterFactory.createFilterFactory().createFidFilter();
126
	        for (int i = 0; i < fids.length; i++) {
127
	            filter.addFid(fids[i]);
128
	        }
129
        return filter;
130
    }
53 131

  
54
    void lockFeature() throws IOException, WFSException, ProtocolException;
132
	public IGeometry getShape(int index) {
133
		return ((IFeature)features.get(index)).getGeometry();
134
	}
55 135

  
56
    void transaction() throws IOException, WFSException, ProtocolException;
136
	public URL getHost() {
137
		try {
138
			return new URL(urlS+"?"+versionS+"&"+requestS+"&"+serviceS);
139
		} catch (MalformedURLException e) {
140
			e.printStackTrace();
141
		}
142
		return null;
143
	}
144

  
145
	public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) throws DriverException {
146
		WFSFeatureIterator geomIterator = null;
147
		/*if (r!=null && extent.contains(r)){
148
			//extent=(Rectangle2D)r.clone();
149
			return new WFSFeatureIterator(features);
150
		}
151
		*/
152
	       // ArrayList shapes=new ArrayList();   
153
		/*	BBoxExpressionImpl RectangleFilter=null;
154
			try {
155
				RectangleFilter = (BBoxExpressionImpl)FilterFactoryImpl.createFilterFactory().createBBoxExpression(new Envelope(fullExtent.getX(),fullExtent.getY(),fullExtent.getMaxX(),fullExtent.getMaxY()));
156
			} catch (IllegalFilterException e2) {
157
				e2.printStackTrace();
158
			} catch (FactoryConfigurationError e2) {
159
				e2.printStackTrace();
160
			}
161
			*/
162
			   Query query = new DefaultQuery((String)typeNames.get(0));
163
				FeatureReader fr=null;
164
				try {
165
					fr = ds.getFeatureReader(query,Transaction.AUTO_COMMIT);
166
					if (numField ==-1){
167
					numField=fr.getFeatureType().getAttributeCount();
168
					attributes=fr.getFeatureType().getAttributeTypes();
169
					}
170
				} catch (IOException e) {
171
					e.printStackTrace();
172
				}
173
				
174
				geomIterator=new WFSFeatureIterator(fr);
175
			   
176
			   
177
			/*   ResultSet rs = st.executeQuery(sql);
178
	            geomIterator = new MySqlFeatureIterator(rs);
179
	        } catch (SQLException e) {
180
	            e.printStackTrace();
181
	            throw new com.iver.cit.gvsig.fmap.DriverException(e);
182
	        }
183
	          */  
184
	        return geomIterator;
185
	}
186

  
187
	public void close() {
188
		
189
	}
190

  
191
	public void open() throws DriverException {
192
	}
193

  
194
	public int getRowIndexByFID(IFeature FID) {
195
		int resul;
196
	    Integer rowIndex = (Integer) hashRelate.get(FID.getID());
197
		resul = rowIndex.intValue();
198
		return resul;
199
	}
200

  
201
	public int getShapeCount() throws IOException {
202
		return numReg;
203
	}
204

  
205
	public DriverAttributes getDriverAttributes() {
206
		return null;
207
	}
208

  
209
	public String getName() {
210
		return "WFS Driver";
211
	}
212
	/**
213
     * Recorre el recordset creando una tabla Hash que usaremos para 
214
     * relacionar el n?mero de un registro con su identificador ?nico.
215
     * Debe ser llamado en el setData justo despu?s de crear el recorset
216
     * principal
217
     */
218
    protected void doRelateID_FID()
219
    {
220
		
221
		if (ds==null){
222
			URL url=null;
223
			try {
224
				url = new URL(urlS+"?"+versionS+"&"+requestS+"&"+serviceS);
225
			} catch (MalformedURLException e) {
226
				e.printStackTrace();
227
			}
228
			int timeout=10000;
229
			boolean protocol=true;
230
			
231
         Map m = new HashMap();
232
         m.put(WFSDataStoreFactory.URL.key,url);
233
         m.put(WFSDataStoreFactory.TIMEOUT.key,new Integer(timeout));
234
         m.put(WFSDataStoreFactory.PROTOCOL.key,new Boolean(protocol));
235
		 
236
        try {
237
			ds = (new WFSDataStoreFactory()).createNewDataStore(m);
238
		} catch (IOException e) {
239
			e.printStackTrace();
240
		}
241
		String[] names=null;
242
		try {
243
			names = ds.getTypeNames();
244
		} catch (IOException e1) {
245
			e1.printStackTrace();
246
		}
247
		System.out.println("Capas :");
248
       
249
		for (int i=0;i<names.length;i++){
250
			System.out.println("Capa "+i+" : "+names[i]);
251
			//Se selecciona la capa que se quiere abrir
252
			if (true)//si esta seleccionada en la lista o arbol que se muestre en el wizard
253
			typeNames.add(names[i]);
254
		}
255
		
256
	}
257
		
258
        hashRelate = new Hashtable();
259
		///indexFID = new Hashtable();
260
		Query query = new DefaultQuery((String)typeNames.get(0));
261
		FeatureReader fr=null;
262
		
263
			//fr = ds.getFeatureReader(query,Transaction.AUTO_COMMIT);
264
			
265
			int index = 0;
266
            IFeatureIterator iter=null;
267
			try {
268
				iter = getFeatureIterator(null,null);
269
			} catch (DriverException e) {
270
				e.printStackTrace();
271
			}
272
			
273
			try {
274
				while(iter.hasNext()){
275
					IFeature feature=iter.next();
276
					features.add(feature);
277
					Rectangle2D rect=feature.getGeometry().getBounds2D();
278
					if (fullExtent==null){
279
						fullExtent=new Rectangle2D.Double(rect.getMinX(),rect.getMinY(),rect.getWidth(),rect.getHeight());
280
					}else{
281
						fullExtent.add(new Rectangle2D.Double(rect.getMinX(),rect.getMinY(),rect.getWidth(),rect.getHeight()));
282
					}
283
					hashRelate.put(feature.getID(), new Integer(index));
284
					///indexFID.put(new Integer(index),feature.getID());
285
					index++;
286
				}
287
			} catch (SQLException e) {
288
				e.printStackTrace();
289
			}
290
			numReg = index;
291
			extent=fullExtent;
292
				 
293
			
294
    }
295

  
296
	public void setData(int id_FID_field) {
297
		idFID_FieldName=id_FID_field;
298
		doRelateID_FID();
299
	}
300
	
301
	public Value getFieldValue(long arg0, int arg1) throws com.hardcode.gdbms.engine.data.driver.DriverException {
302
		
303
		/*try {
304
			ds.getTypeNames();
305
		} catch (IOException e1) {
306
			e1.printStackTrace();
307
		}*/
308
		/*System.out.println("Filter");
309
		Filter fidFilter=createFilter(new String[]{(String)indexFID.get(new Integer((int)arg0))});
310
		System.out.println("Query");
311
		Query query = new DefaultQuery((String)typeNames.get(0),fidFilter);
312
		FeatureReader fr=null;
313
		try {
314
			System.out.println("getFeatureReader");
315
			fr = ds.getFeatureReader(query,Transaction.AUTO_COMMIT);
316
		} catch (IOException e) {
317
			e.printStackTrace();
318
		}
319
			try {
320
				return getValue(fr,arg1);
321
			} catch (NoSuchElementException e) {
322
				e.printStackTrace();
323
			} catch (IOException e) {
324
				e.printStackTrace();
325
			} catch (IllegalAttributeException e) {
326
				e.printStackTrace();
327
			}
328
			*/
329
		return ((IFeature)features.get((int)arg0)).getAttribute(arg1+1);
330
	}
331

  
332
	public int getFieldCount() throws com.hardcode.gdbms.engine.data.driver.DriverException {
333
		return numField-1;
334
	}
335

  
336
	public String getFieldName(int arg0) throws com.hardcode.gdbms.engine.data.driver.DriverException {
337
		return attributes[arg0].getName();		
338
	}
339

  
340
	public long getRowCount() throws com.hardcode.gdbms.engine.data.driver.DriverException {
341
		return numReg;
342
	}
343

  
344
	public int getFieldType(int arg0) throws com.hardcode.gdbms.engine.data.driver.DriverException {
345
		attributes[arg0].getType();
346
		return FIELD_TYPE_STRING;//fr.getFeatureType().getAttributeType(arg0).getType();
347
	}
57 348
}
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/wfs/WFSFeature.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. 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
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package com.iver.cit.gvsig.fmap.drivers.wfs;
42

  
43
import com.hardcode.gdbms.engine.values.Value;
44
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
45
import com.iver.cit.gvsig.fmap.core.IGeometry;
46

  
47
public class WFSFeature extends DefaultFeature{
48
	private String id;
49
	
50
	public WFSFeature(IGeometry geom, Value[] att,String id) {
51
		super(geom, att);
52
		this.id=id;
53
	}
54
	public String getID(){
55
		return id;
56
	}
57
}
0 58

  
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/operations/strategies/StrategyManager.java
44 44
import com.iver.cit.gvsig.fmap.layers.FLayer;
45 45
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
46 46
import com.iver.cit.gvsig.fmap.layers.VectorialDBAdapter;
47
import com.iver.cit.gvsig.fmap.layers.WFSAdapter;
47 48
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
48 49

  
49 50

  
......
68 69
		} else {
69 70
		    if (v.getSource() instanceof VectorialDBAdapter)
70 71
		        return new DBStrategy((FLayer) v);
71
		    else  
72
		    else if (v.getSource() instanceof WFSAdapter)
73
		        return new WFSStrategy((FLayer) v);
74
			else  
72 75
		        return new DefaultStrategy((FLayer) v);
73 76
		}
74 77
	}
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/operations/strategies/WFSStrategy.java
1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
*
3
* Copyright (C) 2004 IVER T.I. 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
*   IVER T.I. S.A
34
*   Salamanca 50
35
*   46005 Valencia
36
*   Spain
37
*
38
*   +34 963163400
39
*   dac@iver.es
40
*/
41
package com.iver.cit.gvsig.fmap.operations.strategies;
42

  
43
import java.awt.Graphics2D;
44
import java.awt.image.BufferedImage;
45
import java.sql.SQLException;
46

  
47
import org.cresques.cts.ICoordTrans;
48

  
49
import com.iver.cit.gvsig.fmap.DriverException;
50
import com.iver.cit.gvsig.fmap.ViewPort;
51
import com.iver.cit.gvsig.fmap.core.IFeature;
52
import com.iver.cit.gvsig.fmap.core.IGeometry;
53
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
54
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
55
import com.iver.cit.gvsig.fmap.drivers.VectorialDatabaseDriver;
56
import com.iver.cit.gvsig.fmap.drivers.VectorialDriver;
57
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSDriver;
58
import com.iver.cit.gvsig.fmap.layers.FBitSet;
59
import com.iver.cit.gvsig.fmap.layers.FLayer;
60
import com.iver.cit.gvsig.fmap.layers.VectorialDBAdapter;
61
import com.iver.cit.gvsig.fmap.layers.WFSAdapter;
62
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
63
import com.iver.cit.gvsig.fmap.layers.layerOperations.Selectable;
64
import com.iver.cit.gvsig.fmap.layers.layerOperations.SingleLayer;
65
import com.iver.cit.gvsig.fmap.operations.Cancellable;
66
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
67
/**
68
 * Estrategia para WFS.
69
 *
70
 * @author Vicente Caballero Navarro
71
 */
72
public class WFSStrategy extends DefaultStrategy {
73

  
74
	public WFSStrategy(FLayer capa) {
75
		super(capa);
76
	}
77

  
78

  
79
    /* (non-Javadoc)
80
     * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#draw(java.awt.image.BufferedImage, java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort, com.iver.cit.gvsig.fmap.operations.Cancellable)
81
     */
82
    public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, Cancellable cancel) throws DriverException {
83
        // Nos aprovechamos del SQL para lanzar la consulta
84
        // teniendo en cuenta el boundingbox que toca.
85
        FLayer capa = getCapa();
86
        WFSAdapter wfsAdapter = (WFSAdapter) ((SingleLayer) capa).getSource();
87
        WFSDriver wfsDriver = (WFSDriver) wfsAdapter.getDriver();
88
        wfsAdapter.start();
89
		Selectable selection = (Selectable) getCapa();
90
		ICoordTrans ct = getCapa().getCoordTrans();
91
		FBitSet bitSet = selection.getSelection();
92
        
93
        String strEPSG = viewPort.getProjection().getAbrev().substring(5);
94
        IFeatureIterator geomIt = wfsAdapter.getFeatureIterator(viewPort.getAdjustedExtent(), strEPSG);
95
        VectorialLegend l = (VectorialLegend) ((ClassifiableVectorial) capa).getLegend();
96
        int i;
97
        FSymbol symbol;
98
        try {
99
            while (geomIt.hasNext())
100
            {
101
            	if (cancel.isCanceled()) {
102
            	    wfsAdapter.stop();
103
            		break;
104
            	}
105
            	IFeature feat = geomIt.next();
106
                IGeometry geom = feat.getGeometry();
107
                // TODO: CORREGIR LO DE LOS SIMBOLOS
108
                // Es probable que necesitemos generar un Feature
109
                // (Geometr?a + Atributos) para que opere con esa feature
110
                // el gestor de leyendas. A la leyenda le pasar?amos un
111
                // feature, y nos devolver? la colecci?n de s?mbolos a 
112
                // aplicar. Similar a lo de "processStylers" de GT2
113
				// if (viewPort.getAdjustedExtent().intersects(geom.getBounds2D())){
114
				i = wfsDriver.getRowIndexByFID(feat);
115
                symbol = l.getSymbolByFeature(feat);                
116
                if (symbol == null) continue;
117
               if (bitSet.get(i)) {
118
                    symbol = FSymbol.getSymbolForSelection(symbol);
119
                }
120
                
121
                //FSymbol symbol = l.getDefaultSymbol();
122
                geom.draw(g,viewPort, symbol);
123
            }
124
            //}
125
        } catch (SQLException e) {
126
            e.printStackTrace();
127
            throw new DriverException(e);
128
        }
129
        wfsAdapter.stop();
130
        
131
    }
132
    
133

  
134
}
0 135

  
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/WFSAdapter.java
40 40
 */
41 41
package com.iver.cit.gvsig.fmap.layers;
42 42

  
43
import java.awt.geom.Rectangle2D;
44
import java.io.IOException;
45
import java.net.URL;
46

  
47
import com.hardcode.driverManager.DriverLoadException;
43 48
import com.hardcode.gdbms.engine.data.DataSource;
44

  
49
import com.hardcode.gdbms.engine.data.DataSourceFactory;
50
import com.hardcode.gdbms.engine.data.NoSuchTableException;
51
import com.hardcode.gdbms.engine.data.driver.ObjectDriver;
45 52
import com.iver.cit.gvsig.fmap.DriverException;
53
import com.iver.cit.gvsig.fmap.core.FShape;
46 54
import com.iver.cit.gvsig.fmap.core.IGeometry;
47 55
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
56
import com.iver.cit.gvsig.fmap.drivers.IFeatureIterator;
57
import com.iver.cit.gvsig.fmap.drivers.wfs.IWFSDriver;
48 58
import com.iver.cit.gvsig.fmap.drivers.wfs.WFSDriver;
49
import com.iver.cit.gvsig.fmap.rendering.indexes.IndexNotExistsException;
50 59

  
51
import java.awt.geom.Rectangle2D;
52 60

  
53
import java.net.URL;
54

  
55

  
56 61
/**
57 62
 * Adapta un driver de WFS a la interfaz vectorial, manteniendo adem?s el
58 63
 * estado necesario por una capa vectorial WFS (URL del host, estado del
......
61 66
public class WFSAdapter extends VectorialAdapter {
62 67
	private URL host;
63 68
	private VectorialAdapter tempAdapter;
69
	private int numReg=-1;
70
	private DataSource ds = null;
71
		/**
72
		 * incrementa el contador de las veces que se ha abierto el fichero.
73
		 * Solamente cuando el contador est? a cero pide al driver que conecte con
74
		 * la base de datos
75
		 */
76
		public void start() {
77
	        /*    try {
78
	                ((IWFSDriver)driver).open();
79
	            } catch (DriverException e) {
80
	                // TODO Auto-generated catch block
81
	                e.printStackTrace();
82
	            }
83
		*/
84
		}
64 85

  
65
	/**
66
	 * incrementa el contador de las veces que se ha abierto el fichero.
67
	 * Solamente cuando el contador est? a cero pide al driver que conecte con
68
	 * el servidor WFS
69
	 */
70
	public void start() {
71
	}
86
		/**
87
		 * decrementa el contador de n?mero de aperturas y cuando llega a cero pide
88
		 * al driver que cierre la conexion con el servidor de base de datos
89
		 */
90
		public void stop() {
91
		    ((IWFSDriver)driver).close();
92
		}
72 93

  
73
	/**
74
	 * M?todo ejecutado para finalizar.
75
	 */
76
	public void stop() {
77
	}
94
		public IFeatureIterator getFeatureIterator(Rectangle2D r, String strEPSG) throws DriverException
95
		{
96
		    return ((IWFSDriver)driver).getFeatureIterator(r, strEPSG);
97
		}
98
		
99
		/*public String getFields()
100
		{
101
		    return ((IWFSDriver)driver).getFields();	    
102
		}
103
		public String getWhereClause()
104
		{
105
		    return ((VectorialDatabaseDriver)driver).getWhereClause();
106
		}
107
		public String getTableName()
108
		{
109
		    return ((VectorialDatabaseDriver)driver).getTableName();
110
		}
111
		
112
		*/
113
		/**
114
		 * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShape(int)
115
		 */
116
		public IGeometry getShape(int index) throws DriverIOException {
117
		    IGeometry geom = null;
118
		    geom = ((IWFSDriver)driver).getShape(index);
119
		    return geom;
120
		}
78 121

  
79
	/**
80
	 * Inserta el driver.
81
	 *
82
	 * @param driver
83
	 */
84
	public void setDriver(WFSDriver driver) {
85
	}
122
		/**
123
		 * @throws DriverException
124
		 * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeCount()
125
		 */
126
		public int getShapeCount() throws DriverIOException {
127
			try {
128
				return ((IWFSDriver)driver).getShapeCount();
129
			} catch (IOException e) {
130
				e.printStackTrace();
131
			}	
132
			return -1;
133
		}
86 134

  
87
	/**
88
	 * Establece el adaptador que se usar? para acceder a los datos temporales
89
	 * obtenidos del servidor
90
	 *
91
	 * @param adapter
92
	 */
93
	private void createTempFile(VectorialFileAdapter adapter) {
94
	}
135
		/**
136
		 * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
137
		 */
138
		public Rectangle2D getFullExtent() {
139
		    return ((IWFSDriver)driver).getFullExtent();
140
		}
95 141

  
96
	/**
97
	 * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShape(int)
98
	 */
99
	public IGeometry getShape(int index) throws DriverIOException {
100
		return null;
101
	}
102 142

  
103
	/**
104
	 * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeCount()
105
	 */
106
	public int getShapeCount() throws DriverIOException {
107
		return 0;
108
	}
143
		/**
144
		 * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType()
145
		 */
146
		public int getShapeType() throws DriverIOException {
147
			return FShape.MULTI;
148
		}
109 149

  
110
	/**
111
	 * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getFullExtent()
112
	 */
113
	public Rectangle2D getFullExtent() throws DriverIOException {
114
		return null;
115
	}
116

  
117
	/**
118
	 * @see com.iver.cit.gvsig.fmap.rendering.indexes.Index#getRecordIndexes(java.awt.geom.Rectangle2D)
119
	 */
120
	public int[] getRecordIndexes(Rectangle2D rect)
121
		throws DriverIOException, IndexNotExistsException {
122
		return null;
123
	}
124

  
125
	/**
126
	 * @see com.iver.cit.gvsig.fmap.layers.ReadableVectorial#getShapeType()
127
	 */
128
	public int getShapeType() throws DriverIOException {
129
		return 0;
130
	}
131

  
132
	/**
133
	 * @see com.iver.cit.gvsig.fmap.layers.VectorialAdapter#getRecordset()
134
	 */
135
	public DataSource getRecordset() {
136
		return null;
137
	}
138

  
139
	/**
140
	 * @see com.iver.cit.gvsig.fmap.layers.VectorialAdapter#changeRecordsetName(java.lang.String)
141
	 */
142
	public void changeRecordsetName(String newName) throws DriverException {
143
	}
150
		/**
151
		 * @see com.iver.cit.gvsig.fmap.layers.VectorialAdapter#getRecordset()
152
		 */
153
		public DataSource getRecordset() throws DriverLoadException {
154
		    if (driver instanceof WFSDriver)
155
		    {
156
				String name = LayerFactory.getDataSourceFactory().addDataSource((ObjectDriver)driver, null);
157
				try {
158
	                ds = LayerFactory.getDataSourceFactory().createRandomDataSource(name, DataSourceFactory.AUTOMATIC_MODE);
159
	            } catch (NoSuchTableException e) {
160
	                throw new RuntimeException(e);
161
				} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
162
					throw new RuntimeException(e);
163
				}
164
		    }
165
			return ds;
166
		}
144 167
}
branches/FMap_SLD/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/LayerFactory.java
265 265
	 *
266 266
	 * @throws UnsupportedOperationException
267 267
	 */
268
	public static FLayer createLayer(WFSDriver driver, URL host,
268
	public static FLayer createWFSLayer(String layerName,WFSDriver driver, URL host,
269 269
		IProjection proj) {
270
		throw new UnsupportedOperationException();
270
		//throw new UnsupportedOperationException();
271
		FLyrVect layer=new FLyrVect();
272
		//layer.setName(name);
273
		VectorialAdapter adapter=new WFSAdapter();
274
		adapter.setDriver(driver);
275
		//WithDefaultLegend aux=(WithDefaultLegend)driver;
276
		
277
		layer.setName(layerName);
278
		layer.setSource(adapter);
279
		layer.setProjection(proj);
280
		try {
281
			layer.setLegend(LegendFactory.createSingleSymbolLegend(
282
					layer.getShapeType()));
283
		} catch (FieldNotFoundException e) {
284
			e.printStackTrace();
285
		} catch (DriverException e) {
286
			e.printStackTrace();
287
		}
288
		//layer.setHost(host);
289
		return layer;
271 290
	}
272 291

  
273 292
	/**

Also available in: Unified diff