root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / operations / strategies / QueryByPointVisitor.java @ 10627
History | View | Annotate | Download (3.57 KB)
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.geom.Point2D; |
44 |
import java.awt.geom.Rectangle2D; |
45 |
|
46 |
import com.iver.cit.gvsig.exceptions.visitors.ProcessVisitorException; |
47 |
import com.iver.cit.gvsig.exceptions.visitors.StartVisitorException; |
48 |
import com.iver.cit.gvsig.exceptions.visitors.VisitorException; |
49 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
50 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
51 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
52 |
|
53 |
|
54 |
/**
|
55 |
* Query by point Visitor.
|
56 |
*
|
57 |
* @author Vicente Caballero Navarro
|
58 |
*/
|
59 |
public class QueryByPointVisitor implements FeatureVisitor { |
60 |
private Point2D point = null; |
61 |
private double tolerance; |
62 |
private FLayer layer = null; |
63 |
private FBitSet bitset = null; |
64 |
private Rectangle2D recPoint = null; |
65 |
// private ICoordTrans ct = null;
|
66 |
|
67 |
/**
|
68 |
* Devuelve un FBitSet con los ?ndices de los registros de la consulta.
|
69 |
*
|
70 |
* @return FBitSet con los ?ndices de la consulta.
|
71 |
*/
|
72 |
public FBitSet getBitSet() {
|
73 |
return bitset;
|
74 |
} |
75 |
|
76 |
/**
|
77 |
* DOCUMENT ME!
|
78 |
*
|
79 |
* @param layer DOCUMENT ME!
|
80 |
*/
|
81 |
public void setLayer(FLayer layer) { |
82 |
this.layer = layer;
|
83 |
// this.ct = layer.getCoordTrans();
|
84 |
} |
85 |
|
86 |
/**
|
87 |
* Inserta la tolerancia que se aplica en la selecci?n.
|
88 |
*
|
89 |
* @param t tolerancia.
|
90 |
*/
|
91 |
public void setTolerance(double t) { |
92 |
tolerance = t; |
93 |
} |
94 |
|
95 |
/**
|
96 |
* Inserta el punto de consulta.
|
97 |
*
|
98 |
* @param p punto de consulta.
|
99 |
*/
|
100 |
public void setQueriedPoint(Point2D p) { |
101 |
point = p; |
102 |
} |
103 |
|
104 |
/**
|
105 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor#visit(com.iver.cit.gvsig.fmap.core.IGeometry,
|
106 |
* int)
|
107 |
*/
|
108 |
public void visit(IGeometry g, int index) throws VisitorException, ProcessVisitorException { |
109 |
if (g==null)return; |
110 |
/* if (ct != null) {
|
111 |
g.reProject(ct);
|
112 |
} */
|
113 |
|
114 |
if (g.intersects(recPoint)) {
|
115 |
bitset.set(index, true);
|
116 |
} else {
|
117 |
bitset.set(index, false);
|
118 |
} |
119 |
} |
120 |
|
121 |
/**
|
122 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor#stop()
|
123 |
*/
|
124 |
public void stop(FLayer layer) throws VisitorException { |
125 |
} |
126 |
|
127 |
/**
|
128 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor#start()
|
129 |
*/
|
130 |
public boolean start(FLayer layer) throws StartVisitorException { |
131 |
bitset = new FBitSet();
|
132 |
recPoint = new Rectangle2D.Double(point.getX() - (tolerance / 2), |
133 |
point.getY() - (tolerance / 2), tolerance, tolerance);
|
134 |
|
135 |
return true; |
136 |
} |
137 |
|
138 |
public String getProcessDescription() { |
139 |
return "Selecting geometries that intersects a point"; |
140 |
} |
141 |
} |