Revision 11613 branches/v10/extensions/extAnnotations/src/com/iver/cit/gvsig/fmap/operation/strategies/Annotation_Strategy.java
Annotation_Strategy.java | ||
---|---|---|
9 | 9 |
import java.awt.image.BufferedImage; |
10 | 10 |
import java.util.List; |
11 | 11 |
|
12 |
import javax.print.attribute.PrintRequestAttributeSet; |
|
13 |
|
|
12 | 14 |
import org.cresques.cts.ICoordTrans; |
13 | 15 |
|
14 | 16 |
import com.hardcode.driverManager.DriverLoadException; |
... | ... | |
21 | 23 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
22 | 24 |
import com.iver.cit.gvsig.fmap.core.FShape; |
23 | 25 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
24 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
|
25 | 26 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
26 | 27 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
27 | 28 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
... | ... | |
42 | 43 |
import com.vividsolutions.jts.geom.Geometry; |
43 | 44 |
import com.vividsolutions.jts.geom.IntersectionMatrix; |
44 | 45 |
|
45 |
|
|
46 | 46 |
/** |
47 | 47 |
* Esta clase se encargar? de dibujar de la forma m?s eficiente los temas de |
48 | 48 |
* anotaciones. |
49 |
* |
|
49 |
*
|
|
50 | 50 |
* @author Vicente Caballero Navarro |
51 | 51 |
*/ |
52 | 52 |
public class Annotation_Strategy extends DefaultStrategy { |
53 |
private FSymbol symbolPoint=new FSymbol(FShape.POINT,Color.black); |
|
53 |
private FSymbol symbolPoint = new FSymbol(FShape.POINT, Color.black); |
|
54 |
|
|
54 | 55 |
private Annotation_Layer capa; |
56 |
|
|
55 | 57 |
/** |
56 |
* Crea un nuevo AnotationStrategy. |
|
57 |
* |
|
58 |
* @param layer |
|
59 |
*/ |
|
60 |
public Annotation_Strategy(FLayer layer) { |
|
61 |
super(layer); |
|
62 |
capa = (Annotation_Layer)getCapa(); |
|
63 |
symbolPoint.setSize(5); |
|
64 |
} |
|
65 |
// /** |
|
66 |
// * @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage, |
|
67 |
// * java.awt.Graphics2D, ISymbol) |
|
68 |
// */ |
|
69 |
// public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
70 |
// Cancellable cancel) throws DriverException { |
|
71 |
// Annotation_Legend l = (Annotation_Legend) capa.getLegend(); |
|
72 |
// FSymbol sym = (FSymbol) l.getDefaultSymbol(); |
|
73 |
// |
|
74 |
// Rectangle2D elExtent = viewPort.getAdjustedExtent(); |
|
75 |
// List lstIndexes=null; |
|
76 |
// |
|
77 |
// try { |
|
78 |
// int sc; |
|
79 |
// ReadableVectorial source = capa.getSource(); |
|
80 |
// sc=source.getShapeCount(); |
|
81 |
// |
|
82 |
// SelectableDataSource recordSet = source.getRecordset(); |
|
83 |
// FBitSet bitSet=recordSet.getSelection(); |
|
84 |
// // If area of needed extent is less than fullExtent / 4, |
|
85 |
// // it will be worthy to use SpatialIndex. |
|
86 |
// // Otherwhise, we will not use it. |
|
87 |
// boolean bUseSpatialIndex = false; |
|
88 |
// if(capa.getISpatialIndex() != null) |
|
89 |
// { |
|
90 |
// if(isSpatialIndexNecessary(elExtent)){ |
|
91 |
// lstIndexes = capa.getISpatialIndex().query(elExtent); |
|
92 |
// sc = lstIndexes.size(); |
|
93 |
// System.out.println("LISTA DEL SPATIALINDEX.SIZE = " + sc); |
|
94 |
// bUseSpatialIndex = true; |
|
95 |
// }//if |
|
96 |
// }//if |
|
97 |
// FontMetrics metrics = g.getFontMetrics(); |
|
98 |
// Annotation_Mapping mapping = ((Annotation_Layer) capa) |
|
99 |
// .getMapping(); |
|
100 |
// int idHeightField = mapping.getColumnHeight(); |
|
101 |
// int idFontName = mapping.getColumnTypeFont(); |
|
102 |
// int idFontStyle = mapping.getColumnStyleFont(); |
|
103 |
// int idRotationField = mapping.getColumnRotate(); |
|
104 |
// int idFontColor = mapping.getColumnColor(); |
|
105 |
// int idTextField = mapping.getColumnText(); |
|
106 |
// |
|
107 |
// double rotation = 0D; |
|
108 |
// double size = sym.getFont().getSize(); |
|
109 |
// sym.setFontSizeInPixels(((Annotation_Layer)capa).isInPixels()); |
|
110 |
// String fontName = "Dialog"; |
|
111 |
// int fontStyle = sym.getFont().getStyle(); |
|
112 |
// int fontColor = sym.getFontColor().getRGB(); |
|
113 |
// SpatialCache cache = capa.getSpatialCache(); |
|
114 |
// cache.clearAll(); |
|
115 |
// int numOriginal; |
|
116 |
// for (int numReg = 0; numReg < sc; numReg++) { |
|
117 |
// if (cancel.isCanceled()){ |
|
118 |
// break; |
|
119 |
// } |
|
120 |
// if (bUseSpatialIndex){ |
|
121 |
// Integer idRec = (Integer) lstIndexes.get(numReg); |
|
122 |
// numOriginal = idRec.intValue(); |
|
123 |
// }else{ |
|
124 |
// numOriginal = numReg; |
|
125 |
// } |
|
126 |
// Value[] vv = recordSet.getRow(numOriginal); |
|
127 |
// if (idHeightField != -1) { |
|
128 |
// // text size is defined in the table |
|
129 |
// try { |
|
130 |
// size = ((NumericValue) vv[idHeightField]).doubleValue() |
|
131 |
// * FConstant.FONT_HEIGHT_SCALE_FACTOR; |
|
132 |
// } catch (ClassCastException ccEx) { |
|
133 |
// if (!NullValue.class.equals(vv[idHeightField] |
|
134 |
// .getClass())) { |
|
135 |
// // throw new ReadDriverException("Unknown", ccEx); |
|
136 |
// } |
|
137 |
// // a null value |
|
138 |
// // Logger.getAnonymousLogger(). |
|
139 |
// // warning("Null text height value for text |
|
140 |
// // '"+vv[idTextField].toString()+"'"); |
|
141 |
// continue; |
|
142 |
// } |
|
143 |
// } else { |
|
144 |
// // otherwise will use the size in the symbol |
|
145 |
// |
|
146 |
// } |
|
147 |
// |
|
148 |
// // size = CartographicSupportToolkit. |
|
149 |
// // toScreenUnitYAxis(size, |
|
150 |
// // unit, |
|
151 |
// // viewPort |
|
152 |
// // ); |
|
153 |
// |
|
154 |
//// if (size <= 3) { |
|
155 |
//// // label is too small to be readable, will be skipped |
|
156 |
//// // this speeds up the rendering in wider zooms |
|
157 |
//// continue; |
|
158 |
//// } |
|
159 |
// |
|
160 |
// |
|
161 |
// if (idFontName != -1) { |
|
162 |
// fontName = ((StringValue) vv[idFontName]).toString(); |
|
163 |
// } |
|
164 |
// |
|
165 |
// |
|
166 |
// if (idFontStyle != -1) { |
|
167 |
// fontStyle = ((NumericValue) vv[idFontStyle]).intValue(); |
|
168 |
// } |
|
169 |
// |
|
170 |
// |
|
171 |
// |
|
172 |
// if (idRotationField != -1) { |
|
173 |
// // text rotation is defined in the table |
|
174 |
// rotation = ((NumericValue) vv[idRotationField]) |
|
175 |
// .doubleValue(); |
|
176 |
// } |
|
177 |
// |
|
178 |
// |
|
179 |
// if (idFontColor != -1) { |
|
180 |
// // text rotation is defined in the table |
|
181 |
// fontColor = ((NumericValue) vv[idFontColor]).intValue(); |
|
182 |
// sym.setFontColor(new Color(fontColor)); |
|
183 |
// } |
|
184 |
// |
|
185 |
// if (bitSet.get(numOriginal)){ |
|
186 |
// sym = (FSymbol)sym.getSymbolForSelection(); |
|
187 |
// } |
|
188 |
// IGeometry geom = source.getShape(numOriginal); |
|
189 |
// |
|
190 |
// sym.setFont(new Font(fontName, fontStyle, (int) size)); |
|
191 |
// |
|
192 |
// |
|
193 |
//// sym.setDescription(vv[idTextField].toString()); |
|
194 |
//// sym.setRotation((int) rotation); |
|
195 |
// FLabel[] aux = geom.createLabels(0, true); |
|
196 |
// aux[0].setHeight(size); |
|
197 |
// aux[0].setRotation((int) rotation); |
|
198 |
// aux[0].setString(vv[idTextField].toString()); |
|
199 |
// symbolPoint.draw((Graphics2D)g,viewPort.getAffineTransform(),new FPoint2D(viewPort.fromMapPoint(aux[0].getOrig()))); |
|
200 |
// FGraphicUtilities.DrawAnnotation(g, viewPort |
|
201 |
// .getAffineTransform(), sym, aux[0], metrics, false); |
|
202 |
// } |
|
203 |
// |
|
204 |
// // System.out.println("..................Fin del dibujado .............."); |
|
205 |
// } catch (DriverIOException e) { |
|
206 |
// e.printStackTrace(); |
|
207 |
// } catch (DriverException e) { |
|
208 |
// // TODO Auto-generated catch block |
|
209 |
// e.printStackTrace(); |
|
210 |
// } |
|
211 |
// heightDefault=-1; |
|
212 |
// } |
|
58 |
* Crea un nuevo AnotationStrategy. |
|
59 |
* |
|
60 |
* @param layer |
|
61 |
*/ |
|
62 |
public Annotation_Strategy(FLayer layer) { |
|
63 |
super(layer); |
|
64 |
capa = (Annotation_Layer) getCapa(); |
|
65 |
symbolPoint.setSize(5); |
|
66 |
} |
|
213 | 67 |
|
68 |
// /** |
|
69 |
// * @see |
|
70 |
// com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage, |
|
71 |
// * java.awt.Graphics2D, ISymbol) |
|
72 |
// */ |
|
73 |
// public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
74 |
// Cancellable cancel) throws DriverException { |
|
75 |
// Annotation_Legend l = (Annotation_Legend) capa.getLegend(); |
|
76 |
// FSymbol sym = (FSymbol) l.getDefaultSymbol(); |
|
77 |
// |
|
78 |
// Rectangle2D elExtent = viewPort.getAdjustedExtent(); |
|
79 |
// List lstIndexes=null; |
|
80 |
// |
|
81 |
// try { |
|
82 |
// int sc; |
|
83 |
// ReadableVectorial source = capa.getSource(); |
|
84 |
// sc=source.getShapeCount(); |
|
85 |
// |
|
86 |
// SelectableDataSource recordSet = source.getRecordset(); |
|
87 |
// FBitSet bitSet=recordSet.getSelection(); |
|
88 |
// // If area of needed extent is less than fullExtent / 4, |
|
89 |
// // it will be worthy to use SpatialIndex. |
|
90 |
// // Otherwhise, we will not use it. |
|
91 |
// boolean bUseSpatialIndex = false; |
|
92 |
// if(capa.getISpatialIndex() != null) |
|
93 |
// { |
|
94 |
// if(isSpatialIndexNecessary(elExtent)){ |
|
95 |
// lstIndexes = capa.getISpatialIndex().query(elExtent); |
|
96 |
// sc = lstIndexes.size(); |
|
97 |
// System.out.println("LISTA DEL SPATIALINDEX.SIZE = " + sc); |
|
98 |
// bUseSpatialIndex = true; |
|
99 |
// }//if |
|
100 |
// }//if |
|
101 |
// FontMetrics metrics = g.getFontMetrics(); |
|
102 |
// Annotation_Mapping mapping = ((Annotation_Layer) capa) |
|
103 |
// .getMapping(); |
|
104 |
// int idHeightField = mapping.getColumnHeight(); |
|
105 |
// int idFontName = mapping.getColumnTypeFont(); |
|
106 |
// int idFontStyle = mapping.getColumnStyleFont(); |
|
107 |
// int idRotationField = mapping.getColumnRotate(); |
|
108 |
// int idFontColor = mapping.getColumnColor(); |
|
109 |
// int idTextField = mapping.getColumnText(); |
|
110 |
// |
|
111 |
// double rotation = 0D; |
|
112 |
// double size = sym.getFont().getSize(); |
|
113 |
// sym.setFontSizeInPixels(((Annotation_Layer)capa).isInPixels()); |
|
114 |
// String fontName = "Dialog"; |
|
115 |
// int fontStyle = sym.getFont().getStyle(); |
|
116 |
// int fontColor = sym.getFontColor().getRGB(); |
|
117 |
// SpatialCache cache = capa.getSpatialCache(); |
|
118 |
// cache.clearAll(); |
|
119 |
// int numOriginal; |
|
120 |
// for (int numReg = 0; numReg < sc; numReg++) { |
|
121 |
// if (cancel.isCanceled()){ |
|
122 |
// break; |
|
123 |
// } |
|
124 |
// if (bUseSpatialIndex){ |
|
125 |
// Integer idRec = (Integer) lstIndexes.get(numReg); |
|
126 |
// numOriginal = idRec.intValue(); |
|
127 |
// }else{ |
|
128 |
// numOriginal = numReg; |
|
129 |
// } |
|
130 |
// Value[] vv = recordSet.getRow(numOriginal); |
|
131 |
// if (idHeightField != -1) { |
|
132 |
// // text size is defined in the table |
|
133 |
// try { |
|
134 |
// size = ((NumericValue) vv[idHeightField]).doubleValue() |
|
135 |
// * FConstant.FONT_HEIGHT_SCALE_FACTOR; |
|
136 |
// } catch (ClassCastException ccEx) { |
|
137 |
// if (!NullValue.class.equals(vv[idHeightField] |
|
138 |
// .getClass())) { |
|
139 |
// // throw new ReadDriverException("Unknown", ccEx); |
|
140 |
// } |
|
141 |
// // a null value |
|
142 |
// // Logger.getAnonymousLogger(). |
|
143 |
// // warning("Null text height value for text |
|
144 |
// // '"+vv[idTextField].toString()+"'"); |
|
145 |
// continue; |
|
146 |
// } |
|
147 |
// } else { |
|
148 |
// // otherwise will use the size in the symbol |
|
149 |
// |
|
150 |
// } |
|
151 |
// |
|
152 |
// // size = CartographicSupportToolkit. |
|
153 |
// // toScreenUnitYAxis(size, |
|
154 |
// // unit, |
|
155 |
// // viewPort |
|
156 |
// // ); |
|
157 |
// |
|
158 |
// // if (size <= 3) { |
|
159 |
// // // label is too small to be readable, will be skipped |
|
160 |
// // // this speeds up the rendering in wider zooms |
|
161 |
// // continue; |
|
162 |
// // } |
|
163 |
// |
|
164 |
// |
|
165 |
// if (idFontName != -1) { |
|
166 |
// fontName = ((StringValue) vv[idFontName]).toString(); |
|
167 |
// } |
|
168 |
// |
|
169 |
// |
|
170 |
// if (idFontStyle != -1) { |
|
171 |
// fontStyle = ((NumericValue) vv[idFontStyle]).intValue(); |
|
172 |
// } |
|
173 |
// |
|
174 |
// |
|
175 |
// |
|
176 |
// if (idRotationField != -1) { |
|
177 |
// // text rotation is defined in the table |
|
178 |
// rotation = ((NumericValue) vv[idRotationField]) |
|
179 |
// .doubleValue(); |
|
180 |
// } |
|
181 |
// |
|
182 |
// |
|
183 |
// if (idFontColor != -1) { |
|
184 |
// // text rotation is defined in the table |
|
185 |
// fontColor = ((NumericValue) vv[idFontColor]).intValue(); |
|
186 |
// sym.setFontColor(new Color(fontColor)); |
|
187 |
// } |
|
188 |
// |
|
189 |
// if (bitSet.get(numOriginal)){ |
|
190 |
// sym = (FSymbol)sym.getSymbolForSelection(); |
|
191 |
// } |
|
192 |
// IGeometry geom = source.getShape(numOriginal); |
|
193 |
// |
|
194 |
// sym.setFont(new Font(fontName, fontStyle, (int) size)); |
|
195 |
// |
|
196 |
// |
|
197 |
// // sym.setDescription(vv[idTextField].toString()); |
|
198 |
// // sym.setRotation((int) rotation); |
|
199 |
// FLabel[] aux = geom.createLabels(0, true); |
|
200 |
// aux[0].setHeight(size); |
|
201 |
// aux[0].setRotation((int) rotation); |
|
202 |
// aux[0].setString(vv[idTextField].toString()); |
|
203 |
// symbolPoint.draw((Graphics2D)g,viewPort.getAffineTransform(),new |
|
204 |
// FPoint2D(viewPort.fromMapPoint(aux[0].getOrig()))); |
|
205 |
// FGraphicUtilities.DrawAnnotation(g, viewPort |
|
206 |
// .getAffineTransform(), sym, aux[0], metrics, false); |
|
207 |
// } |
|
208 |
// |
|
209 |
// // System.out.println("..................Fin del dibujado |
|
210 |
// .............."); |
|
211 |
// } catch (DriverIOException e) { |
|
212 |
// e.printStackTrace(); |
|
213 |
// } catch (DriverException e) { |
|
214 |
// // TODO Auto-generated catch block |
|
215 |
// e.printStackTrace(); |
|
216 |
// } |
|
217 |
// heightDefault=-1; |
|
218 |
// } |
|
214 | 219 |
|
215 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
|
|
220 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort,
|
|
216 | 221 |
Cancellable cancel) { |
217 | 222 |
// Copia draw AttrInTableLabeling |
218 | 223 |
Annotation_Legend l = (Annotation_Legend) capa.getLegend(); |
... | ... | |
222 | 227 |
// limit the labeling to the visible extent |
223 | 228 |
FBitSet bs = capa.queryByRect(viewPort.getAdjustedExtent()); |
224 | 229 |
|
225 |
|
|
226 | 230 |
SelectableDataSource recordSet = source.getRecordset(); |
227 |
FBitSet bitSet=recordSet.getSelection();
|
|
231 |
FBitSet bitSet = recordSet.getSelection();
|
|
228 | 232 |
FontMetrics metrics = g.getFontMetrics(); |
229 | 233 |
Annotation_Mapping mapping = ((Annotation_Layer) capa) |
230 |
.getAnnotatonMapping(); |
|
234 |
.getAnnotatonMapping();
|
|
231 | 235 |
int idHeightField = mapping.getColumnHeight(); |
232 | 236 |
int idFontName = mapping.getColumnTypeFont(); |
233 | 237 |
int idFontStyle = mapping.getColumnStyleFont(); |
... | ... | |
237 | 241 |
|
238 | 242 |
double rotation = 0D; |
239 | 243 |
double size = sym.getFont().getSize(); |
240 |
sym.setFontSizeInPixels(((Annotation_Layer)capa).isInPixels()); |
|
244 |
sym.setFontSizeInPixels(((Annotation_Layer) capa).isInPixels());
|
|
241 | 245 |
String fontName = "Dialog"; |
242 | 246 |
int fontStyle = sym.getFont().getStyle(); |
243 | 247 |
int fontColor = sym.getFontColor().getRGB(); |
244 | 248 |
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { |
245 |
if (cancel.isCanceled()){ |
|
249 |
if (cancel.isCanceled()) {
|
|
246 | 250 |
break; |
247 | 251 |
} |
248 | 252 |
Value[] vv = recordSet.getRow(i); |
... | ... | |
273 | 277 |
// viewPort |
274 | 278 |
// ); |
275 | 279 |
|
276 |
// if (size <= 3) {
|
|
277 |
// // label is too small to be readable, will be skipped
|
|
278 |
// // this speeds up the rendering in wider zooms
|
|
279 |
// continue;
|
|
280 |
// }
|
|
280 |
// if (size <= 3) {
|
|
281 |
// // label is too small to be readable, will be skipped
|
|
282 |
// // this speeds up the rendering in wider zooms
|
|
283 |
// continue;
|
|
284 |
// }
|
|
281 | 285 |
|
282 |
|
|
283 | 286 |
if (idFontName != -1) { |
284 | 287 |
fontName = ((StringValue) vv[idFontName]).toString(); |
285 | 288 |
} |
286 | 289 |
|
287 |
|
|
288 | 290 |
if (idFontStyle != -1) { |
289 | 291 |
fontStyle = ((NumericValue) vv[idFontStyle]).intValue(); |
290 | 292 |
} |
291 | 293 |
|
292 |
|
|
293 |
|
|
294 | 294 |
if (idRotationField != -1) { |
295 | 295 |
// text rotation is defined in the table |
296 | 296 |
rotation = ((NumericValue) vv[idRotationField]) |
297 | 297 |
.doubleValue(); |
298 | 298 |
} |
299 | 299 |
|
300 |
|
|
301 | 300 |
if (idFontColor != -1) { |
302 | 301 |
// text rotation is defined in the table |
303 | 302 |
fontColor = ((NumericValue) vv[idFontColor]).intValue(); |
304 | 303 |
sym.setFontColor(new Color(fontColor)); |
305 | 304 |
} |
306 | 305 |
|
307 |
if (bitSet.get(i)){ |
|
308 |
sym = (FSymbol)sym.getSymbolForSelection(); |
|
306 |
if (bitSet.get(i)) {
|
|
307 |
sym = (FSymbol) sym.getSymbolForSelection();
|
|
309 | 308 |
} |
310 | 309 |
IGeometry geom = source.getShape(i); |
311 | 310 |
|
312 | 311 |
sym.setFont(new Font(fontName, fontStyle, (int) size)); |
313 | 312 |
|
314 |
|
|
315 |
// sym.setDescription(vv[idTextField].toString()); |
|
316 |
// sym.setRotation((int) rotation); |
|
313 |
// sym.setDescription(vv[idTextField].toString()); |
|
314 |
// sym.setRotation((int) rotation); |
|
317 | 315 |
FLabel[] aux = geom.createLabels(0, true); |
318 | 316 |
aux[0].setHeight(size); |
319 | 317 |
aux[0].setRotation((int) rotation); |
320 | 318 |
aux[0].setString(vv[idTextField].toString()); |
321 |
if (sym.isShapeVisible()){ |
|
322 |
symbolPoint.draw((Graphics2D)g,viewPort.getAffineTransform(),new FPoint2D(viewPort.fromMapPoint(aux[0].getOrig()))); |
|
319 |
if (sym.isShapeVisible()) { |
|
320 |
symbolPoint.draw((Graphics2D) g, viewPort |
|
321 |
.getAffineTransform(), new FPoint2D(viewPort |
|
322 |
.fromMapPoint(aux[0].getOrig()))); |
|
323 | 323 |
} |
324 | 324 |
FGraphicUtilities.DrawAnnotation(g, viewPort |
325 | 325 |
.getAffineTransform(), sym, aux[0], metrics, false); |
... | ... | |
334 | 334 |
// } |
335 | 335 |
} |
336 | 336 |
|
337 |
// /** |
|
338 |
// * @see |
|
339 |
// com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage, |
|
340 |
// * java.awt.Graphics2D, ISymbol) |
|
341 |
// */ |
|
342 |
// public void print(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
343 |
// Cancellable cancel) throws DriverException { |
|
344 |
// |
|
345 |
// // Rectangle2D elExtent = viewPort.getAdjustedExtent(); |
|
346 |
// // graphics=g; |
|
347 |
// // Annotation_Layer lyrAnnotation=(Annotation_Layer)capa; |
|
348 |
// // List lstIndexes=null; |
|
349 |
// // |
|
350 |
// // VectorialLegend l=(VectorialLegend)lyrAnnotation.getLegend(); |
|
351 |
// // FBitSet bitSet=lyrAnnotation.getRecordset().getSelection(); |
|
352 |
// // |
|
353 |
// // boolean inPixels=lyrAnnotation.isInPixels(); |
|
354 |
// // FSymbol theSymbol = (FSymbol) l.getDefaultSymbol(); |
|
355 |
// // theSymbol.setFontSizeInPixels(inPixels); |
|
356 |
// // this.viewPort=viewPort;//capa.getFMap().getViewPort(); |
|
357 |
// // AffineTransform at=viewPort.getAffineTransform(); |
|
358 |
// // try { |
|
359 |
// // int sc; |
|
360 |
// // sc=lyrAnnotation.getSource().getShapeCount(); |
|
361 |
// // // If area of needed extent is less than fullExtent / 4, |
|
362 |
// // // it will be worthy to use SpatialIndex. |
|
363 |
// // // Otherwhise, we will not use it. |
|
364 |
// // boolean bUseSpatialIndex = false; |
|
365 |
// // if(lyrAnnotation.getISpatialIndex() != null) |
|
366 |
// // { |
|
367 |
// // if(isSpatialIndexNecessary(elExtent)){ |
|
368 |
// // lstIndexes = lyrAnnotation.getISpatialIndex().query(elExtent); |
|
369 |
// // sc = lstIndexes.size(); |
|
370 |
// // bUseSpatialIndex = true; |
|
371 |
// // }//if |
|
372 |
// // }//if |
|
373 |
// // |
|
374 |
// // FontMetrics metrics = g.getFontMetrics(); |
|
375 |
// // //SpatialCache cache = lyrAnnotation.createSpatialCache(); |
|
376 |
// // int numOriginal; |
|
377 |
// // for (int numReg = 0; numReg < sc; numReg++) { |
|
378 |
// // if (cancel.isCanceled()){ |
|
379 |
// // break; |
|
380 |
// // } |
|
381 |
// // if (bUseSpatialIndex){ |
|
382 |
// // Integer idRec = (Integer) lstIndexes.get(numReg); |
|
383 |
// // numOriginal = idRec.intValue(); |
|
384 |
// // }else{ |
|
385 |
// // numOriginal = numReg; |
|
386 |
// // } |
|
387 |
// // /* if (lyrAnnotation.getSource() instanceof EditableAdapter) |
|
388 |
// // |
|
389 |
// numOriginal=((EditableAdapter)lyrAnnotation.getSource()).getCalculatedIndex(numOriginal);*/ |
|
390 |
// // |
|
391 |
// // FLabel theLabel = lyrAnnotation.getLabel(numOriginal); |
|
392 |
// // if ((theLabel == null) || (theLabel.getOrig() == null)) |
|
393 |
// // continue; |
|
394 |
// // |
|
395 |
// // |
|
396 |
// // Rectangle2D r=null; |
|
397 |
// // if (inPixels && lyrAnnotation.getMapping().getColumnHeight()==-1) { |
|
398 |
// // |
|
399 |
// r=getDefaultBoundBoxinPixels(metrics,theLabel.getOrig(),theLabel.getString()); |
|
400 |
// // }else { |
|
401 |
// // r=getBoundBox(theLabel.getOrig(),(float)theLabel.getHeight(), |
|
402 |
// theLabel.getJustification(),theLabel.getString()); |
|
403 |
// // } |
|
404 |
// // theLabel.setBoundBox(r); |
|
405 |
// // |
|
406 |
// // if (elExtent.intersects(r)) |
|
407 |
// // { |
|
408 |
// // FPoint2D p=new FPoint2D(viewPort.fromMapPoint(new |
|
409 |
// Point2D.Double(r.getX(),r.getY()))); |
|
410 |
// // FGraphicUtilities.DrawShape(g,at,p,symbolPoint); |
|
411 |
// // if (bitSet.get(numOriginal)) { |
|
412 |
// // FGraphicUtilities.DrawAnnotation(g, at, theSymbol, |
|
413 |
// theLabel,metrics,true); |
|
414 |
// // }else{ |
|
415 |
// // FGraphicUtilities.DrawAnnotation(g, at, theSymbol, |
|
416 |
// theLabel,metrics,false); |
|
417 |
// // } |
|
418 |
// // |
|
419 |
// // |
|
420 |
// // } // XIntersects |
|
421 |
// // |
|
422 |
// // |
|
423 |
// // } |
|
424 |
// // |
|
425 |
// // } catch (DriverIOException e) { |
|
426 |
// // e.printStackTrace(); |
|
427 |
// // } |
|
428 |
// // heightDefault=-1; |
|
429 |
// } |
|
337 | 430 |
|
431 |
// public Rectangle2D getDefaultBoundBoxinPixels(FontMetrics metrics, |
|
432 |
// Point2D p, String s) { |
|
433 |
// int w = metrics.stringWidth(s); |
|
434 |
// double width = viewPort.toMapDistance(w); |
|
435 |
// if (heightDefault == -1) { |
|
436 |
// int h = metrics.getMaxAscent(); |
|
437 |
// heightDefault = viewPort.toMapDistance(h); |
|
438 |
// } |
|
439 |
// return new Rectangle2D.Double(p.getX(), p.getY(), width, heightDefault); |
|
440 |
// |
|
441 |
// } |
|
338 | 442 |
|
443 |
/** |
|
444 |
* Construcci?n del rect?ngulo |
|
445 |
* |
|
446 |
* @param p |
|
447 |
* @param g |
|
448 |
* DOCUMENT ME! |
|
449 |
* @param justification |
|
450 |
* DOCUMENT ME! |
|
451 |
* @param vp |
|
452 |
* DOCUMENT ME! |
|
453 |
* |
|
454 |
* @return |
|
455 |
*/ |
|
456 |
// public Rectangle2D getBoundBox(Point2D p, float hp, |
|
457 |
// int justification,String s) { |
|
458 |
// //Rectangle2D bounding=null; |
|
459 |
// if (((Annotation_Layer)capa).isInPixels()){ |
|
460 |
// graphics.setFont(graphics.getFont().deriveFont(hp)); |
|
461 |
// }else{ |
|
462 |
// float alturaPixels = (float) ((hp * |
|
463 |
// viewPort.getAffineTransform().getScaleX())*FConstant.FONT_HEIGHT_SCALE_FACTOR); |
|
464 |
// graphics.setFont(graphics.getFont().deriveFont(alturaPixels)); |
|
465 |
// } |
|
466 |
// FontMetrics metrics = graphics.getFontMetrics(); |
|
467 |
// int w = metrics.stringWidth(s); |
|
468 |
// double width = viewPort.toMapDistance(w); |
|
469 |
// int h = metrics.getMaxAscent(); |
|
470 |
// double height = viewPort.toMapDistance(h); |
|
471 |
// //double dist = viewPort.toMapDistance(3); |
|
472 |
// return new Rectangle2D.Double(p.getX(), p.getY(), width, height); |
|
473 |
// /* switch (justification) { |
|
474 |
// case FLabel.LEFT_BOTTOM: |
|
475 |
// bounding=justification(p, width,height, 0, 0); |
|
476 |
// |
|
477 |
// break; |
|
478 |
// |
|
479 |
// case FLabel.LEFT_CENTER: |
|
480 |
// bounding=justification(p, width,height, 0, -(height / 2)); |
|
481 |
// |
|
482 |
// break; |
|
483 |
// |
|
484 |
// case FLabel.LEFT_TOP: |
|
485 |
// bounding=justification(p,width,height, 0, -height); |
|
486 |
// |
|
487 |
// break; |
|
488 |
// |
|
489 |
// case FLabel.CENTER_BOTTOM: |
|
490 |
// bounding=justification(p, width,height, -(width / 2), -dist); |
|
491 |
// |
|
492 |
// break; |
|
493 |
// |
|
494 |
// case FLabel.CENTER_CENTER: |
|
495 |
// bounding=justification(p, width,height, -(width / 2), -(height / 2)); |
|
496 |
// |
|
497 |
// break; |
|
498 |
// |
|
499 |
// case FLabel.CENTER_TOP: |
|
500 |
// bounding=justification(p, width,height, -(width / 2), -height); |
|
501 |
// |
|
502 |
// break; |
|
503 |
// |
|
504 |
// case FLabel.RIGHT_BOTTOM: |
|
505 |
// bounding=justification(p, width,height, -width, -dist); |
|
506 |
// |
|
507 |
// break; |
|
508 |
// |
|
509 |
// case FLabel.RIGHT_CENTER: |
|
510 |
// bounding=justification(p, width,height, -width, -(height / 2)); |
|
511 |
// |
|
512 |
// break; |
|
513 |
// |
|
514 |
// case FLabel.RIGHT_TOP: |
|
515 |
// bounding=justification(p, width,height, -width, -height); |
|
516 |
// |
|
517 |
// break; |
|
518 |
// } |
|
519 |
// |
|
520 |
// return bounding; |
|
521 |
// */ |
|
522 |
// } |
|
523 |
/* |
|
524 |
* private Rectangle2D justification(Point2D p, double w,double h, double x, |
|
525 |
* double y) { Rectangle2D r=new Rectangle2D.Double(p.getX() + x, p.getY() - |
|
526 |
* y, w, h); return r; } |
|
527 |
*/ |
|
339 | 528 |
|
529 |
/* |
|
530 |
* (non-Javadoc) |
|
531 |
* |
|
532 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.core.IGeometry, |
|
533 |
* int) |
|
534 |
*/ |
|
535 |
public FBitSet queryByShape(IGeometry g, int relationship) |
|
536 |
throws DriverException, VisitException { |
|
537 |
// Si hay un ?ndice espacial, lo usamos para hacer el query. |
|
538 |
FLyrVect lyr = (FLyrVect) capa; |
|
539 |
// if (lyr.getSpatialIndex() == null) |
|
540 |
if (lyr.getISpatialIndex() == null) |
|
541 |
return super.queryByShape(g, relationship); |
|
340 | 542 |
|
543 |
long t1 = System.currentTimeMillis(); |
|
544 |
ReadableVectorial va = lyr.getSource(); |
|
545 |
ICoordTrans ct = lyr.getCoordTrans(); |
|
546 |
Rectangle2D bounds = g.getBounds2D(); |
|
547 |
// Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY()); |
|
548 |
// Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY()); |
|
549 |
// Envelope env = new Envelope(c1, c2); |
|
550 |
// List lstRecs = lyr.getSpatialIndex().query(env); |
|
551 |
List lstRecs = lyr.getISpatialIndex().query(bounds); |
|
552 |
Integer idRec; |
|
553 |
FBitSet bitset = new FBitSet(); |
|
554 |
Geometry jtsShape = g.toJTSGeometry(); |
|
555 |
IntersectionMatrix m; |
|
556 |
int index; |
|
557 |
try { |
|
558 |
va.start(); |
|
559 |
// Annotation_Legend aLegend=(Annotation_Legend)capa.getLegend(); |
|
560 |
for (int i = 0; i < lstRecs.size(); i++) { |
|
561 |
idRec = (Integer) lstRecs.get(i); |
|
562 |
index = idRec.intValue(); |
|
563 |
IGeometry geom = va.getShape(index); |
|
564 |
// FSymbol symbol=(FSymbol)aLegend.getSymbol(index); |
|
565 |
// IGeometry geom=aLegend.getTextWrappingGeometry(symbol,index); |
|
566 |
// IGeometry |
|
567 |
// geom=getGeometry(((Annotation_Layer)capa).getLabel(index).getBoundBox()); |
|
568 |
if (ct != null) { |
|
569 |
geom.reProject(ct); |
|
570 |
} |
|
571 |
Geometry jtsGeom = geom.toJTSGeometry(); |
|
572 |
switch (relationship) { |
|
573 |
case CONTAINS: |
|
574 |
m = jtsShape.relate(jtsGeom); |
|
575 |
if (m.isContains()) { |
|
576 |
bitset.set(index, true); |
|
577 |
} |
|
578 |
break; |
|
341 | 579 |
|
580 |
case CROSSES: |
|
581 |
m = jtsShape.relate(jtsGeom); |
|
582 |
if (m.isCrosses(jtsGeom.getDimension(), jtsShape |
|
583 |
.getDimension())) { |
|
584 |
bitset.set(index, true); |
|
585 |
} |
|
586 |
break; |
|
342 | 587 |
|
588 |
case DISJOINT: |
|
589 |
// TODO: CREO QUE EL DISJOINT NO SE PUEDE METER AQUI |
|
590 |
m = jtsShape.relate(jtsGeom); |
|
591 |
if (m.isDisjoint()) { |
|
592 |
bitset.set(index, true); |
|
593 |
} |
|
594 |
break; |
|
343 | 595 |
|
344 |
/** |
|
345 |
* @see com.iver.cit.gvsig.fmap.operations.LayerOperations#draw(java.awt.image.BufferedImage, |
|
346 |
* java.awt.Graphics2D, ISymbol) |
|
347 |
*/ |
|
348 |
public void print(BufferedImage image, Graphics2D g, ViewPort viewPort, |
|
349 |
Cancellable cancel) throws DriverException { |
|
350 |
// Rectangle2D elExtent = viewPort.getAdjustedExtent(); |
|
351 |
// graphics=g; |
|
352 |
// Annotation_Layer lyrAnnotation=(Annotation_Layer)capa; |
|
353 |
// List lstIndexes=null; |
|
354 |
// |
|
355 |
// VectorialLegend l=(VectorialLegend)lyrAnnotation.getLegend(); |
|
356 |
// FBitSet bitSet=lyrAnnotation.getRecordset().getSelection(); |
|
357 |
// |
|
358 |
// boolean inPixels=lyrAnnotation.isInPixels(); |
|
359 |
// FSymbol theSymbol = (FSymbol) l.getDefaultSymbol(); |
|
360 |
// theSymbol.setFontSizeInPixels(inPixels); |
|
361 |
// this.viewPort=viewPort;//capa.getFMap().getViewPort(); |
|
362 |
// AffineTransform at=viewPort.getAffineTransform(); |
|
363 |
// try { |
|
364 |
// int sc; |
|
365 |
// sc=lyrAnnotation.getSource().getShapeCount(); |
|
366 |
// // If area of needed extent is less than fullExtent / 4, |
|
367 |
// // it will be worthy to use SpatialIndex. |
|
368 |
// // Otherwhise, we will not use it. |
|
369 |
// boolean bUseSpatialIndex = false; |
|
370 |
// if(lyrAnnotation.getISpatialIndex() != null) |
|
371 |
// { |
|
372 |
// if(isSpatialIndexNecessary(elExtent)){ |
|
373 |
// lstIndexes = lyrAnnotation.getISpatialIndex().query(elExtent); |
|
374 |
// sc = lstIndexes.size(); |
|
375 |
// bUseSpatialIndex = true; |
|
376 |
// }//if |
|
377 |
// }//if |
|
378 |
// |
|
379 |
// FontMetrics metrics = g.getFontMetrics(); |
|
380 |
// //SpatialCache cache = lyrAnnotation.createSpatialCache(); |
|
381 |
// int numOriginal; |
|
382 |
// for (int numReg = 0; numReg < sc; numReg++) { |
|
383 |
// if (cancel.isCanceled()){ |
|
384 |
// break; |
|
385 |
// } |
|
386 |
// if (bUseSpatialIndex){ |
|
387 |
// Integer idRec = (Integer) lstIndexes.get(numReg); |
|
388 |
// numOriginal = idRec.intValue(); |
|
389 |
// }else{ |
|
390 |
// numOriginal = numReg; |
|
391 |
// } |
|
392 |
// /* if (lyrAnnotation.getSource() instanceof EditableAdapter) |
|
393 |
// numOriginal=((EditableAdapter)lyrAnnotation.getSource()).getCalculatedIndex(numOriginal);*/ |
|
394 |
// |
|
395 |
// FLabel theLabel = lyrAnnotation.getLabel(numOriginal); |
|
396 |
// if ((theLabel == null) || (theLabel.getOrig() == null)) |
|
397 |
// continue; |
|
398 |
// |
|
399 |
// |
|
400 |
// Rectangle2D r=null; |
|
401 |
// if (inPixels && lyrAnnotation.getMapping().getColumnHeight()==-1) { |
|
402 |
// r=getDefaultBoundBoxinPixels(metrics,theLabel.getOrig(),theLabel.getString()); |
|
403 |
// }else { |
|
404 |
// r=getBoundBox(theLabel.getOrig(),(float)theLabel.getHeight(), theLabel.getJustification(),theLabel.getString()); |
|
405 |
// } |
|
406 |
// theLabel.setBoundBox(r); |
|
407 |
// |
|
408 |
// if (elExtent.intersects(r)) |
|
409 |
// { |
|
410 |
// FPoint2D p=new FPoint2D(viewPort.fromMapPoint(new Point2D.Double(r.getX(),r.getY()))); |
|
411 |
// FGraphicUtilities.DrawShape(g,at,p,symbolPoint); |
|
412 |
// if (bitSet.get(numOriginal)) { |
|
413 |
// FGraphicUtilities.DrawAnnotation(g, at, theSymbol, theLabel,metrics,true); |
|
414 |
// }else{ |
|
415 |
// FGraphicUtilities.DrawAnnotation(g, at, theSymbol, theLabel,metrics,false); |
|
416 |
// } |
|
417 |
// |
|
418 |
// |
|
419 |
// } // XIntersects |
|
420 |
// |
|
421 |
// |
|
422 |
// } |
|
423 |
// |
|
424 |
// } catch (DriverIOException e) { |
|
425 |
// e.printStackTrace(); |
|
426 |
// } |
|
427 |
// heightDefault=-1; |
|
428 |
} |
|
596 |
case EQUALS: |
|
597 |
m = jtsShape.relate(jtsGeom); |
|
598 |
if (m.isEquals(jtsGeom.getDimension(), jtsShape |
|
599 |
.getDimension())) { |
|
600 |
bitset.set(index, true); |
|
601 |
} |
|
602 |
break; |
|
429 | 603 |
|
430 |
// public Rectangle2D getDefaultBoundBoxinPixels(FontMetrics metrics, |
|
431 |
// Point2D p, String s) { |
|
432 |
// int w = metrics.stringWidth(s); |
|
433 |
// double width = viewPort.toMapDistance(w); |
|
434 |
// if (heightDefault == -1) { |
|
435 |
// int h = metrics.getMaxAscent(); |
|
436 |
// heightDefault = viewPort.toMapDistance(h); |
|
437 |
// } |
|
438 |
// return new Rectangle2D.Double(p.getX(), p.getY(), width, heightDefault); |
|
439 |
// |
|
440 |
// } |
|
604 |
case INTERSECTS: |
|
605 |
m = jtsShape.relate(jtsGeom); |
|
606 |
if (m.isIntersects()) { |
|
607 |
bitset.set(index, true); |
|
608 |
} |
|
609 |
break; |
|
441 | 610 |
|
442 |
/** |
|
443 |
* Construcci?n del rect?ngulo |
|
444 |
* |
|
445 |
* @param p |
|
446 |
* @param g |
|
447 |
* DOCUMENT ME! |
|
448 |
* @param justification |
|
449 |
* DOCUMENT ME! |
|
450 |
* @param vp |
|
451 |
* DOCUMENT ME! |
|
452 |
* |
|
453 |
* @return |
|
454 |
*/ |
|
455 |
// public Rectangle2D getBoundBox(Point2D p, float hp, |
|
456 |
// int justification,String s) { |
|
457 |
// //Rectangle2D bounding=null; |
|
458 |
// if (((Annotation_Layer)capa).isInPixels()){ |
|
459 |
// graphics.setFont(graphics.getFont().deriveFont(hp)); |
|
460 |
// }else{ |
|
461 |
// float alturaPixels = (float) ((hp * viewPort.getAffineTransform().getScaleX())*FConstant.FONT_HEIGHT_SCALE_FACTOR); |
|
462 |
// graphics.setFont(graphics.getFont().deriveFont(alturaPixels)); |
|
463 |
// } |
|
464 |
// FontMetrics metrics = graphics.getFontMetrics(); |
|
465 |
// int w = metrics.stringWidth(s); |
|
466 |
// double width = viewPort.toMapDistance(w); |
|
467 |
// int h = metrics.getMaxAscent(); |
|
468 |
// double height = viewPort.toMapDistance(h); |
|
469 |
// //double dist = viewPort.toMapDistance(3); |
|
470 |
// return new Rectangle2D.Double(p.getX(), p.getY(), width, height); |
|
471 |
// /* switch (justification) { |
|
472 |
// case FLabel.LEFT_BOTTOM: |
|
473 |
// bounding=justification(p, width,height, 0, 0); |
|
474 |
// |
|
475 |
// break; |
|
476 |
// |
|
477 |
// case FLabel.LEFT_CENTER: |
|
478 |
// bounding=justification(p, width,height, 0, -(height / 2)); |
|
479 |
// |
|
480 |
// break; |
|
481 |
// |
|
482 |
// case FLabel.LEFT_TOP: |
|
483 |
// bounding=justification(p,width,height, 0, -height); |
|
484 |
// |
|
485 |
// break; |
|
486 |
// |
|
487 |
// case FLabel.CENTER_BOTTOM: |
|
488 |
// bounding=justification(p, width,height, -(width / 2), -dist); |
|
489 |
// |
|
490 |
// break; |
|
491 |
// |
|
492 |
// case FLabel.CENTER_CENTER: |
|
493 |
// bounding=justification(p, width,height, -(width / 2), -(height / 2)); |
|
494 |
// |
|
495 |
// break; |
|
496 |
// |
|
497 |
// case FLabel.CENTER_TOP: |
|
498 |
// bounding=justification(p, width,height, -(width / 2), -height); |
|
499 |
// |
|
500 |
// break; |
|
501 |
// |
|
502 |
// case FLabel.RIGHT_BOTTOM: |
|
503 |
// bounding=justification(p, width,height, -width, -dist); |
|
504 |
// |
|
505 |
// break; |
|
506 |
// |
|
507 |
// case FLabel.RIGHT_CENTER: |
|
508 |
// bounding=justification(p, width,height, -width, -(height / 2)); |
|
509 |
// |
|
510 |
// break; |
|
511 |
// |
|
512 |
// case FLabel.RIGHT_TOP: |
|
513 |
// bounding=justification(p, width,height, -width, -height); |
|
514 |
// |
|
515 |
// break; |
|
516 |
// } |
|
517 |
// |
|
518 |
// return bounding; |
|
519 |
// */ |
|
520 |
// } |
|
521 |
/* private Rectangle2D justification(Point2D p, double w,double h, double x, double y) { |
|
522 |
Rectangle2D r=new Rectangle2D.Double(p.getX() + x, p.getY() - y, w, h); |
|
523 |
return r; |
|
524 |
} |
|
525 |
*/ |
|
611 |
case OVERLAPS: |
|
612 |
m = jtsShape.relate(jtsGeom); |
|
613 |
if (m.isOverlaps(jtsGeom.getDimension(), jtsShape |
|
614 |
.getDimension())) { |
|
615 |
bitset.set(index, true); |
|
616 |
} |
|
526 | 617 |
|
527 |
/* (non-Javadoc) |
|
528 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByShape(com.iver.cit.gvsig.fmap.core.IGeometry, int) |
|
529 |
*/ |
|
530 |
public FBitSet queryByShape(IGeometry g, int relationship) |
|
531 |
throws DriverException, VisitException { |
|
532 |
// Si hay un ?ndice espacial, lo usamos para hacer el query. |
|
533 |
FLyrVect lyr = (FLyrVect) capa; |
|
534 |
// if (lyr.getSpatialIndex() == null) |
|
535 |
if(lyr.getISpatialIndex() == null) |
|
536 |
return super.queryByShape(g, relationship); |
|
618 |
break; |
|
537 | 619 |
|
538 |
long t1 = System.currentTimeMillis(); |
|
539 |
ReadableVectorial va = lyr.getSource(); |
|
540 |
ICoordTrans ct = lyr.getCoordTrans(); |
|
541 |
Rectangle2D bounds = g.getBounds2D(); |
|
542 |
// Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY()); |
|
543 |
// Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY()); |
|
544 |
// Envelope env = new Envelope(c1, c2); |
|
545 |
// List lstRecs = lyr.getSpatialIndex().query(env); |
|
546 |
List lstRecs = lyr.getISpatialIndex().query(bounds); |
|
547 |
Integer idRec; |
|
548 |
FBitSet bitset = new FBitSet(); |
|
549 |
Geometry jtsShape = g.toJTSGeometry(); |
|
550 |
IntersectionMatrix m; |
|
551 |
int index; |
|
552 |
try { |
|
553 |
va.start(); |
|
554 |
// Annotation_Legend aLegend=(Annotation_Legend)capa.getLegend(); |
|
555 |
for (int i=0; i < lstRecs.size(); i++) |
|
556 |
{ |
|
557 |
idRec = (Integer) lstRecs.get(i); |
|
558 |
index = idRec.intValue(); |
|
559 |
IGeometry geom=va.getShape(index); |
|
560 |
// FSymbol symbol=(FSymbol)aLegend.getSymbol(index); |
|
561 |
// IGeometry geom=aLegend.getTextWrappingGeometry(symbol,index); |
|
562 |
// IGeometry geom=getGeometry(((Annotation_Layer)capa).getLabel(index).getBoundBox()); |
|
563 |
if (ct != null) { |
|
564 |
geom.reProject(ct); |
|
565 |
} |
|
566 |
Geometry jtsGeom = geom.toJTSGeometry(); |
|
567 |
switch (relationship) { |
|
568 |
case CONTAINS: |
|
569 |
m = jtsShape.relate(jtsGeom); |
|
570 |
if (m.isContains()) { |
|
571 |
bitset.set(index, true); |
|
572 |
} |
|
573 |
break; |
|
620 |
case TOUCHES: |
|
621 |
m = jtsShape.relate(jtsGeom); |
|
622 |
if (m.isTouches(jtsGeom.getDimension(), jtsShape |
|
623 |
.getDimension())) { |
|
624 |
bitset.set(index, true); |
|
625 |
} |
|
574 | 626 |
|
575 |
case CROSSES: |
|
576 |
m = jtsShape.relate(jtsGeom); |
|
577 |
if (m.isCrosses(jtsGeom.getDimension(), jtsShape.getDimension())) { |
|
578 |
bitset.set(index, true); |
|
579 |
} |
|
580 |
break; |
|
627 |
break; |
|
581 | 628 |
|
582 |
case DISJOINT: |
|
583 |
// TODO: CREO QUE EL DISJOINT NO SE PUEDE METER AQUI |
|
584 |
m = jtsShape.relate(jtsGeom); |
|
585 |
if (m.isDisjoint()) { |
|
586 |
bitset.set(index, true); |
|
587 |
} |
|
588 |
break; |
|
629 |
case WITHIN: |
|
630 |
m = jtsShape.relate(jtsGeom); |
|
631 |
if (m.isWithin()) { |
|
632 |
bitset.set(index, true); |
|
633 |
} |
|
589 | 634 |
|
590 |
case EQUALS: |
|
591 |
m = jtsShape.relate(jtsGeom); |
|
592 |
if (m.isEquals(jtsGeom.getDimension(), jtsShape.getDimension())) { |
|
593 |
bitset.set(index, true); |
|
594 |
} |
|
595 |
break; |
|
635 |
break; |
|
636 |
} |
|
637 |
} |
|
638 |
va.stop(); |
|
639 |
} catch (DriverIOException e) { |
|
640 |
// TODO Auto-generated catch block |
|
641 |
e.printStackTrace(); |
|
642 |
} |
|
643 |
long t2 = System.currentTimeMillis(); |
|
644 |
// logger.debug("queryByShape optimizado sobre la capa " + lyr.getName() |
|
645 |
// + ". " + (t2-t1) + " mseg."); |
|
646 |
return bitset; |
|
647 |
} |
|
596 | 648 |
|
597 |
case INTERSECTS:
|
|
598 |
m = jtsShape.relate(jtsGeom);
|
|
599 |
if (m.isIntersects()) {
|
|
600 |
bitset.set(index, true);
|
|
601 |
}
|
|
602 |
break;
|
|
649 |
public FBitSet queryByRect(Rectangle2D rect) throws DriverException {
|
|
650 |
// Si hay un ?ndice espacial, lo usamos para hacer el query.
|
|
651 |
Annotation_Layer lyr = (Annotation_Layer) capa;
|
|
652 |
// if (lyr.getSpatialIndex() == null)
|
|
653 |
if (lyr.getISpatialIndex() == null)
|
|
654 |
return super.queryByRect(rect);
|
|
603 | 655 |
|
604 |
case OVERLAPS: |
|
605 |
m = jtsShape.relate(jtsGeom); |
|
606 |
if (m.isOverlaps(jtsGeom.getDimension(), jtsShape.getDimension())) |
|
607 |
{ |
|
608 |
bitset.set(index, true); |
|
609 |
} |
|
656 |
ReadableVectorial va = lyr.getSource(); |
|
657 |
ICoordTrans ct = lyr.getCoordTrans(); |
|
658 |
Rectangle2D bounds = rect; |
|
659 |
// Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY()); |
|
660 |
// Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY()); |
|
661 |
// Envelope env = new Envelope(c1, c2); |
|
662 |
// |
|
663 |
// List lstRecs = lyr.getSpatialIndex().query(env); |
|
664 |
// azabala |
|
665 |
List lstRecs = lyr.getISpatialIndex().query(bounds); |
|
666 |
Integer idRec; |
|
667 |
FBitSet bitset = new FBitSet(); |
|
668 |
int index; |
|
669 |
try { |
|
670 |
va.start(); |
|
671 |
DriverAttributes attr = va.getDriverAttributes(); |
|
672 |
boolean bMustClone = false; |
|
673 |
if (attr != null) { |
|
674 |
if (attr.isLoadedInMemory()) { |
|
675 |
bMustClone = attr.isLoadedInMemory(); |
|
676 |
} |
|
677 |
} |
|
678 |
// Annotation_Legend aLegend=(Annotation_Legend)capa.getLegend(); |
|
679 |
for (int i = 0; i < lstRecs.size(); i++) { |
|
680 |
idRec = (Integer) lstRecs.get(i); |
|
681 |
index = idRec.intValue(); |
|
682 |
// FSymbol symbol=(FSymbol)aLegend.getSymbol(index); |
|
683 |
// IGeometry geom=aLegend.getTextWrappingGeometry(symbol,index); |
|
684 |
Annotation_Mapping mapping = ((Annotation_Layer) capa) |
|
685 |
.getAnnotatonMapping(); |
|
686 |
NumericValue vRotation = (NumericValue) va.getRecordset() |
|
687 |
.getFieldValue(index, mapping.getColumnRotate()); |
|
688 |
NumericValue vHeight = (NumericValue) va.getRecordset() |
|
689 |
.getFieldValue(index, mapping.getColumnHeight()); |
|
690 |
Value vText = va.getRecordset().getFieldValue(index, |
|
691 |
mapping.getColumnText()); |
|
692 |
IGeometry geom = ((Annotation_Layer) capa) |
|
693 |
.getTextWrappingGeometry(vHeight.floatValue(), vText |
|
694 |
.toString(), vRotation.doubleValue(), index); |
|
695 |
// IGeometry geom=va.getShape(index); |
|
696 |
// IGeometry |
|
697 |
// geom=getGeometry(((Annotation_Layer)capa).getLabel(index).getBoundBox()); |
|
698 |
if (ct != null) { |
|
699 |
if (bMustClone) |
|
700 |
geom = geom.cloneGeometry(); |
|
701 |
geom.reProject(ct); |
|
702 |
} |
|
703 |
// System.out.println("Rect?ngulo de selecci?n = "+ rect); |
|
704 |
// System.out.println("Rect?ngulo de la geometr?a = "+ |
|
705 |
// geom.getBounds2D()); |
|
706 |
if (geom.intersects(rect)) { |
|
707 |
bitset.set(index, true); |
|
708 |
} |
|
610 | 709 |
|
611 |
break; |
|
612 |
|
|
613 |
case TOUCHES: |
|
614 |
m = jtsShape.relate(jtsGeom); |
|
615 |
if (m.isTouches(jtsGeom.getDimension(), jtsShape.getDimension())) |
|
616 |
{ |
|
617 |
bitset.set(index, true); |
|
618 |
} |
|
619 |
|
|
620 |
break; |
|
621 |
|
|
622 |
case WITHIN: |
|
623 |
m = jtsShape.relate(jtsGeom); |
|
624 |
if (m.isWithin()) { |
|
625 |
bitset.set(index, true); |
|
626 |
} |
|
627 |
|
|
628 |
break; |
|
629 |
} |
|
630 |
} |
|
631 |
va.stop(); |
|
632 |
} catch (DriverIOException e) { |
|
633 |
// TODO Auto-generated catch block |
|
634 |
e.printStackTrace(); |
|
635 |
} |
|
636 |
long t2 = System.currentTimeMillis(); |
|
637 |
// logger.debug("queryByShape optimizado sobre la capa " + lyr.getName() + ". " + (t2-t1) + " mseg."); |
|
638 |
return bitset; |
|
639 |
} |
|
640 |
public FBitSet queryByRect(Rectangle2D rect) throws DriverException { |
|
641 |
// Si hay un ?ndice espacial, lo usamos para hacer el query. |
|
642 |
Annotation_Layer lyr = (Annotation_Layer) capa; |
|
643 |
// if (lyr.getSpatialIndex() == null) |
|
644 |
if(lyr.getISpatialIndex() == null) |
|
645 |
return super.queryByRect(rect); |
|
646 |
|
|
647 |
ReadableVectorial va = lyr.getSource(); |
|
648 |
ICoordTrans ct = lyr.getCoordTrans(); |
|
649 |
Rectangle2D bounds = rect; |
|
650 |
// Coordinate c1 = new Coordinate(bounds.getMinX(), bounds.getMinY()); |
|
651 |
// Coordinate c2 = new Coordinate(bounds.getMaxX(), bounds.getMaxY()); |
|
652 |
// Envelope env = new Envelope(c1, c2); |
|
653 |
// |
|
654 |
// List lstRecs = lyr.getSpatialIndex().query(env); |
|
655 |
//azabala |
|
656 |
List lstRecs = lyr.getISpatialIndex().query(bounds); |
|
657 |
Integer idRec; |
|
658 |
FBitSet bitset = new FBitSet(); |
|
659 |
int index; |
|
660 |
try { |
|
661 |
va.start(); |
|
662 |
DriverAttributes attr = va.getDriverAttributes(); |
|
663 |
boolean bMustClone = false; |
|
664 |
if (attr != null) |
|
665 |
{ |
|
666 |
if (attr.isLoadedInMemory()) |
|
667 |
{ |
|
668 |
bMustClone = attr.isLoadedInMemory(); |
|
669 |
} |
|
670 |
} |
|
671 |
// Annotation_Legend aLegend=(Annotation_Legend)capa.getLegend(); |
|
672 |
for (int i=0; i < lstRecs.size(); i++) |
|
673 |
{ |
|
674 |
idRec = (Integer) lstRecs.get(i); |
|
675 |
index = idRec.intValue(); |
|
676 |
// FSymbol symbol=(FSymbol)aLegend.getSymbol(index); |
|
677 |
// IGeometry geom=aLegend.getTextWrappingGeometry(symbol,index); |
|
678 |
Annotation_Mapping mapping=((Annotation_Layer)capa).getAnnotatonMapping(); |
|
679 |
NumericValue vRotation = (NumericValue)va.getRecordset().getFieldValue(index,mapping.getColumnRotate()); |
|
680 |
NumericValue vHeight = (NumericValue)va.getRecordset().getFieldValue(index,mapping.getColumnHeight()); |
|
681 |
Value vText = va.getRecordset().getFieldValue(index,mapping.getColumnText()); |
|
682 |
IGeometry geom=((Annotation_Layer)capa).getTextWrappingGeometry(vHeight.floatValue(), |
|
683 |
vText.toString(),vRotation.doubleValue(),index); |
|
684 |
// IGeometry geom=va.getShape(index); |
|
685 |
// IGeometry geom=getGeometry(((Annotation_Layer)capa).getLabel(index).getBoundBox()); |
|
686 |
if (ct != null) { |
|
687 |
if (bMustClone) |
|
688 |
geom = geom.cloneGeometry(); |
|
689 |
geom.reProject(ct); |
|
690 |
} |
|
691 |
//System.out.println("Rect?ngulo de selecci?n = "+ rect); |
|
692 |
//System.out.println("Rect?ngulo de la geometr?a = "+ geom.getBounds2D()); |
|
693 |
if (geom.intersects(rect)){ |
|
694 |
bitset.set(index, true); |
|
695 |
} |
|
696 |
|
|
697 |
} |
|
698 |
va.stop(); |
|
699 |
} catch (DriverIOException e) { |
|
700 |
// TODO Auto-generated catch block |
|
701 |
e.printStackTrace(); |
|
702 |
} catch (DriverLoadException e) { |
|
710 |
} |
|
711 |
va.stop(); |
|
712 |
} catch (DriverIOException e) { |
|
703 | 713 |
// TODO Auto-generated catch block |
704 | 714 |
e.printStackTrace(); |
715 |
} catch (DriverLoadException e) { |
|
716 |
// TODO Auto-generated catch block |
|
717 |
e.printStackTrace(); |
|
705 | 718 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
706 | 719 |
// TODO Auto-generated catch block |
707 | 720 |
e.printStackTrace(); |
708 | 721 |
} |
709 |
return bitset;
|
|
722 |
return bitset;
|
|
710 | 723 |
|
711 |
}
|
|
724 |
}
|
|
712 | 725 |
|
713 |
/* (non-Javadoc) |
|
714 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(java.awt.geom.Point2D, double) |
|
715 |
*/ |
|
716 |
public FBitSet queryByPoint(Point2D p, double tolerance) |
|
717 |
throws DriverException { |
|
718 |
// TODO: OJO!!!!. Est? implementado como un rectangulo. |
|
719 |
// Lo correcto deber?a ser calculando las distancias reales |
|
720 |
// es decir, con un c?rculo. |
|
721 |
Rectangle2D recPoint = new Rectangle2D.Double(p.getX() - (tolerance / 2), |
|
722 |
p.getY() - (tolerance / 2), tolerance, tolerance); |
|
723 |
return queryByRect(recPoint); |
|
724 |
} |
|
725 |
// private IGeometry getGeometry(Rectangle2D r){ |
|
726 |
// GeneralPathX resul = new GeneralPathX(); |
|
727 |
// Point2D[] vs=new Point2D[4]; |
|
728 |
// vs[0]=new Point2D.Double(r.getX(),r.getY()); |
|
729 |
// vs[1]=new Point2D.Double(r.getMaxX(),r.getY()); |
|
730 |
// vs[2]=new Point2D.Double(r.getMaxX(),r.getMaxY()); |
|
731 |
// vs[3]=new Point2D.Double(r.getX(),r.getMaxY()); |
|
732 |
// //vs[4]=new Point2D.Double(r.getX(),r.getY()); |
|
733 |
// for (int i = 0; i < vs.length; i++) { |
|
734 |
// if (i == 0) { |
|
735 |
// resul.moveTo(vs[i].getX(),vs[i].getY()); |
|
736 |
// } else { |
|
737 |
// resul.lineTo(vs[i].getX(),vs[i].getY()); |
|
738 |
// } |
|
739 |
// } |
|
740 |
// resul.closePath(); |
|
741 |
// return ShapeFactory.createPolygon2D(resul); |
|
742 |
// } |
|
726 |
/* |
|
727 |
* (non-Javadoc) |
|
728 |
* |
|
729 |
* @see com.iver.cit.gvsig.fmap.operations.strategies.Strategy#queryByPoint(java.awt.geom.Point2D, |
|
730 |
* double) |
|
731 |
*/ |
|
732 |
public FBitSet queryByPoint(Point2D p, double tolerance) |
|
733 |
throws DriverException { |
|
734 |
// TODO: OJO!!!!. Est? implementado como un rectangulo. |
|
735 |
// Lo correcto deber?a ser calculando las distancias reales |
|
736 |
// es decir, con un c?rculo. |
|
737 |
Rectangle2D recPoint = new Rectangle2D.Double(p.getX() |
|
738 |
- (tolerance / 2), p.getY() - (tolerance / 2), tolerance, |
|
739 |
tolerance); |
|
740 |
return queryByRect(recPoint); |
|
741 |
} |
|
742 |
|
|
743 |
// private IGeometry getGeometry(Rectangle2D r){ |
|
744 |
// GeneralPathX resul = new GeneralPathX(); |
|
745 |
// Point2D[] vs=new Point2D[4]; |
|
746 |
// vs[0]=new Point2D.Double(r.getX(),r.getY()); |
|
747 |
// vs[1]=new Point2D.Double(r.getMaxX(),r.getY()); |
|
748 |
// vs[2]=new Point2D.Double(r.getMaxX(),r.getMaxY()); |
|
749 |
// vs[3]=new Point2D.Double(r.getX(),r.getMaxY()); |
|
750 |
// //vs[4]=new Point2D.Double(r.getX(),r.getY()); |
|
751 |
// for (int i = 0; i < vs.length; i++) { |
|
752 |
// if (i == 0) { |
|
753 |
// resul.moveTo(vs[i].getX(),vs[i].getY()); |
|
754 |
// } else { |
|
755 |
// resul.lineTo(vs[i].getX(),vs[i].getY()); |
|
756 |
// } |
|
757 |
// } |
|
758 |
// resul.closePath(); |
|
759 |
// return ShapeFactory.createPolygon2D(resul); |
|
760 |
// } |
|
761 |
public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
|
762 |
PrintRequestAttributeSet properties) throws DriverException { |
|
763 |
capa.beforePrinting(properties); |
|
764 |
draw(null, g, viewPort, cancel); |
|
765 |
capa.afterPrinting(); |
|
766 |
} |
|
743 | 767 |
} |
Also available in: Unified diff