svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / layers / FLyrAnnotation.java @ 6763
History | View | Annotate | Download (15.7 KB)
1 | 4213 | caballero | package com.iver.cit.gvsig.fmap.layers; |
---|---|---|---|
2 | |||
3 | 4256 | caballero | import java.awt.Color; |
4 | 4296 | caballero | import java.awt.Font; |
5 | 4213 | caballero | import java.awt.Graphics2D; |
6 | import java.awt.geom.Point2D; |
||
7 | import java.awt.geom.Rectangle2D; |
||
8 | import java.awt.image.BufferedImage; |
||
9 | import java.io.File; |
||
10 | import java.io.IOException; |
||
11 | import java.util.ArrayList; |
||
12 | |||
13 | import org.cresques.cts.ICoordTrans; |
||
14 | import org.cresques.cts.IProjection; |
||
15 | |||
16 | import com.hardcode.driverManager.Driver; |
||
17 | import com.hardcode.driverManager.DriverLoadException; |
||
18 | 4296 | caballero | import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
19 | 4213 | caballero | import com.hardcode.gdbms.engine.values.DoubleValue; |
20 | 4296 | caballero | import com.hardcode.gdbms.engine.values.IntValue; |
21 | 4213 | caballero | import com.hardcode.gdbms.engine.values.NullValue; |
22 | 4256 | caballero | import com.hardcode.gdbms.engine.values.NumericValue; |
23 | import com.hardcode.gdbms.engine.values.StringValue; |
||
24 | 4213 | caballero | import com.hardcode.gdbms.engine.values.Value; |
25 | 4296 | caballero | import com.hardcode.gdbms.engine.values.ValueFactory; |
26 | 4213 | caballero | import com.iver.cit.gvsig.fmap.DriverException; |
27 | import com.iver.cit.gvsig.fmap.ViewPort; |
||
28 | import com.iver.cit.gvsig.fmap.core.IGeometry; |
||
29 | 4296 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
30 | 4213 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FLabel; |
31 | 4296 | caballero | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
32 | 6164 | luisw2 | import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
33 | 4213 | caballero | import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
34 | import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
||
35 | import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
||
36 | import com.iver.cit.gvsig.fmap.drivers.VectorialDriver; |
||
37 | 4316 | caballero | import com.iver.cit.gvsig.fmap.edition.AnnotationEditableAdapter; |
38 | 4213 | caballero | import com.iver.cit.gvsig.fmap.operations.strategies.AnnotationStrategy; |
39 | import com.iver.cit.gvsig.fmap.operations.strategies.Strategy; |
||
40 | import com.iver.cit.gvsig.fmap.operations.strategies.StrategyManager; |
||
41 | import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
||
42 | 4296 | caballero | import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
43 | 4978 | azabala | import com.iver.cit.gvsig.fmap.spatialindex.QuadtreeJts; |
44 | 4213 | caballero | import com.iver.utiles.XMLEntity; |
45 | 5317 | fjp | import com.iver.utiles.swing.threads.Cancellable; |
46 | 4213 | caballero | |
47 | /**
|
||
48 | * DOCUMENT ME!
|
||
49 | *
|
||
50 | * @author Vicente Caballero Navarro
|
||
51 | */
|
||
52 | public class FLyrAnnotation extends FLyrVect { |
||
53 | 4316 | caballero | private MappingAnnotation mapping = null; |
54 | 4296 | caballero | |
55 | 4213 | caballero | private ArrayList m_labels; |
56 | 4296 | caballero | |
57 | private int indexEditing = -1; |
||
58 | |||
59 | 4213 | caballero | private boolean inPixels; |
60 | 4296 | caballero | private VectorialUniqueValueLegend vuvl=new VectorialUniqueValueLegend(); |
61 | 4954 | caballero | private Strategy strategy=null; |
62 | 4296 | caballero | /**
|
63 | * Crea un nuevo FLyrAnnotation.
|
||
64 | */
|
||
65 | public FLyrAnnotation() {
|
||
66 | super();
|
||
67 | } |
||
68 | 4213 | caballero | |
69 | 4296 | caballero | /**
|
70 | * DOCUMENT ME!
|
||
71 | *
|
||
72 | * @param mapping
|
||
73 | * DOCUMENT ME!
|
||
74 | */
|
||
75 | 4316 | caballero | public void setMapping(MappingAnnotation mapping) { |
76 | 4296 | caballero | this.mapping = mapping;
|
77 | try {
|
||
78 | setLegend(); |
||
79 | 4213 | caballero | createLabels(); |
80 | } catch (DriverException e) {
|
||
81 | e.printStackTrace(); |
||
82 | } |
||
83 | 4296 | caballero | } |
84 | 4213 | caballero | |
85 | 4296 | caballero | /**
|
86 | * DOCUMENT ME!
|
||
87 | *
|
||
88 | * @return DOCUMENT ME!
|
||
89 | */
|
||
90 | 4316 | caballero | public MappingAnnotation getMapping() {
|
91 | 4296 | caballero | return mapping;
|
92 | } |
||
93 | 4213 | caballero | |
94 | 4296 | caballero | /**
|
95 | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#draw(java.awt.image.BufferedImage,
|
||
96 | * java.awt.Graphics2D, com.iver.cit.gvsig.fmap.ViewPort)
|
||
97 | */
|
||
98 | public void draw(BufferedImage image, Graphics2D g, ViewPort viewPort, |
||
99 | Cancellable cancel, double scale) throws DriverException { |
||
100 | if (isWithinScale(scale)) {
|
||
101 | // Las que solo tienen etiquetado sin pintar el shape,
|
||
102 | // no pasamos por ellas
|
||
103 | boolean bDrawShapes = true; |
||
104 | 4213 | caballero | |
105 | 4296 | caballero | if (bDrawShapes) {
|
106 | 4954 | caballero | if (strategy == null){ |
107 | strategy = (AnnotationStrategy) StrategyManager |
||
108 | .getStrategy(this);
|
||
109 | } |
||
110 | 4296 | caballero | try {
|
111 | g.setColor(Color.black);
|
||
112 | strategy.draw(image, g, viewPort, cancel); |
||
113 | 5098 | azabala | if (getISpatialIndex()==null) { |
114 | 4296 | caballero | createSpatialIndex(); |
115 | } |
||
116 | } catch (DriverException e) {
|
||
117 | this.setVisible(false); |
||
118 | this.setActive(false); |
||
119 | throw e;
|
||
120 | } |
||
121 | } |
||
122 | 4213 | caballero | |
123 | 4296 | caballero | if (getVirtualLayers() != null) { |
124 | getVirtualLayers().draw(image, g, viewPort, cancel, scale); |
||
125 | } |
||
126 | } |
||
127 | } |
||
128 | 4213 | caballero | |
129 | 4296 | caballero | /**
|
130 | * @see com.iver.cit.gvsig.fmap.layers.LayerOperations#getFullExtent()
|
||
131 | */
|
||
132 | public Rectangle2D getFullExtent() throws DriverException { |
||
133 | try {
|
||
134 | Rectangle2D rAux;
|
||
135 | 4213 | caballero | |
136 | 4296 | caballero | // logger.debug("source.start()");
|
137 | getSource().start(); |
||
138 | rAux = getSource().getFullExtent(); |
||
139 | 4213 | caballero | |
140 | 4296 | caballero | // logger.debug("source.stop()");
|
141 | getSource().stop(); |
||
142 | 4213 | caballero | |
143 | 4296 | caballero | // Si existe reproyecci?n, reproyectar el extent
|
144 | ICoordTrans ct = getCoordTrans(); |
||
145 | 4213 | caballero | |
146 | 4296 | caballero | if (ct != null) { |
147 | Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY()); |
||
148 | Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY()); |
||
149 | pt1 = ct.convert(pt1, null);
|
||
150 | pt2 = ct.convert(pt2, null);
|
||
151 | rAux = new Rectangle2D.Double(); |
||
152 | rAux.setFrameFromDiagonal(pt1, pt2); |
||
153 | } |
||
154 | 4213 | caballero | |
155 | 4296 | caballero | return rAux;
|
156 | } catch (DriverIOException e) {
|
||
157 | throw new DriverException(e); |
||
158 | } |
||
159 | } |
||
160 | 4213 | caballero | |
161 | 4296 | caballero | /**
|
162 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#print(java.awt.Graphics2D,
|
||
163 | * com.iver.cit.gvsig.fmap.ViewPort,
|
||
164 | 5317 | fjp | * com.iver.utiles.swing.threads.Cancellable)
|
165 | 4296 | caballero | */
|
166 | public void print(Graphics2D g, ViewPort viewPort, Cancellable cancel, |
||
167 | double scale) throws DriverException { |
||
168 | if (isVisible() && isWithinScale(scale)) {
|
||
169 | Strategy strategy = StrategyManager.getStrategy(this);
|
||
170 | strategy.print(g, viewPort, cancel); |
||
171 | } |
||
172 | } |
||
173 | 4213 | caballero | |
174 | 4296 | caballero | /*
|
175 | * (non-Javadoc)
|
||
176 | *
|
||
177 | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#queryByRect(java.awt.geom.Rectangle2D)
|
||
178 | */
|
||
179 | public FBitSet queryByRect(Rectangle2D rect) throws DriverException { |
||
180 | Strategy s = StrategyManager.getStrategy(this);
|
||
181 | 4213 | caballero | |
182 | 4296 | caballero | return s.queryByRect(rect);
|
183 | } |
||
184 | 4213 | caballero | |
185 | 4296 | caballero | /**
|
186 | * DOCUMENT ME!
|
||
187 | *
|
||
188 | * @param p
|
||
189 | * DOCUMENT ME!
|
||
190 | * @param tolerance
|
||
191 | * DOCUMENT ME!
|
||
192 | *
|
||
193 | * @return DOCUMENT ME!
|
||
194 | *
|
||
195 | * @throws DriverException
|
||
196 | * DOCUMENT ME!
|
||
197 | */
|
||
198 | public FBitSet queryByPoint(Point2D p, double tolerance) |
||
199 | throws DriverException {
|
||
200 | Strategy s = StrategyManager.getStrategy(this);
|
||
201 | 4213 | caballero | |
202 | 4296 | caballero | return s.queryByPoint(p, tolerance);
|
203 | } |
||
204 | 4213 | caballero | |
205 | 4296 | caballero | /**
|
206 | * DOCUMENT ME!
|
||
207 | *
|
||
208 | * @param g
|
||
209 | * DOCUMENT ME!
|
||
210 | * @param relationship
|
||
211 | * DOCUMENT ME!
|
||
212 | *
|
||
213 | * @return DOCUMENT ME!
|
||
214 | *
|
||
215 | * @throws DriverException
|
||
216 | * DOCUMENT ME!
|
||
217 | * @throws VisitException
|
||
218 | * DOCUMENT ME!
|
||
219 | */
|
||
220 | public FBitSet queryByShape(IGeometry g, int relationship) |
||
221 | throws DriverException, VisitException {
|
||
222 | Strategy s = StrategyManager.getStrategy(this);
|
||
223 | 4213 | caballero | |
224 | 4296 | caballero | return s.queryByShape(g, relationship);
|
225 | } |
||
226 | 4213 | caballero | |
227 | 4296 | caballero | /**
|
228 | * DOCUMENT ME!
|
||
229 | *
|
||
230 | * @return DOCUMENT ME!
|
||
231 | *
|
||
232 | * @throws XMLException
|
||
233 | *
|
||
234 | * @see com.iver.cit.gvsig.fmap.layers.FLayer#getProperties()
|
||
235 | */
|
||
236 | public XMLEntity getXMLEntity() throws XMLException { |
||
237 | XMLEntity xml = super.getXMLEntity();
|
||
238 | 4316 | caballero | xml.addChild(mapping.getXMLEntity()); |
239 | 4296 | caballero | xml.putProperty("isInPixels", isInPixels());
|
240 | 4213 | caballero | |
241 | 4296 | caballero | return xml;
|
242 | } |
||
243 | 4213 | caballero | |
244 | 4296 | caballero | /**
|
245 | * @see com.iver.cit.gvsig.fmap.layers.FLyrDefault#setXMLEntity(com.iver.utiles.XMLEntity)
|
||
246 | */
|
||
247 | public void setXMLEntity(XMLEntity xml) throws XMLException { |
||
248 | 4369 | caballero | mapping = MappingAnnotation.createFromXML(xml.getChild(2));//getIntArrayProperty("mapping"); |
249 | 4296 | caballero | setInPixels(xml.getBooleanProperty("isInPixels"));
|
250 | 4213 | caballero | |
251 | 4296 | caballero | IProjection proj = null;
|
252 | 4213 | caballero | |
253 | 4296 | caballero | if (xml.contains("proj")) { |
254 | 6164 | luisw2 | proj = CRSFactory.getCRS(xml.getStringProperty("proj"));
|
255 | 4296 | caballero | } |
256 | 4213 | caballero | |
257 | 4296 | caballero | VectorialFileAdapter adapter = new VectorialFileAdapter(new File(xml |
258 | .getStringProperty("file")));
|
||
259 | Driver d;
|
||
260 | 4213 | caballero | |
261 | 4296 | caballero | try {
|
262 | d = LayerFactory.getDM().getDriver( |
||
263 | xml.getStringProperty("driverName"));
|
||
264 | } catch (DriverLoadException e1) {
|
||
265 | throw new XMLException(e1); |
||
266 | } |
||
267 | 4213 | caballero | |
268 | 4296 | caballero | adapter.setDriver((VectorialDriver) d); |
269 | // TODO Meter esto dentro de la comprobaci?n de si hay memoria
|
||
270 | if (false) { |
||
271 | } else {
|
||
272 | setSource(adapter); |
||
273 | setProjection(proj); |
||
274 | } |
||
275 | 4213 | caballero | |
276 | 4296 | caballero | // Le asignamos tambi?n una legenda por defecto acorde con
|
277 | // el tipo de shape que tenga. Tampoco s? si es aqu? el
|
||
278 | // sitio adecuado, pero en fin....
|
||
279 | /*
|
||
280 | * if (d instanceof WithDefaultLegend) { WithDefaultLegend aux =
|
||
281 | * (WithDefaultLegend) d; adapter.start(); setLegend((VectorialLegend)
|
||
282 | * aux.getDefaultLegend()); adapter.stop(); } else {
|
||
283 | * setLegend(LegendFactory.createSingleSymbolLegend(getShapeType())); }
|
||
284 | */
|
||
285 | 4213 | caballero | |
286 | 4296 | caballero | super.setXMLEntity(xml);
|
287 | try {
|
||
288 | 4256 | caballero | createLabels(); |
289 | } catch (DriverException e) {
|
||
290 | // TODO Auto-generated catch block
|
||
291 | e.printStackTrace(); |
||
292 | } |
||
293 | 4296 | caballero | } |
294 | 4213 | caballero | |
295 | /**
|
||
296 | 4296 | caballero | * Esto tiene el fallo de que obligas a una etiqueta por entidad, para poder
|
297 | * evitar esto, una posible soluci?n ser?a que un FLabel pudiera ser una
|
||
298 | * colecci?n de FLabel (Patr?n Composite)
|
||
299 | *
|
||
300 | * @param lyrVect
|
||
301 | * @throws DriverException
|
||
302 | */
|
||
303 | public void createLabels() throws DriverException { |
||
304 | SelectableDataSource ds = getRecordset(); |
||
305 | FSymbol symbol; |
||
306 | try {
|
||
307 | ReadableVectorial adapter = getSource(); |
||
308 | adapter.start(); |
||
309 | ds.start(); |
||
310 | int sc;
|
||
311 | // El mapping[0] es el text
|
||
312 | 4316 | caballero | int fieldId = mapping.getColumnText();
|
313 | 4296 | caballero | // El mapping[1] es el ?ngulo
|
314 | 4316 | caballero | int idFieldRotationText = mapping.getColumnRotate();
|
315 | 4296 | caballero | // El mapping[2] es el color
|
316 | 4316 | caballero | int idFieldColorText = mapping.getColumnColor();
|
317 | 4296 | caballero | // El mapping[3] es el alto
|
318 | 4316 | caballero | int idFieldHeightText = mapping.getColumnHeight();
|
319 | 4296 | caballero | // El mapping[4] es el tipo de fuente
|
320 | 4316 | caballero | int idFieldTypeFontText = mapping.getColumnTypeFont();
|
321 | 4296 | caballero | // El mapping[5] es el estilo de fuente
|
322 | 4316 | caballero | int idFieldStyleFontText = mapping.getColumnStyleFont();
|
323 | 4213 | caballero | |
324 | 4296 | caballero | sc = (int) ds.getRowCount();
|
325 | m_labels = new ArrayList(sc); |
||
326 | DriverAttributes attr = adapter.getDriverAttributes(); |
||
327 | boolean bMustClone = false; |
||
328 | if (attr != null) { |
||
329 | if (attr.isLoadedInMemory()) {
|
||
330 | bMustClone = attr.isLoadedInMemory(); |
||
331 | } |
||
332 | } |
||
333 | ICoordTrans ct = getCoordTrans(); |
||
334 | for (int i = 0; i < sc; i++) { |
||
335 | IGeometry geom = adapter.getShape(i); |
||
336 | 4213 | caballero | |
337 | 4296 | caballero | if (geom == null) { |
338 | m_labels.add(null);
|
||
339 | continue;
|
||
340 | } |
||
341 | if (ct != null) { |
||
342 | if (bMustClone)
|
||
343 | geom = geom.cloneGeometry(); |
||
344 | geom.reProject(ct); |
||
345 | } |
||
346 | 4213 | caballero | |
347 | 4296 | caballero | // TODO: El m?todo contenedor (createLabelLayer) debe recoger
|
348 | // los par?metros de posicionamiento y de allowDuplicates
|
||
349 | // if (i >= 328)
|
||
350 | // System.out.println("i= " + i + " " + val.toString());
|
||
351 | //ArrayList values=new ArrayList(4);
|
||
352 | String t=new String(); |
||
353 | Value val = ds.getFieldValue(i, fieldId); |
||
354 | t=val.toString(); |
||
355 | //values.add(val);
|
||
356 | if (idFieldColorText!=-1){ |
||
357 | Value valColor=ds.getFieldValue(i,idFieldColorText); |
||
358 | t=t.concat(valColor.toString()); |
||
359 | //values.add(valColor);
|
||
360 | } |
||
361 | if (idFieldTypeFontText!=-1){ |
||
362 | Value valTypeFont=ds.getFieldValue(i,idFieldTypeFontText); |
||
363 | t=t.concat(valTypeFont.toString()); |
||
364 | //values.add(valTypeFont);
|
||
365 | } |
||
366 | 4213 | caballero | |
367 | 4296 | caballero | if (idFieldStyleFontText!=-1){ |
368 | Value valStyleFont=ds.getFieldValue(i,idFieldStyleFontText); |
||
369 | t=t.concat(valStyleFont.toString()); |
||
370 | //values.add(valStyleFont);
|
||
371 | } |
||
372 | //Value total=ValueFactory.createValue((Value[])values.toArray(new Value[0]));
|
||
373 | Value total=ValueFactory.createValue(t); |
||
374 | if ((val instanceof NullValue) || (val == null)) { |
||
375 | 6221 | caballero | m_labels.add(null);
|
376 | 4296 | caballero | continue;
|
377 | } |
||
378 | FLabel[] lbls = geom.createLabels(0, true); |
||
379 | 4213 | caballero | for (int j = 0; j < lbls.length; j++) { |
380 | if (lbls[j] != null) { |
||
381 | lbls[j].setString(val.toString()); |
||
382 | if (idFieldRotationText != -1) { |
||
383 | 4296 | caballero | DoubleValue rotation = (DoubleValue) ds |
384 | .getFieldValue(i, idFieldRotationText); |
||
385 | 4213 | caballero | lbls[j].setRotation(rotation.getValue()); |
386 | 4296 | caballero | } else {
|
387 | lbls[j].setRotation(getLegend().getDefaultSymbol() |
||
388 | .getRotation()); |
||
389 | 4213 | caballero | } |
390 | 4296 | caballero | |
391 | float height;
|
||
392 | 4256 | caballero | if (idFieldHeightText != -1) { |
393 | 4296 | caballero | NumericValue h = (NumericValue) ds |
394 | .getFieldValue(i, idFieldHeightText); |
||
395 | height=h.floatValue(); |
||
396 | lbls[j].setHeight(height); |
||
397 | } else {
|
||
398 | height=getLegend().getDefaultSymbol() |
||
399 | .getFontSize(); |
||
400 | lbls[j].setHeight(height); |
||
401 | 4256 | caballero | } |
402 | 4296 | caballero | |
403 | |||
404 | |||
405 | if (vuvl.getSymbolByValue(total)==null){ |
||
406 | Color color;
|
||
407 | if (idFieldColorText != -1) { |
||
408 | DoubleValue c = (DoubleValue) ds.getFieldValue( |
||
409 | i, idFieldColorText); |
||
410 | color=new Color((int) c.getValue()); |
||
411 | } else {
|
||
412 | color=getLegend().getDefaultSymbol() |
||
413 | .getFontColor(); |
||
414 | } |
||
415 | String typeFont;
|
||
416 | if (idFieldTypeFontText != -1) { |
||
417 | StringValue tf = (StringValue) ds |
||
418 | .getFieldValue(i, idFieldTypeFontText); |
||
419 | typeFont=tf.getValue(); |
||
420 | } else {
|
||
421 | typeFont=getLegend().getDefaultSymbol() |
||
422 | .getFont().getFontName(); |
||
423 | } |
||
424 | int style;
|
||
425 | if (idFieldStyleFontText != -1) { |
||
426 | IntValue sf = (IntValue) ds |
||
427 | .getFieldValue(i, idFieldStyleFontText); |
||
428 | style=sf.getValue(); |
||
429 | } else {
|
||
430 | style=getLegend().getDefaultSymbol() |
||
431 | .getFont().getStyle(); |
||
432 | } |
||
433 | symbol=new FSymbol(FConstant.SYMBOL_TYPE_TEXT);
|
||
434 | symbol.setFontSizeInPixels(isInPixels()); |
||
435 | symbol.setFont(new Font(typeFont,style,(int)height)); |
||
436 | symbol.setDescription(lbls[j].getString()); |
||
437 | symbol.setFontColor(color); |
||
438 | vuvl.addSymbol(total,symbol); |
||
439 | 4213 | caballero | } |
440 | 4256 | caballero | |
441 | 4213 | caballero | } |
442 | 4296 | caballero | m_labels.add(lbls[j]); |
443 | 4213 | caballero | |
444 | } |
||
445 | 4296 | caballero | } |
446 | 4213 | caballero | |
447 | 4296 | caballero | ds.stop(); |
448 | adapter.stop(); |
||
449 | } catch (DriverIOException e) {
|
||
450 | e.printStackTrace(); |
||
451 | throw new DriverException(e); |
||
452 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
453 | e.printStackTrace(); |
||
454 | throw new DriverException(e); |
||
455 | } |
||
456 | 4213 | caballero | |
457 | 4296 | caballero | } |
458 | 4213 | caballero | |
459 | public FLabel getLabel(int numReg) { |
||
460 | 4296 | caballero | if (m_labels == null || numReg == -1) |
461 | return null; |
||
462 | 4954 | caballero | if (getSource() instanceof AnnotationEditableAdapter){ |
463 | AnnotationEditableAdapter aea=((AnnotationEditableAdapter)getSource()); |
||
464 | return aea.getLabel(numReg,false); |
||
465 | } else
|
||
466 | return (FLabel)m_labels.get(numReg);
|
||
467 | 4213 | caballero | } |
468 | 4296 | caballero | |
469 | /*
|
||
470 | * (non-Javadoc)
|
||
471 | *
|
||
472 | 4213 | caballero | * @see com.iver.cit.gvsig.fmap.layers.layerOperations.RandomVectorialData#createIndex()
|
473 | */
|
||
474 | public void createSpatialIndex() { |
||
475 | 4296 | caballero | // FJP: ESTO HABR? QUE CAMBIARLO. PARA LAS CAPAS SECUENCIALES, TENDREMOS
|
476 | // QUE ACCEDER CON UN WHILE NEXT. (O mejorar lo de los FeatureVisitor
|
||
477 | // para que acepten recorrer sin geometria, solo con rectangulos.
|
||
478 | 5183 | caballero | |
479 | 4978 | azabala | //AZABALA: Como no tengo claro de donde se crean las capas de textos
|
480 | //el ?ndice espacial creado seguir? siendo el Quadtree en memoria
|
||
481 | //de JTS (QuadtreeJts es un adapter a nuestra api de indices)
|
||
482 | spatialIndex = new QuadtreeJts();
|
||
483 | 4296 | caballero | ReadableVectorial va = getSource(); |
484 | ICoordTrans ct = getCoordTrans(); |
||
485 | BoundedShapes shapeBounds = (BoundedShapes) va.getDriver(); |
||
486 | try {
|
||
487 | va.start(); |
||
488 | 4213 | caballero | |
489 | 4296 | caballero | for (int i = 0; i < va.getShapeCount(); i++) { |
490 | Rectangle2D r = null; |
||
491 | 4954 | caballero | FLabel label=getLabel(i); |
492 | if (label != null) { |
||
493 | r = label.getBoundBox(); |
||
494 | 4296 | caballero | } else {
|
495 | r = shapeBounds.getShapeBounds(i); |
||
496 | } |
||
497 | // TODO: MIRAR COMO SE TRAGAR?A ESTO LO DE LAS REPROYECCIONES
|
||
498 | if (ct != null) { |
||
499 | r = ct.convert(r); |
||
500 | } |
||
501 | if (r != null) { |
||
502 | 4978 | azabala | // Coordinate c1 = new Coordinate(r.getMinX(), r.getMinY());
|
503 | // Coordinate c2 = new Coordinate(r.getMaxX(), r.getMaxY());
|
||
504 | // Envelope env = new Envelope(c1, c2);
|
||
505 | // spatialIndex.insert(env, new Integer(i));
|
||
506 | spatialIndex.insert(r, i); |
||
507 | 4296 | caballero | } |
508 | } // for
|
||
509 | va.stop(); |
||
510 | } catch (DriverIOException e) {
|
||
511 | e.printStackTrace(); |
||
512 | } catch (IOException e) { |
||
513 | e.printStackTrace(); |
||
514 | } |
||
515 | 4213 | caballero | } |
516 | |||
517 | 4455 | fjp | public void setSelectedEditing() throws DriverException { |
518 | 4296 | caballero | FBitSet bitSet = getRecordset().getSelection(); |
519 | if (bitSet.cardinality() == 0) |
||
520 | return;
|
||
521 | indexEditing = bitSet.nextSetBit(0);
|
||
522 | } |
||
523 | 4213 | caballero | |
524 | public void setInPixels(boolean b) { |
||
525 | 4296 | caballero | inPixels = b; |
526 | 4213 | caballero | } |
527 | 4296 | caballero | |
528 | public boolean isInPixels() { |
||
529 | 4256 | caballero | return inPixels;
|
530 | } |
||
531 | 4226 | caballero | |
532 | public void setInEdition(int i) { |
||
533 | 4296 | caballero | indexEditing = i; |
534 | 4226 | caballero | |
535 | } |
||
536 | |||
537 | public int getInEdition() { |
||
538 | 4256 | caballero | return indexEditing;
|
539 | 4226 | caballero | } |
540 | 4256 | caballero | |
541 | public ArrayList getLabels() { |
||
542 | return m_labels;
|
||
543 | } |
||
544 | 4296 | caballero | |
545 | |||
546 | public void setLegend() { |
||
547 | try {
|
||
548 | getSource().getRecordset().start(); |
||
549 | 4316 | caballero | vuvl.setFieldName(getSource().getRecordset().getFieldName(mapping.getColumnText())); |
550 | 4296 | caballero | vuvl.setDefaultSymbol(new FSymbol(FConstant.SYMBOL_TYPE_TEXT));
|
551 | setLegend(vuvl); |
||
552 | getSource().getRecordset().stop(); |
||
553 | } catch (FieldNotFoundException e) {
|
||
554 | e.printStackTrace(); |
||
555 | } catch (DriverException e) {
|
||
556 | e.printStackTrace(); |
||
557 | } catch (DriverLoadException e) {
|
||
558 | e.printStackTrace(); |
||
559 | } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
||
560 | e.printStackTrace(); |
||
561 | } |
||
562 | |||
563 | } |
||
564 | 4619 | caballero | |
565 | 4954 | caballero | public Strategy getStrategy() {
|
566 | return strategy;
|
||
567 | 4619 | caballero | } |
568 | 4213 | caballero | } |