svn-gvsig-desktop / branches / v10 / extensions / extAnnotations / src / com / iver / cit / gvsig / fmap / operation / strategies / Annotation_Strategy.java @ 11588
History | View | Annotate | Download (25.6 KB)
1 |
package com.iver.cit.gvsig.fmap.operation.strategies; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Font; |
5 |
import java.awt.FontMetrics; |
6 |
import java.awt.Graphics2D; |
7 |
import java.awt.geom.Point2D; |
8 |
import java.awt.geom.Rectangle2D; |
9 |
import java.awt.image.BufferedImage; |
10 |
import java.util.List; |
11 |
|
12 |
import org.cresques.cts.ICoordTrans; |
13 |
|
14 |
import com.hardcode.driverManager.DriverLoadException; |
15 |
import com.hardcode.gdbms.engine.values.NullValue; |
16 |
import com.hardcode.gdbms.engine.values.NumericValue; |
17 |
import com.hardcode.gdbms.engine.values.StringValue; |
18 |
import com.hardcode.gdbms.engine.values.Value; |
19 |
import com.iver.cit.gvsig.fmap.DriverException; |
20 |
import com.iver.cit.gvsig.fmap.ViewPort; |
21 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
22 |
import com.iver.cit.gvsig.fmap.core.FShape; |
23 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
24 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
25 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
26 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
27 |
import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
28 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
29 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
30 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
31 |
import com.iver.cit.gvsig.fmap.layers.Annotation_Layer; |
32 |
import com.iver.cit.gvsig.fmap.layers.Annotation_Mapping; |
33 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
34 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
35 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
36 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
37 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
38 |
import com.iver.cit.gvsig.fmap.operations.strategies.DefaultStrategy; |
39 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
40 |
import com.iver.cit.gvsig.fmap.rendering.Annotation_Legend; |
41 |
import com.iver.utiles.swing.threads.Cancellable; |
42 |
import com.vividsolutions.jts.geom.Geometry; |
43 |
import com.vividsolutions.jts.geom.IntersectionMatrix; |
44 |
|
45 |
|
46 |
/**
|
47 |
* Esta clase se encargar? de dibujar de la forma m?s eficiente los temas de
|
48 |
* anotaciones.
|
49 |
*
|
50 |
* @author Vicente Caballero Navarro
|
51 |
*/
|
52 |
public class Annotation_Strategy extends DefaultStrategy { |
53 |
private FSymbol symbolPoint=new FSymbol(FShape.POINT,Color.black); |
54 |
private Annotation_Layer capa;
|
55 |
/**
|
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 |
// }
|
213 |
|
214 |
|
215 |
public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
216 |
Cancellable cancel) { |
217 |
// Copia draw AttrInTableLabeling
|
218 |
Annotation_Legend l = (Annotation_Legend) capa.getLegend(); |
219 |
FSymbol sym = (FSymbol) l.getDefaultSymbol(); |
220 |
try {
|
221 |
ReadableVectorial source = capa.getSource(); |
222 |
// limit the labeling to the visible extent
|
223 |
FBitSet bs = capa.queryByRect(viewPort.getAdjustedExtent()); |
224 |
|
225 |
|
226 |
SelectableDataSource recordSet = source.getRecordset(); |
227 |
FBitSet bitSet=recordSet.getSelection(); |
228 |
FontMetrics metrics = g.getFontMetrics();
|
229 |
Annotation_Mapping mapping = ((Annotation_Layer) capa) |
230 |
.getAnnotatonMapping(); |
231 |
int idHeightField = mapping.getColumnHeight();
|
232 |
int idFontName = mapping.getColumnTypeFont();
|
233 |
int idFontStyle = mapping.getColumnStyleFont();
|
234 |
int idRotationField = mapping.getColumnRotate();
|
235 |
int idFontColor = mapping.getColumnColor();
|
236 |
int idTextField = mapping.getColumnText();
|
237 |
|
238 |
double rotation = 0D; |
239 |
double size = sym.getFont().getSize();
|
240 |
sym.setFontSizeInPixels(((Annotation_Layer)capa).isInPixels()); |
241 |
String fontName = "Dialog"; |
242 |
int fontStyle = sym.getFont().getStyle();
|
243 |
int fontColor = sym.getFontColor().getRGB();
|
244 |
for (int i = bs.nextSetBit(0); i >= 0; i = bs.nextSetBit(i + 1)) { |
245 |
if (cancel.isCanceled()){
|
246 |
break;
|
247 |
} |
248 |
Value[] vv = recordSet.getRow(i);
|
249 |
if (idHeightField != -1) { |
250 |
// text size is defined in the table
|
251 |
try {
|
252 |
size = ((NumericValue) vv[idHeightField]).doubleValue() |
253 |
* FConstant.FONT_HEIGHT_SCALE_FACTOR; |
254 |
} catch (ClassCastException ccEx) { |
255 |
if (!NullValue.class.equals(vv[idHeightField]
|
256 |
.getClass())) { |
257 |
// throw new ReadDriverException("Unknown", ccEx);
|
258 |
} |
259 |
// a null value
|
260 |
// Logger.getAnonymousLogger().
|
261 |
// warning("Null text height value for text
|
262 |
// '"+vv[idTextField].toString()+"'");
|
263 |
continue;
|
264 |
} |
265 |
} else {
|
266 |
// otherwise will use the size in the symbol
|
267 |
|
268 |
} |
269 |
|
270 |
// size = CartographicSupportToolkit.
|
271 |
// toScreenUnitYAxis(size,
|
272 |
// unit,
|
273 |
// viewPort
|
274 |
// );
|
275 |
|
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 |
// }
|
281 |
|
282 |
|
283 |
if (idFontName != -1) { |
284 |
fontName = ((StringValue) vv[idFontName]).toString(); |
285 |
} |
286 |
|
287 |
|
288 |
if (idFontStyle != -1) { |
289 |
fontStyle = ((NumericValue) vv[idFontStyle]).intValue(); |
290 |
} |
291 |
|
292 |
|
293 |
|
294 |
if (idRotationField != -1) { |
295 |
// text rotation is defined in the table
|
296 |
rotation = ((NumericValue) vv[idRotationField]) |
297 |
.doubleValue(); |
298 |
} |
299 |
|
300 |
|
301 |
if (idFontColor != -1) { |
302 |
// text rotation is defined in the table
|
303 |
fontColor = ((NumericValue) vv[idFontColor]).intValue(); |
304 |
sym.setFontColor(new Color(fontColor)); |
305 |
} |
306 |
|
307 |
if (bitSet.get(i)){
|
308 |
sym = (FSymbol)sym.getSymbolForSelection(); |
309 |
} |
310 |
IGeometry geom = source.getShape(i); |
311 |
|
312 |
sym.setFont(new Font(fontName, fontStyle, (int) size)); |
313 |
|
314 |
|
315 |
// sym.setDescription(vv[idTextField].toString());
|
316 |
// sym.setRotation((int) rotation);
|
317 |
FLabel[] aux = geom.createLabels(0, true); |
318 |
aux[0].setHeight(size);
|
319 |
aux[0].setRotation((int) rotation); |
320 |
aux[0].setString(vv[idTextField].toString());
|
321 |
if (sym.isShapeVisible()){
|
322 |
symbolPoint.draw((Graphics2D)g,viewPort.getAffineTransform(),new FPoint2D(viewPort.fromMapPoint(aux[0].getOrig()))); |
323 |
} |
324 |
FGraphicUtilities.DrawAnnotation(g, viewPort |
325 |
.getAffineTransform(), sym, aux[0], metrics, false); |
326 |
} |
327 |
} catch (Exception e) { |
328 |
// Logger.getAnonymousLogger().log(Level.SEVERE, "Could not get the
|
329 |
// layer extent.\n" +
|
330 |
// e.getMessage());
|
331 |
e.printStackTrace(); |
332 |
} |
333 |
|
334 |
// }
|
335 |
} |
336 |
|
337 |
|
338 |
|
339 |
|
340 |
|
341 |
|
342 |
|
343 |
|
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 |
} |
429 |
|
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 |
// }
|
441 |
|
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 |
*/
|
526 |
|
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); |
537 |
|
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;
|
574 |
|
575 |
case CROSSES:
|
576 |
m = jtsShape.relate(jtsGeom); |
577 |
if (m.isCrosses(jtsGeom.getDimension(), jtsShape.getDimension())) {
|
578 |
bitset.set(index, true);
|
579 |
} |
580 |
break;
|
581 |
|
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;
|
589 |
|
590 |
case EQUALS:
|
591 |
m = jtsShape.relate(jtsGeom); |
592 |
if (m.isEquals(jtsGeom.getDimension(), jtsShape.getDimension())) {
|
593 |
bitset.set(index, true);
|
594 |
} |
595 |
break;
|
596 |
|
597 |
case INTERSECTS:
|
598 |
m = jtsShape.relate(jtsGeom); |
599 |
if (m.isIntersects()) {
|
600 |
bitset.set(index, true);
|
601 |
} |
602 |
break;
|
603 |
|
604 |
case OVERLAPS:
|
605 |
m = jtsShape.relate(jtsGeom); |
606 |
if (m.isOverlaps(jtsGeom.getDimension(), jtsShape.getDimension()))
|
607 |
{ |
608 |
bitset.set(index, true);
|
609 |
} |
610 |
|
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) {
|
703 |
// TODO Auto-generated catch block
|
704 |
e.printStackTrace(); |
705 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
706 |
// TODO Auto-generated catch block
|
707 |
e.printStackTrace(); |
708 |
} |
709 |
return bitset;
|
710 |
|
711 |
} |
712 |
|
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 |
// }
|
743 |
} |