Revision 12799

View differences:

branches/v10/libraries/libFMap/src/com/iver/cit/gvsig/fmap/operations/strategies/DBStrategy.java
2 2
 * Created on 08-mar-2005
3 3
 *
4 4
 * gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
5
 * 
5
 *
6 6
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
7
 * 
7
 *
8 8
 * This program is free software; you can redistribute it and/or
9 9
 * modify it under the terms of the GNU General Public License
10 10
 * as published by the Free Software Foundation; either version 2
11 11
 * of the License, or (at your option) any later version.
12
 *  
12
 *
13 13
 * This program is distributed in the hope that it will be useful,
14 14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 16
 * GNU General Public License for more details.
17
 * 
17
 *
18 18
 * You should have received a copy of the GNU General Public License
19 19
 * along with this program; if not, write to the Free Software
20 20
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21
 *  
21
 *
22 22
 * For more information, contact:
23 23
 *
24 24
 *  Generalitat Valenciana
......
30 30
 *      +34 963862235
31 31
 *   gvsig@gva.es
32 32
 *      www.gvsig.gva.es
33
 * 
33
 *
34 34
 *    or
35
 * 
35
 *
36 36
 *   IVER T.I. S.A
37 37
 *   Salamanca 50
38 38
 *   46005 Valencia
39 39
 *   Spain
40
 * 
40
 *
41 41
 *   +34 963163400
42 42
 *   dac@iver.es
43 43
 */
......
90 90
        // teniendo en cuenta el boundingbox que toca.
91 91
        FLyrVect lyr = (FLyrVect) getCapa();
92 92
        ISpatialDB dbAdapter = (ISpatialDB) ((SingleLayer) capa).getSource();
93

  
94
        boolean isJoined = lyr.isJoined();
95

  
93 96
        IVectorialDatabaseDriver dbDriver = (IVectorialDatabaseDriver) dbAdapter.getDriver();
94 97
        try {
95 98
			dbAdapter.start();
96 99
	        Selectable selectable=lyr.getRecordset();
97 100
			ICoordTrans ct = lyr.getCoordTrans();
98 101
			FBitSet bitSet = selectable.getSelection();
99
	        
102

  
100 103
	        String strEPSG = viewPort.getProjection().getAbrev().substring(5);
101 104
	        // TODO: EXPLORAR LAS LEYENDAS PARA SABER LOS CAMPOS QUE VAMOS
102 105
	        // A NECESITAR RECUPERAR, PARA INCLUIR EN LA CONSULTA SOLO
......
113 116
	        {
114 117
	            l = (VectorialLegend) lyr.getLegend();
115 118
	        }
116
	        
119

  
117 120
	        Rectangle2D rectAux = viewPort.getAdjustedExtent();
118 121
	        if (ct != null) {
119 122
	            ICoordTrans invertedCT = ct.getInverted();
120
	            rectAux = invertedCT.convert(rectAux);            
123
	            rectAux = invertedCT.convert(rectAux);
121 124
	        }
122
	
123
	        
124
	        usedFields = l.getUsedFields();
125
	
126
	        
125

  
126

  
127
	        if (!isJoined){
128
	        	usedFields = l.getUsedFields();
129
	        }
130

  
131

  
127 132
	        IFeatureIterator geomIt = dbAdapter.getFeatureIterator(rectAux, strEPSG, usedFields);
128 133
	        if (geomIt == null)
129 134
	        {
130 135
	            // dbAdapter.stop();
131 136
	            return;
132 137
	        }
133
	        
134
	        
138

  
139

  
135 140
	        DriverAttributes attr = dbAdapter.getDriverAttributes();
136 141
	        boolean bMustClone = false;
137 142
	        if (attr != null)
138 143
	        {
139 144
	            if (attr.isLoadedInMemory())
140 145
	            {
141
	                bMustClone = attr.isLoadedInMemory();               
146
	                bMustClone = attr.isLoadedInMemory();
142 147
	            }
143 148
	        }
144
	
145
	        
149

  
150

  
146 151
	        int i;
147 152
	        ISymbol symbol;
148 153
	        SpatialCache cache = lyr.getSpatialCache();
......
159 164
	        		continue;
160 165
	        	}
161 166
	            IGeometry geom = feat.getGeometry();
162
	            
167

  
163 168
	            // System.out.println("PINTANDO FEATURE " + feat.getID());
164
	            
169

  
165 170
	            if (ct != null) {
166 171
	                if (bMustClone)
167 172
	                    geom = geom.cloneGeometry();
168 173
	                geom.reProject(ct);
169 174
	            }
170
	
175

  
171 176
	            i = dbAdapter.getRowIndexByFID(feat);
172
	            // System.out.println("Antes de pintar " + i);
173
	            // Value val = feat.getAttribute(0);                
174
	            symbol = l.getSymbolByFeature(feat);
175
	            // symbol = l.getSymbol(i);
177

  
178
	            if (isJoined){
179
	            	symbol = l.getSymbol(i);
180
	            } else {
181
	            	symbol = l.getSymbolByFeature(feat);
182
	            }
183

  
176 184
	            if (symbol == null) continue;
177 185
	            if (bitSet.get(i)) {
178 186
	                symbol = symbol.getSymbolForSelection();
179
	            } 
180
	
187
	            }
