Revision 2979

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/operations/strategies/DefaultStrategy.java
74 74
 * mayor parte de las estrategias
75 75
 */
76 76
public class DefaultStrategy implements Strategy {
77
    public static final int EQUALS = 0;
78
    public static final int DISJOINT = 1;
79
    public static final int INTERSECTS = 2;
80
    public static final int TOUCHES = 3;
81
    public static final int CROSSES = 4;
82
    public static final int WITHIN = 5;
83
    public static final int CONTAINS = 6;
84
    public static final int OVERLAPS = 7;
85
    
77 86
	private static Logger logger = Logger.getLogger(DefaultStrategy.class.getName());
78 87
	FLayer capa = null;
79 88

  
......
316 325
	 */
317 326
	public FBitSet queryByPoint(Point2D p, double tolerance)
318 327
		throws DriverException {
319
		QueryByPointVisitor visitor = new QueryByPointVisitor();
320
		visitor.setLayer(capa);
321
		visitor.setTolerance(tolerance);
322
		visitor.setQueriedPoint(p);
323

  
324
		try {
325
			process(visitor);
326
		} catch (VisitException e) {
327
			throw new RuntimeException(
328
				"QueryByPointVisitor lanza una VisitException?");
329
		}
330

  
331
		return visitor.getBitSet();
328
        // TODO: OJO!!!!. Est? implementado como un rectangulo.
329
        // Lo correcto deber?a ser calculando las distancias reales
330
        // es decir, con un c?rculo.
331
        Rectangle2D recPoint = new Rectangle2D.Double(p.getX() - (tolerance / 2),
332
                p.getY() - (tolerance / 2), tolerance, tolerance);
333
		return queryByRect(recPoint);
332 334
	}
333 335

  
334 336
	/* (non-Javadoc)
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/operations/strategies/ShpStrategy.java
46 46
import java.awt.image.BufferedImage;
47 47
import java.io.IOException;
48 48
import java.util.BitSet;
49
import java.util.List;
49 50

  
50 51
import org.apache.log4j.Logger;
51 52
import org.cresques.cts.ICoordTrans;
......
53 54

  
54 55
import com.iver.cit.gvsig.fmap.DriverException;
55 56
import com.iver.cit.gvsig.fmap.ViewPort;
56
import com.iver.cit.gvsig.fmap.core.FPolygon2D;
57 57
import com.iver.cit.gvsig.fmap.core.FShape;
58
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
59 58
import com.iver.cit.gvsig.fmap.core.IGeometry;
60
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
61
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
62 59
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
63 60
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes;
64 61
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes;
65 62
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
66 63
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver;
64
import com.iver.cit.gvsig.fmap.layers.FBitSet;
67 65
import com.iver.cit.gvsig.fmap.layers.FLayer;
66
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
68 67
import com.iver.cit.gvsig.fmap.layers.VectorialAdapter;
69 68
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
70 69
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
......
74 73
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo;
75 74
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
76 75
import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D;
76
import com.vividsolutions.jts.geom.Coordinate;
77
import com.vividsolutions.jts.geom.Envelope;
78
import com.vividsolutions.jts.geom.Geometry;
79
import com.vividsolutions.jts.geom.IntersectionMatrix;
77 80

  
78 81

  
79 82
/**
......
261 264
		throws DriverException {
262 265
		super.draw(null, g, viewPort, cancel); // Quiero ejecutar el draw del padre, que es el que va sin acelaraci?n!!
263 266
	}
267
    
268
    /* (non-Javadoc)
269
     * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.core.IGeometry, int)
270
     */
271
    public FBitSet queryByShape(IGeometry g, int relationship)
272
    throws DriverException, VisitException {
273
        // Si hay un ?ndice espacial, lo usamos para hacer el query.
274
        FLyrVect lyr = (FLyrVect) capa;
275
        if (lyr.getSpatialIndex() == null)
276
            return super.queryByShape(g, relationship);
277

  
278
        VectorialAdapter va = lyr.getSource();
279
        ICoordTrans ct = lyr.getCoordTrans();
280
        Rectangle2D bounds = g.getBounds2D();
281
        Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY());
282
        Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY());
283
        Envelope env = new Envelope(c1, c2);
284
        
285
        List lstRecs = lyr.getSpatialIndex().query(env);
286
        Integer idRec;
287
        FBitSet bitset = new FBitSet();
288
        Geometry jtsShape = g.toJTSGeometry();
289
        IntersectionMatrix m;
290
        int index;
