Revision 32734 branches/v2_0_0_prep/extensions/extWFS2/src/org/gvsig/fmap/dal/store/wfs/WFSStoreProvider.java

View differences:

WFSStoreProvider.java
31 31
import java.util.List;
32 32
import java.util.Vector;
33 33

  
34
import org.cresques.cts.ICoordTrans;
34 35
import org.cresques.cts.IProjection;
35 36
import org.gvsig.fmap.crs.CRSFactory;
36 37
import org.gvsig.fmap.dal.DALLocator;
......
51 52
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
52 53
import org.gvsig.fmap.dal.store.gpe.GPEStoreProvider;
53 54
import org.gvsig.fmap.geom.Geometry;
55
import org.gvsig.fmap.geom.GeometryLocator;
56
import org.gvsig.fmap.geom.GeometryManager;
57
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
54 58
import org.gvsig.fmap.geom.Geometry.TYPES;
59
import org.gvsig.fmap.geom.exception.CreateEnvelopeException;
55 60
import org.gvsig.fmap.geom.primitive.Envelope;
56 61
import org.gvsig.remoteclient.ogc.OGCClientOperation;
62
import org.gvsig.remoteclient.utils.BoundaryBox;
57 63
import org.gvsig.remoteclient.wfs.WFSClient;
58 64
import org.gvsig.remoteclient.wfs.WFSFeature;
59 65
import org.gvsig.remoteclient.wfs.WFSStatus;
......
81 87
	private static final String DYNCLASS_NAME = "WFSStore";
82 88
	protected static DynClass DYNCLASS = null;
83 89
	private IProjection projection;	
90
	private static final GeometryManager geometryManager = GeometryLocator.getGeometryManager();
84 91

  
85 92
	boolean isFilterByAreaSupported = true;
86 93

  
......
107 114
				}
108 115
			} catch (IOException e) {
109 116
				throw new InitializeException(e);
110
			}
117
			}			
111 118
			wfsStatus = new WFSStatus( wfsParameters.getFeatureType(),
112 119
					wfsParameters.getFeaturePrefix());
113 120
			wfsStatus.setNamespace(wfsParameters.getFeatureNamespace());
......
118 125
			wfsStatus.setUserName(wfsParameters.getUser());
119 126
			wfsStatus.setPassword(wfsParameters.getPassword());
120 127

  
128
			//Setting the envelope for the layer
129
			wfsClient.getCapabilities(wfsStatus, false, null);
130

  
131
			Envelope envelope = calculateFullEnvelope();
132
			if (envelope != null){
133
				this.setDynValue("Envelope", envelope);
134
			}
135

  
121 136
			m_Fich = wfsClient.getFeature(wfsStatus, true, null);
122 137
		} catch (WFSException e) {
123 138
			throw new InitializeException("Impossible to retrieve the file", e);
124 139
		}
125 140
	}
126 141

  
142
	private Envelope calculateFullEnvelope() {
143
		Object obj = wfsClient.getFeatures().get(wfsStatus.getFeatureName());
144
		try{
145
			if (obj != null){
146
				WFSFeature feature = (WFSFeature)obj;
147
				if (feature.getSrs().size() > 0){
148
					String srs = (String)feature.getSrs().get(0);
149
					BoundaryBox boundaryBox = feature.getBbox("srs");
150
					if (boundaryBox == null)
151
					{
152
						boundaryBox = feature.getBbox(getEPSGCode("srs"));
153
					}	
154
					//The projection is found
155
					if (boundaryBox != null){
156
						return geometryManager.createEnvelope(boundaryBox.getXmin(),
157
								boundaryBox.getYmin(), boundaryBox.getXmax(), boundaryBox.getYmax(), SUBTYPES.GEOM2D);
158
					}
159
					//Check if there is a latlon envelope
160
					boundaryBox = feature.getLatLonBbox();
161
					if (boundaryBox != null){
162
						Envelope envelope = geometryManager.createEnvelope(boundaryBox.getXmin(),
163
								boundaryBox.getYmin(), boundaryBox.getXmax(), boundaryBox.getYmax(), SUBTYPES.GEOM2D);
164
						IProjection projection = CRSFactory.getCRS(getEPSGCode(srs));
165
						if (projection != null){
166
							ICoordTrans coordTrans = projection.getCT(CRSFactory.getCRS(getEPSGCode("EPSG:4326")));
167
							return envelope.convert(coordTrans);
168
						}					
169
					}
170
				}
171
			}
172
		}catch(CreateEnvelopeException e){
173
			logger.error("Impossible to create an envelope", e);
174
		}
175
		return null;
176
	}
177

  
127 178
	private WFSStoreParameters getWFSParameters() {
128 179
		return (WFSStoreParameters) getParameters();
129 180
	}
......
198 249
	public FeatureSetProvider createSet(FeatureQuery query,
199 250
			FeatureType featureType) throws DataException {
200 251
		//If it is possible to execute a spatial query...
201
		//if (!executeSpatialQuery(query)){
202
			executeQuery();			
203
		//}
252
		if (query.getFilter() != null){
253
			executeSpatialQuery(query);
254
		}else{
255
			executeQuery();   
256
		}
204 257
		isOpen = false;
205 258
		open();
206 259
		return super.createSet(query, featureType);
......
265 318
	private void executeSpatialQuery() throws DataException{
266 319
		try {
267 320
			wfsStatus.setProtocol(OGCClientOperation.PROTOCOL_POST);
268
			//			wfsStatus.setResultType(WFSStatus.RESULTYPE_HITS);
269
			//			wfsClient.getFeature(wfsStatus, true, null);
270
			//			WFSGetFeatureRequestInformation requestInformation = 
271
			//				(WFSGetFeatureRequestInformation)wfsClient.getLastWfsRequestInformation();
272
			//			WFSServiceInformation serviceInformation = 
273
			//				wfsClient.getServiceInformation();
274
			//			if (requestInformation.getNumberOfFeatures() != 0){
275
			//				//TODO DefaultMaxFeatures
276
			//				if (requestInformation.getNumberOfFeatures() == wfsStatus.getBuffer()){
277
			//					//Divide the space in 4 rectangles
278
			//					WFSSpatialFilterOperation spatialFilterOperation = wfsStatus.getFilterByArea();
279
			//					
280
			//				}
281
			//			}
321
//			wfsStatus.setResultType(WFSStatus.RESULTYPE_HITS);
322
//			wfsClient.getFeature(wfsStatus, true, null);
323
//
324
//			WFSGetFeatureRequestInformation requestInformation = (WFSGetFeatureRequestInformation)wfsClient.getLastWfsRequestInformation();
325
//			WFSServiceInformation serviceInformation = wfsClient.getServiceInformation();
326
//			if (requestInformation.getNumberOfFeatures() != 0){
327
//				//TODO DefaultMaxFeatures
328
//				if (requestInformation.getNumberOfFeatures() == wfsStatus.getBuffer()){
329
//					//Divide the space in 4 rectangles
330
//					WFSSpatialFilterOperation spatialFilterOperation = wfsStatus.getFilterByArea();
331
//
332
//				}
333
//			}
282 334
			//If it is not possible to calculate the 
283 335
			wfsStatus.setResultType(WFSStatus.RESULTYPE_RESULTS);
284 336
			m_Fich = wfsClient.getFeature(wfsStatus, true, null);

Also available in: Unified diff