188

  
181 189
				if (lyr.isSpatialCacheEnabled()) {
182 190
					if (cache.getMaxFeatures() >= cache.size()) {
183 191
						// Ya reproyectado todo
......
187 195

  
188 196
	            // symbol = l.getDefaultSymbol();
189 197
	            geom.drawInts(g,viewPort, symbol);
190
	            
191
	        } 
198

  
199
	        }
192 200
	        dbAdapter.stop();
193 201
		} catch (DriverIOException e) {
194 202
			throw new DriverException(e);
195 203
		}
196
        
204

  
197 205
    }
198 206
    /**
199 207
     * Processes features of layer whose geometries would
200 208
     * intersect rectangle passed as param by calling visitor's
201 209
     * visit method.
202
     * 
210
     *
203 211
     * FIXME FeatureVisitor is designed to work with memory and
204
     * file drivers (visit(IGeometry, index), and to work with 
212
     * file drivers (visit(IGeometry, index), and to work with
205 213
     * geometries (thats the reason for not to create Values, instead
206 214
     * of pass an index)
207
     * 
215
     *
208 216
     * But DBDrivers recovers IGeometry and Values in dbAdapter.getFeatureIterator
209 217
     * method. We must add a visit(Feature) method to FeatureVisitor.
210
     * 
211
     * 
218
     *
219
     *
212 220
     */
213
    public void process(FeatureVisitor visitor, Rectangle2D rect, CancellableMonitorable cancel) 
221
    public void process(FeatureVisitor visitor, Rectangle2D rect, CancellableMonitorable cancel)
214 222
    					throws DriverException, VisitException{
215 223
    	 FLyrVect lyr = (FLyrVect) getCapa();
216 224
         ISpatialDB dbAdapter = (ISpatialDB) ((SingleLayer) capa).getSource();
......
218 226
         try {
219 227
 			dbAdapter.start();
220 228
 			ICoordTrans ct = lyr.getCoordTrans();
221
 			String strEPSG = lyr.getProjection().getAbrev().substring(5);                
229
 			String strEPSG = lyr.getProjection().getAbrev().substring(5);
222 230
 	        Rectangle2D rectAux = rect;
223 231
 	        if (ct != null) {
224 232
 	            ICoordTrans invertedCT = ct.getInverted();
225
 	            rectAux = invertedCT.convert(rectAux);            
233
 	            rectAux = invertedCT.convert(rectAux);
226 234
 	        }
227 235
 	        IFeatureIterator geomIt = dbAdapter.getFeatureIterator(rectAux, strEPSG, null);
228 236
 	        if (geomIt == null){
......
234 242
 	        {
235 243
 	            if (attr.isLoadedInMemory())
236 244
 	            {
237
 	                bMustClone = attr.isLoadedInMemory();               
245
 	                bMustClone = attr.isLoadedInMemory();
238 246
 	            }//if
239 247
 	        }//if
240 248
 	        int i;
......
274 282
        try {
275 283
			dbAdapter.start();
276 284
			ICoordTrans ct = lyr.getCoordTrans();
277
			String strEPSG = lyr.getProjection().getAbrev().substring(5);                
285
			String strEPSG = lyr.getProjection().getAbrev().substring(5);
278 286
	        Rectangle2D rectAux = rect;
279 287
	        if (ct != null) {
280 288
	            ICoordTrans invertedCT = ct.getInverted();
281
	            rectAux = invertedCT.convert(rectAux);            
289
	            rectAux = invertedCT.convert(rectAux);
282 290
	        }
283
	
291

  
284 292
	        FBitSet selection = new FBitSet();
285
	        
293

  
286 294
	        IFeatureIterator geomIt = dbAdapter.getFeatureIterator(rectAux, strEPSG, null);
287 295
	        if (geomIt == null)
288 296
	        {
289 297
	            return selection;
290 298
	        }
291
	        
292
	        
299

  
300

  
293 301
	        DriverAttributes attr = dbAdapter.getDriverAttributes();
294 302
	        boolean bMustClone = false;
295 303
	        if (attr != null)
296 304
	        {
297 305
	            if (attr.isLoadedInMemory())
298 306
	            {
299
	                bMustClone = attr.isLoadedInMemory();               
307
	                bMustClone = attr.isLoadedInMemory();
300 308
	            }
301 309
	        }
302
	
303
	        
310

  
311

  
304 312
	        int i;
305
	        
313

  
306 314
	        while (geomIt.hasNext())
307 315
	        {
308 316
	        	if(cancel != null)
309
	        	{	
317
	        	{
310 318
	        		cancel.reportStep();
311 319
	        		if(cancel.isCanceled())
312 320
	        		{
313 321
	        			dbAdapter.stop();
314 322
	        			return selection;
315
	        		}	        		
323
	        		}
316 324
	        	}
317 325
	        	IFeature feat = geomIt.next();
318 326
	            IGeometry geom = feat.getGeometry();
319
	            
327

  
320 328
	            if (ct != null) {
321 329
	                if (bMustClone)
322 330
	                    geom = geom.cloneGeometry();
323 331
	                geom.reProject(ct);
324 332
	            }
325
	
333

  
326 334
	            i = dbDriver.getRowIndexByFID(feat);
327 335
	            if (geom.intersects(rect))
328 336
	            	selection.set(i, true);
329 337
	        }
330 338
	        dbAdapter.stop();
331
	        
339

  
332 340
	        return selection;
333 341
		} catch (DriverIOException e) {
334 342
			throw new DriverException(e);
335 343
		}
336 344

  
337 345
	}
338
    
339 346

  
347

  
340 348
}

Also available in: Unified diff