291
        try {
292
            va.start();
293

  
294
            for (int i=0; i < lstRecs.size(); i++)
295
            {
296
                idRec = (Integer) lstRecs.get(i);
297
                index = idRec.intValue();
298
                IGeometry geom = va.getShape(index);
299
                if (ct != null) {
300
                    geom.reProject(ct);
301
                }                
302
                Geometry jtsGeom = geom.toJTSGeometry();
303
                switch (relationship) {
304
                case CONTAINS:
305
                    m = jtsShape.relate(jtsGeom);
306
                    if (m.isContains()) {
307
                        bitset.set(index, true);
308
                    }
309
                    break;
310

  
311
                case CROSSES:
312
                    m = jtsShape.relate(jtsGeom);
313
                    if (m.isCrosses(jtsGeom.getDimension(), jtsShape.getDimension())) {
314
                        bitset.set(index, true);
315
                    }
316
                    break;
317

  
318
                case DISJOINT:
319
                    m = jtsShape.relate(jtsGeom);            
320
                    if (m.isDisjoint()) {
321
                        bitset.set(index, true);
322
                    }
323
                    break;
324

  
325
                case EQUALS:
326
                    m = jtsShape.relate(jtsGeom); 
327
                    if (m.isEquals(jtsGeom.getDimension(), jtsShape.getDimension())) {
328
                        bitset.set(index, true);
329
                    }
330
                    break;
331

  
332
                case INTERSECTS:
333
                    m = jtsShape.relate(jtsGeom);
334
                    if (m.isIntersects()) {
335
                        bitset.set(index, true);
336
                    }
337
                    break;
338

  
339
                case OVERLAPS:
340
                    m = jtsShape.relate(jtsGeom);
341
                    if (m.isOverlaps(jtsGeom.getDimension(), jtsShape.getDimension()))
342
                    {
343
                        bitset.set(index, true);
344
                    }
345

  
346
                    break;
347

  
348
                case TOUCHES:
349
                    m = jtsShape.relate(jtsGeom);
350
                    if (m.isTouches(jtsGeom.getDimension(), jtsShape.getDimension()))
351
                    {
352
                        bitset.set(index, true);
353
                    }
354

  
355
                    break;
356

  
357
                case WITHIN:
358
                    m = jtsShape.relate(jtsGeom);
359
                    if (m.isWithin()) {
360
                        bitset.set(index, true);
361
                    }
362

  
363
                    break;
364
                }
365
            }
366
            va.stop();
367
        } catch (DriverIOException e) {
368
            // TODO Auto-generated catch block
369
            e.printStackTrace();
370
        }
371
        return bitset;
372
    }
373
    public FBitSet queryByRect(Rectangle2D rect) throws DriverException {
374
        // Si hay un ?ndice espacial, lo usamos para hacer el query.
375
        FLyrVect lyr = (FLyrVect) capa;
376
        if (lyr.getSpatialIndex() == null)
377
            return super.queryByRect(rect);
378

  
379
        VectorialAdapter va = lyr.getSource();
380
        ICoordTrans ct = lyr.getCoordTrans();
381
        Rectangle2D bounds = rect;
382
        Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY());
383
        Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY());
384
        Envelope env = new Envelope(c1, c2);
385
        
386
        List lstRecs = lyr.getSpatialIndex().query(env);
387
        Integer idRec;
388
        FBitSet bitset = new FBitSet();
389
        int index;
390
        try {
391
            va.start();
392

  
393
            for (int i=0; i < lstRecs.size(); i++)
394
            {
395
                idRec = (Integer) lstRecs.get(i);
396
                index = idRec.intValue();
397
                IGeometry geom = va.getShape(index);
398
                if (ct != null) {
399
                    geom.reProject(ct);
400
                }
401
                if (geom.intersects(rect))
402
                    bitset.set(index, true);
403
            }
404
            va.stop();
405
        } catch (DriverIOException e) {
406
            // TODO Auto-generated catch block
407
            e.printStackTrace();
408
        }
409
        return bitset;
410

  
411
    }
412
    
413
    /* (non-Javadoc)
414
     * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(java.awt.geom.Point2D, double)
415
     */
416
    public FBitSet queryByPoint(Point2D p, double tolerance)
417
    throws DriverException {
418
        // TODO: OJO!!!!. Est? implementado como un rectangulo.
419
        // Lo correcto deber?a ser calculando las distancias reales
420
        // es decir, con un c?rculo.
421
        Rectangle2D recPoint = new Rectangle2D.Double(p.getX() - (tolerance / 2),
422
                p.getY() - (tolerance / 2), tolerance, tolerance);
423
        return queryByRect(recPoint);
424
    }
264 425
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/layers/layerOperations/RandomVectorialData.java
41 41
package com.iver.cit.gvsig.fmap.layers.layerOperations;
42 42

  
43 43
import com.iver.cit.gvsig.fmap.DriverException;
44
import com.iver.cit.gvsig.fmap.layers.FBitSet;
44 45

  
45 46
import java.awt.geom.Rectangle2D;
46 47

  
47
import java.util.BitSet;
48 48

  
49 49

  
50 50
/**
......
55 55
	/**
56 56
	 * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#createIndex()
57 57
	 */
58
	void createIndex();
58
	void createSpatialIndex();
59 59

  
60 60
	/**
61 61
	 * Devuelve un BitSet con los ?ndices de los shapes que estan dentro del
......
69 69
	 *
70 70
	 * @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByRect(java.awt.geom.Rectangle2D)
71 71
	 */
72
	BitSet queryByRect(Rectangle2D rect) throws DriverException;
72
	FBitSet queryByRect(Rectangle2D rect) throws DriverException;
73 73
}

Also available in: Unified diff