root / branches / Mobile_Compatible_Hito_1 / libFMap / src / es / prodevelop / gvsig / mobile / fmap / layer / FLyrVect.java @ 21606
History | View | Annotate | Download (20.5 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
/************************************************
|
42 |
* *
|
43 |
* Modfied By: *
|
44 |
* Prodevelop Integraci?n de Tecnolog?as SL *
|
45 |
* Conde Salvatierra de ?lava , 34-10 *
|
46 |
* 46004 Valencia *
|
47 |
* Spain *
|
48 |
* *
|
49 |
* +34 963 510 612 *
|
50 |
* +34 963 510 968 *
|
51 |
* gis@prodevelop.es *
|
52 |
* http://www.prodevelop.es *
|
53 |
* *
|
54 |
* gvSIG Mobile Team 2006 *
|
55 |
* *
|
56 |
************************************************/
|
57 |
|
58 |
package es.prodevelop.gvsig.mobile.fmap.layer; |
59 |
|
60 |
import java.awt.BasicStroke; |
61 |
import java.awt.Graphics2D; |
62 |
import java.awt.Point; |
63 |
import java.awt.Shape; |
64 |
import java.awt.geom.AffineTransform; |
65 |
import java.awt.geom.PathIterator; |
66 |
import java.awt.geom.Point2D; |
67 |
import java.awt.geom.Rectangle2D; |
68 |
import java.awt.image.BufferedImage; |
69 |
import java.io.IOException; |
70 |
import java.util.ArrayList; |
71 |
import java.util.BitSet; |
72 |
|
73 |
import org.apache.log4j.Logger; |
74 |
|
75 |
import com.hardcode.gdbms.engine.data.driver.DriverException; |
76 |
import com.hardcode.gdbms.engine.values.Value; |
77 |
|
78 |
import es.prodevelop.geodetic.utils.conversion.GeoUtils; |
79 |
import es.prodevelop.gvsig.mobile.fmap.core.FDot; |
80 |
import es.prodevelop.gvsig.mobile.fmap.core.FMultiPoint2D; |
81 |
import es.prodevelop.gvsig.mobile.fmap.core.FPoint2D; |
82 |
import es.prodevelop.gvsig.mobile.fmap.core.FPolygon2D; |
83 |
import es.prodevelop.gvsig.mobile.fmap.core.FPolyline2D; |
84 |
import es.prodevelop.gvsig.mobile.fmap.core.FShape; |
85 |
import es.prodevelop.gvsig.mobile.fmap.core.IGeometry; |
86 |
import es.prodevelop.gvsig.mobile.fmap.driver.BoundedShapes; |
87 |
import es.prodevelop.gvsig.mobile.fmap.driver.FMapDriverException; |
88 |
import es.prodevelop.gvsig.mobile.fmap.driver.VectorialDriver; |
89 |
import es.prodevelop.gvsig.mobile.fmap.legend.Legend; |
90 |
import es.prodevelop.gvsig.mobile.fmap.legend.LegendFactory; |
91 |
import es.prodevelop.gvsig.mobile.fmap.legend.VectorialLegend; |
92 |
import es.prodevelop.gvsig.mobile.fmap.symbol.FSymbol; |
93 |
import es.prodevelop.gvsig.mobile.fmap.util.Utils; |
94 |
import es.prodevelop.gvsig.mobile.fmap.util.cancel.Cancellable; |
95 |
import es.prodevelop.gvsig.mobile.fmap.util.graph2d.FBitSet; |
96 |
import es.prodevelop.gvsig.mobile.fmap.util.graph2d.Graph2DUtilities; |
97 |
import es.prodevelop.gvsig.mobile.fmap.viewport.ViewPort; |
98 |
|
99 |
/**
|
100 |
* Capa b?sica Vectorial.
|
101 |
*
|
102 |
* @author Fernando Gonz?lez Cort?s
|
103 |
*/
|
104 |
|
105 |
// TODO Cuando no sea para pruebas debe no ser public
|
106 |
public class FLyrVect extends FLyrDefault implements ClassifiableVectorial, |
107 |
SingleLayer, AlphanumericData, InfoByPoint { |
108 |
|
109 |
private static final int MAX_REQUESTED_IN_INFO = 5; |
110 |
|
111 |
private static Logger logger = Logger.getLogger(FLyrVect.class.getName()); |
112 |
private VectorialLegend legend;
|
113 |
private int typeShape = -1; |
114 |
private ReadableVectorial source;
|
115 |
private SelectableDataSource sds;
|
116 |
private SelectionSupport selectionSupport = new SelectionSupport(); |
117 |
|
118 |
public FLyrVect() {
|
119 |
id = System.currentTimeMillis();
|
120 |
} |
121 |
|
122 |
public ReadableVectorial getSource() {
|
123 |
if (!this.isAvailable()) return null; |
124 |
return source;
|
125 |
} |
126 |
|
127 |
public void setSource(ReadableVectorial rv) { |
128 |
source = rv; |
129 |
} |
130 |
|
131 |
public Rectangle2D getFullExtent() throws FMapDriverException { |
132 |
|
133 |
|
134 |
Rectangle2D rAux;
|
135 |
|
136 |
try {
|
137 |
source.start(); |
138 |
rAux = (Rectangle2D) source.getFullExtent().clone();
|
139 |
source.stop(); |
140 |
} catch (DriverException e) {
|
141 |
throw new FMapDriverException(e.getMessage()); |
142 |
} |
143 |
|
144 |
// Si existe reproyecci?n, reproyectar el extent
|
145 |
// ICoordTrans ct = getCoordTrans();
|
146 |
|
147 |
// if (ct != null) {
|
148 |
// Point2D pt1 = new Point2D.Double(rAux.getMinX(), rAux.getMinY());
|
149 |
// Point2D pt2 = new Point2D.Double(rAux.getMaxX(), rAux.getMaxY());
|
150 |
// pt1 = ct.convert(pt1, null);
|
151 |
// pt2 = ct.convert(pt2, null);
|
152 |
// rAux = new Rectangle2D.Double();
|
153 |
// rAux.setFrameFromDiagonal(pt1, pt2);
|
154 |
// }
|
155 |
|
156 |
//Esto es para cuando se crea una capa nueva con el fullExtent de ancho y alto 0.
|
157 |
if (rAux.getWidth()==0 && rAux.getHeight()==0) { |
158 |
rAux=new Rectangle2D.Double(0,0,100,100); |
159 |
} |
160 |
|
161 |
return rAux;
|
162 |
} |
163 |
|
164 |
public void drawSelected(Graphics2D g, ViewPort _vp, FSymbol sym) throws FMapDriverException { |
165 |
|
166 |
IGeometry ig = null;
|
167 |
Rectangle2D bb = null; |
168 |
|
169 |
BitSet sel = selectionSupport.getSelection();
|
170 |
AffineTransform aft = _vp.getAffineTransform();
|
171 |
|
172 |
try {
|
173 |
g.setStroke(new BasicStroke(sym.getStrokeWidth())); |
174 |
g.setColor(FSymbol.SELECTION_SYMBOL.getBorderColor()); |
175 |
|
176 |
for (int i = sel.nextSetBit(0); i >= 0; i = sel.nextSetBit(i+1)) { |
177 |
bb = getSource().getShapeBounds(i); |
178 |
if (Utils.rectanglesItersect(bb, _vp.getAdjustedExtent())) {
|
179 |
|
180 |
ig = getSource().getShape(i); |
181 |
if (ig == null) { |
182 |
logger.debug("ig es NULL: " + i);
|
183 |
continue;
|
184 |
} |
185 |
|
186 |
if (ig.getGeometryType() == FShape.POINT || ig.intersects(_vp.getAdjustedExtent())) {
|
187 |
ig.transform(aft); |
188 |
Shape shp = ig.getInternalShape();
|
189 |
Graph2DUtilities.drawShape(g, shp, FSymbol.SELECTION_SYMBOL); |
190 |
} |
191 |
} |
192 |
} |
193 |
} catch (Exception ex) { |
194 |
throw new FMapDriverException(ex.getMessage()); |
195 |
} |
196 |
} |
197 |
|
198 |
protected double angle=Math.PI/2; |
199 |
protected void drawPoints(Graphics2D g, ViewPort vp) throws FMapDriverException{ |
200 |
AffineTransform _at = vp.getAffineTransform();
|
201 |
int count = getSource().getShapeCount();
|
202 |
FSymbol sym = legend.getDefaultSymbol(); |
203 |
for (int i=0; i<count; i++) { |
204 |
try{
|
205 |
if (selectionSupport.isSelected(i)) {
|
206 |
continue; //sym = FSymbol.SELECTION_SYMBOL; |
207 |
} |
208 |
|
209 |
Rectangle2D bb = getSource().getShapeBounds(i);
|
210 |
|
211 |
if (Utils.rectanglesItersect(bb, vp.getAdjustedExtent())) {
|
212 |
IGeometry ig = getSource().getShape(i); |
213 |
|
214 |
ig.transform(_at); |
215 |
Shape shp = ig.getInternalShape();
|
216 |
//Graph2DUtilities.drawShape(g, shp, sym);
|
217 |
//Graph2DUtilities.drawPoint(g, (FPoint2D) shp);
|
218 |
Graph2DUtilities.drawPoint(g, (FPoint2D) shp); |
219 |
//Rectangle2D r2 = (Rectangle2D)ig.getBounds();
|
220 |
if (ig==null) |
221 |
logger.error("No hay bbox");
|
222 |
//RotationUtils.drawRotatedText(g,"Hola",Color.red,(int)r2.getMinX(),(int)r2.getMinY(),0.5);
|
223 |
/*RotationUtils.drawRotatedText(g,
|
224 |
"Hola",
|
225 |
Color.red,
|
226 |
(int)((FPoint2D) shp).getX(),
|
227 |
(int)((FPoint2D) shp).getY(),
|
228 |
angle);
|
229 |
angle-=0.1;*/
|
230 |
} |
231 |
} catch (Exception e){ |
232 |
logger.error("drawPoints: ", e);
|
233 |
} |
234 |
} |
235 |
} |
236 |
protected void drawMultiPoints(Graphics2D g, ViewPort vp) throws FMapDriverException{ |
237 |
AffineTransform _at = vp.getAffineTransform();
|
238 |
int count = getSource().getShapeCount();
|
239 |
FSymbol sym = legend.getDefaultSymbol(); |
240 |
for (int i=0; i<count; i++) { |
241 |
try{
|
242 |
if (selectionSupport.isSelected(i)) {
|
243 |
continue; //sym = FSymbol.SELECTION_SYMBOL; |
244 |
} |
245 |
|
246 |
Rectangle2D bb = getSource().getShapeBounds(i);
|
247 |
|
248 |
if (Utils.rectanglesItersect(bb, vp.getAdjustedExtent())) {
|
249 |
IGeometry ig = getSource().getShape(i); |
250 |
ig.transform(_at); |
251 |
Shape shp = ig.getInternalShape();
|
252 |
//Graph2DUtilities.drawShape(g, shp, sym);
|
253 |
//Graph2DUtilities.drawPoint(g, (FPoint2D) shp);
|
254 |
Graph2DUtilities.drawMultiPoint(g, (FMultiPoint2D) shp); |
255 |
} |
256 |
} catch (Exception e){ |
257 |
logger.error("drawPoints: ", e);
|
258 |
} |
259 |
} |
260 |
} |
261 |
|
262 |
protected void drawLines(Graphics2D g, ViewPort vp) throws FMapDriverException{ |
263 |
AffineTransform _at = vp.getAffineTransform();
|
264 |
int count = getSource().getShapeCount();
|
265 |
FSymbol sym = legend.getDefaultSymbol(); |
266 |
for (int i=0; i<count; i++) { |
267 |
try{
|
268 |
if (selectionSupport.isSelected(i)) {
|
269 |
continue; //sym = FSymbol.SELECTION_SYMBOL; |
270 |
} |
271 |
|
272 |
Rectangle2D bb = getSource().getShapeBounds(i);
|
273 |
|
274 |
if (Utils.rectanglesItersect(bb, vp.getAdjustedExtent())) {
|
275 |
|
276 |
IGeometry ig = getSource().getShape(i); |
277 |
if (ig == null) { |
278 |
//logger.debug("ig es NULL: " + i);
|
279 |
continue;
|
280 |
} |
281 |
|
282 |
double[] xs = {bb.getMinX(),bb.getMaxX()}; |
283 |
double[] ys = {bb.getMinY(),bb.getMaxY()}; |
284 |
FMultiPoint2D gbb = new FMultiPoint2D(xs,ys);
|
285 |
gbb.transform(_at); |
286 |
Rectangle2D bb2 = gbb.getBounds2D();
|
287 |
|
288 |
if(bb2.getWidth() < 2 && bb2.getHeight()<2){ |
289 |
//If shape size is only a pixel size we paint only a pixel
|
290 |
FDot pt = new FDot(bb2.getMinX(),bb2.getMinY());
|
291 |
Graph2DUtilities.drawDot(g, pt); |
292 |
} /*else if(bb2.getWidth() < 2 || bb2.getHeight()<2){
|
293 |
g.drawLine(
|
294 |
(int)Math.round(bb2.getMinX()),
|
295 |
(int)Math.round(bb2.getMinY()),
|
296 |
(int)Math.round(bb2.getMaxX()),
|
297 |
(int)Math.round(bb2.getMaxY()));
|
298 |
}*/ else if (ig.intersects(vp.getAdjustedExtent())) { |
299 |
ig.transform(_at); |
300 |
Shape shp = ig.getInternalShape();
|
301 |
//Graph2DUtilities.drawShape(g, shp, sym);
|
302 |
Graph2DUtilities.drawPolyLine(g, (FPolyline2D)shp); |
303 |
} |
304 |
} |
305 |
} catch (Exception e){ |
306 |
logger.error(e); |
307 |
} |
308 |
} |
309 |
} |
310 |
|
311 |
protected void drawPolygons(Graphics2D g, ViewPort vp) throws FMapDriverException{ |
312 |
AffineTransform _at = vp.getAffineTransform();
|
313 |
int count = getSource().getShapeCount();
|
314 |
FSymbol sym = legend.getDefaultSymbol(); |
315 |
boolean fill = sym.isFilled();
|
316 |
for (int i=0; i<count; i++) { |
317 |
try{
|
318 |
if (selectionSupport.isSelected(i)) {
|
319 |
continue; //sym = FSymbol.SELECTION_SYMBOL; |
320 |
} |
321 |
|
322 |
Rectangle2D bb = getSource().getShapeBounds(i);
|
323 |
|
324 |
if (Utils.rectanglesItersect(bb, vp.getAdjustedExtent())) {
|
325 |
|
326 |
IGeometry ig = getSource().getShape(i); |
327 |
if (ig == null) { |
328 |
logger.debug("ig es NULL: " + i);
|
329 |
continue;
|
330 |
} |
331 |
|
332 |
double[] xs = {bb.getMinX(),bb.getMaxX()}; |
333 |
double[] ys = {bb.getMinY(),bb.getMaxY()}; |
334 |
FMultiPoint2D gbb = new FMultiPoint2D(xs,ys);
|
335 |
gbb.transform(_at); |
336 |
Rectangle2D bb2 = gbb.getBounds2D();
|
337 |
|
338 |
|
339 |
if(bb2.getWidth() < 1 && bb2.getHeight()<1){ |
340 |
//If shape size is only a pixel size we paint only a pixel
|
341 |
FDot pt = new FDot(bb2.getMinX(),bb2.getMinY());
|
342 |
Graph2DUtilities.drawDot(g, pt); |
343 |
}else if(bb2.getWidth()*bb2.getHeight()<6){ |
344 |
if (fill)
|
345 |
g.fillRect( |
346 |
(int)bb2.getMinX(),
|
347 |
(int)bb2.getMinY(),
|
348 |
(int)Math.round(bb2.getWidth()), |
349 |
(int)Math.round(bb2.getHeight())); |
350 |
else
|
351 |
g.drawRect( |
352 |
(int)bb2.getMinX(),
|
353 |
(int)bb2.getMinY(),
|
354 |
(int)Math.round(bb2.getWidth()), |
355 |
(int)Math.round(bb2.getHeight())); |
356 |
} else if (ig.intersects(vp.getAdjustedExtent())) { |
357 |
if (fill && (bb2.getWidth() < 3 || bb2.getHeight()<3)){ |
358 |
//If shape interior is not seen we do not paint it
|
359 |
sym.setFilled(false);
|
360 |
} |
361 |
ig.transform(_at); |
362 |
Shape shp = ig.getInternalShape();
|
363 |
Graph2DUtilities.drawPolygon(g, (FPolygon2D)shp, sym); |
364 |
} |
365 |
sym.setFilled(fill); |
366 |
} else{
|
367 |
//logger.debug("No intersecto");
|
368 |
} |
369 |
} catch (Exception e) { |
370 |
logger.error(e); |
371 |
} |
372 |
} |
373 |
|
374 |
} |
375 |
|
376 |
public void draw(Graphics2D g, ViewPort vp) throws FMapDriverException { |
377 |
|
378 |
logger.debug("Empieza draw de FLyrVect: " + getName());
|
379 |
|
380 |
double scale = vp.getScale();
|
381 |
|
382 |
if (isWithinScale(scale)) {
|
383 |
|
384 |
AffineTransform _at = vp.getAffineTransform();
|
385 |
int count = getSource().getShapeCount();
|
386 |
|
387 |
try {
|
388 |
FSymbol sym = legend.getDefaultSymbol(); |
389 |
IGeometry ig = null;
|
390 |
g.setColor(sym.getBorderColor()); |
391 |
g.setStroke(new BasicStroke(sym.getStrokeWidth())); |
392 |
|
393 |
int lyrType = getSource().getShape(0).getGeometryType(); |
394 |
|
395 |
switch (lyrType){
|
396 |
case FShape.POINT:
|
397 |
drawPoints(g,vp); |
398 |
break;
|
399 |
case FShape.MULTIPOINT:
|
400 |
drawMultiPoints(g,vp); |
401 |
break;
|
402 |
case FShape.LINE:
|
403 |
drawLines(g,vp); |
404 |
break;
|
405 |
case FShape.POLYGON:
|
406 |
drawPolygons(g,vp); |
407 |
break;
|
408 |
|
409 |
} |
410 |
/*
|
411 |
for (int i=0; i<count; i++) {
|
412 |
|
413 |
//logger.debug("Init: " + Utils.time());
|
414 |
if (selectionSupport.isSelected(i)) {
|
415 |
continue; //sym = FSymbol.SELECTION_SYMBOL;
|
416 |
}
|
417 |
//logger.debug("1: " + Utils.time());
|
418 |
|
419 |
Rectangle2D bb = getSource().getShapeBounds(i);
|
420 |
//logger.debug("2: " + Utils.time());
|
421 |
if (Utils.rectanglesItersect(bb, vp.getAdjustedExtent())) {
|
422 |
//logger.debug("3: " + Utils.time());
|
423 |
ig = getSource().getShape(i);
|
424 |
//logger.debug("4: " + Utils.time());
|
425 |
if (ig == null) {
|
426 |
//logger.debug("ig es NULL: " + i);
|
427 |
continue;
|
428 |
}
|
429 |
//logger.debug("5: " + Utils.time());
|
430 |
|
431 |
//[jcarras] Performance modifications
|
432 |
|
433 |
boolean fill = sym.isFilled();
|
434 |
|
435 |
double[] xs = {bb.getMinX(),bb.getMaxX()};
|
436 |
double[] ys = {bb.getMinY(),bb.getMaxY()};
|
437 |
//logger.debug("6: " + Utils.time());
|
438 |
FMultiPoint2D gbb = new FMultiPoint2D(xs,ys);//15
|
439 |
//logger.debug("7: " + Utils.time());
|
440 |
gbb.transform(_at);
|
441 |
//logger.debug("8: " + Utils.time());
|
442 |
Rectangle2D bb2 = gbb.getBounds2D();//47
|
443 |
//logger.debug("9: " + Utils.time());
|
444 |
|
445 |
if (fill && (bb2.getWidth() < 2 || bb2.getHeight()<2)){
|
446 |
//If shape interior is not seen we do not paint it
|
447 |
sym.setFilled(false);
|
448 |
}
|
449 |
//logger.debug("10: " + Utils.time());
|
450 |
if(ig.getGeometryType() != FShape.POINT && bb2.getWidth() < 1 && bb2.getHeight()<1){
|
451 |
//If shape size is only a pixel size we paint only a pixel
|
452 |
FDot pt = new FDot(bb2.getMinX(),bb2.getMinY());
|
453 |
//logger.debug("11: " + Utils.time());
|
454 |
Graph2DUtilities.drawShape(g, pt, sym);
|
455 |
//logger.debug("12: " + Utils.time());
|
456 |
} else {
|
457 |
//logger.debug("13: " + Utils.time());
|
458 |
if (ig.getGeometryType() == FShape.POINT || ig.intersects(vp.getAdjustedExtent())) {
|
459 |
ig.transform(_at);
|
460 |
//logger.debug("14: " + Utils.time());
|
461 |
Shape shp = ig.getInternalShape();
|
462 |
//logger.debug("15: " + Utils.time());
|
463 |
Graph2DUtilities.drawShape(g, shp, sym); //15
|
464 |
//logger.debug("16: " + Utils.time());
|
465 |
}
|
466 |
}
|
467 |
|
468 |
sym.setFilled(fill);
|
469 |
//logger.debug("17: " + Utils.time());
|
470 |
} else{
|
471 |
//logger.debug("No intersecto");
|
472 |
}
|
473 |
}*/
|
474 |
|
475 |
drawSelected(g, vp, sym); |
476 |
//logger.debug("18: " + Utils.time());
|
477 |
} catch (Exception e) { |
478 |
logger.error("Error while drawing vect layer: " + e.getMessage());
|
479 |
} |
480 |
} |
481 |
} |
482 |
|
483 |
private void prepareDrawing(BufferedImage image, Graphics2D g, ViewPort viewPort) { |
484 |
|
485 |
} |
486 |
|
487 |
public FBitSet queryByPoint(Point2D p, double tolerance) |
488 |
throws FMapDriverException {
|
489 |
|
490 |
return null; |
491 |
} |
492 |
|
493 |
public ArrayList getInfo(Point p, double tolerance, Cancellable cancel, String srs) throws FMapDriverException { |
494 |
Point2D pReal = this.getMapContext().getViewPort().toMapPoint( |
495 |
new Point2D.Double(p.x, p.y) |
496 |
); |
497 |
|
498 |
VectorialDriver vd = source.getDriver(); |
499 |
int[] intersect_indices = null; |
500 |
ArrayList resp = new ArrayList(); |
501 |
resp.add("[No data]"); resp.add(null); |
502 |
|
503 |
if (vd instanceof BoundedShapes) { |
504 |
|
505 |
Rectangle2D click_rect = new Rectangle2D.Double( |
506 |
pReal.getX() - 0.5 * tolerance,
|
507 |
pReal.getY() - 0.5 * tolerance,
|
508 |
tolerance, tolerance); |
509 |
|
510 |
try {
|
511 |
intersect_indices = ((BoundedShapes) vd).getIntersectingIndices(click_rect, MAX_REQUESTED_IN_INFO); |
512 |
} catch (IOException e) { |
513 |
logger.error("While computing intersecting indices: " + e.getMessage());
|
514 |
throw new FMapDriverException(e.getMessage()); |
515 |
} |
516 |
|
517 |
if (intersect_indices == null) return resp; |
518 |
|
519 |
SelectableDataSource sds = getRecordset(); |
520 |
try {
|
521 |
String[] f_names = sds.getFieldNames(); |
522 |
|
523 |
for (int i=0; i<intersect_indices.length; i++) { |
524 |
if (i == 0) resp.clear(); |
525 |
|
526 |
resp.add(""); resp.add(null); // empty row before item |
527 |
|
528 |
Value[] atts = sds.getRow(intersect_indices[i]);
|
529 |
ArrayList geom_data = getGeometryMetadata(intersect_indices[i], srs);
|
530 |
Utils.addAttributesToList(atts, f_names, geom_data, resp); |
531 |
} |
532 |
|
533 |
} catch (DriverException dex) {
|
534 |
resp.add("Error:");
|
535 |
resp.add(dex.getMessage().substring(0, 20) + "..."); |
536 |
} |
537 |
} |
538 |
|
539 |
return resp;
|
540 |
|
541 |
} |
542 |
|
543 |
private ArrayList getGeometryMetadata(int i, String srs) { |
544 |
|
545 |
ArrayList resp = new ArrayList(); |
546 |
double[] tot_last = null; |
547 |
|
548 |
VectorialDriver vd = source.getDriver(); |
549 |
IGeometry ig = null;
|
550 |
try {
|
551 |
ig = vd.getShape(i); |
552 |
} catch (Exception ex) { |
553 |
logger.debug("Error: " + ex.getMessage());
|
554 |
} |
555 |
|
556 |
int _type = ig.getGeometryType();
|
557 |
|
558 |
switch (_type) {
|
559 |
|
560 |
case FShape.MULTIPOINT:
|
561 |
resp.add("Points"); resp.add(null); |
562 |
FMultiPoint2D mp = (FMultiPoint2D) ig.getInternalShape(); |
563 |
for (int n=0; n<mp.getNumPoints(); n++) { |
564 |
FPoint2D p = mp.getPoint(n); |
565 |
resp.add("[" + Utils.getFormattedDouble(p.getX(), 3) + ", "); |
566 |
resp.add(Utils.getFormattedDouble(p.getY(), 3) + "]"); |
567 |
} |
568 |
break;
|
569 |
|
570 |
case FShape.POINT:
|
571 |
resp.add("Point"); resp.add(null); |
572 |
FPoint2D p = (FPoint2D) ig.getInternalShape(); |
573 |
resp.add("[" + Utils.getFormattedDouble(p.getX(), 3) + ", "); |
574 |
resp.add(Utils.getFormattedDouble(p.getY(), 3) + "]"); |
575 |
break;
|
576 |
|
577 |
case FShape.LINE:
|
578 |
resp.add("Line"); resp.add(null); |
579 |
FPolyline2D l = (FPolyline2D) ig.getInternalShape(); |
580 |
resp.add("Length");
|
581 |
|
582 |
tot_last = GeoUtils.getIteratorLengthAndLast(l.getPathIterator(Utils.IDENTITY_AT), srs); |
583 |
if (tot_last == null) { |
584 |
resp.add("[Error]");
|
585 |
} else {
|
586 |
resp.add(Utils.getFormattedDouble(tot_last[0], 3) + " m"); |
587 |
} |
588 |
|
589 |
break;
|
590 |
|
591 |
case FShape.POLYGON:
|
592 |
resp.add("Polygon"); resp.add(null); |
593 |
FPolygon2D pol = (FPolygon2D) ig.getInternalShape(); |
594 |
|
595 |
PathIterator pitr = pol.getPathIterator(Utils.IDENTITY_AT);
|
596 |
resp.add("Perimeter");
|
597 |
|
598 |
tot_last = GeoUtils.getIteratorLengthAndLast(pitr, srs); |
599 |
if (tot_last == null) { |
600 |
resp.add("[Error]");
|
601 |
} else {
|
602 |
resp.add(Utils.getFormattedDouble(tot_last[0], 3) + " m"); |
603 |
} |
604 |
|
605 |
pitr = pol.getPathIterator(Utils.IDENTITY_AT); |
606 |
resp.add("Area");
|
607 |
|
608 |
double a = GeoUtils.getAreaInSquareMeters(pitr, srs);
|
609 |
String units = " sq m"; |
610 |
int prec = 2; |
611 |
if (a >= GeoUtils.SQ_METERS_LIMIT) {
|
612 |
a = a / 1000000;
|
613 |
units = " sq km";
|
614 |
} |
615 |
resp.add(Utils.getFormattedDouble(a, prec) + units); |
616 |
break;
|
617 |
} |
618 |
return resp;
|
619 |
} |
620 |
|
621 |
public void setLegend(VectorialLegend r) { |
622 |
|
623 |
legend = r; |
624 |
} |
625 |
|
626 |
public Legend getLegend() {
|
627 |
return legend;
|
628 |
} |
629 |
|
630 |
|
631 |
public int getShapeType() throws FMapDriverException { |
632 |
if (typeShape == -1) { |
633 |
try {
|
634 |
getSource().start(); |
635 |
typeShape = getSource().getShapeType(); |
636 |
getSource().stop(); |
637 |
} catch (DriverException e) {
|
638 |
throw new FMapDriverException(e.getMessage()); |
639 |
} |
640 |
} |
641 |
return typeShape;
|
642 |
} |
643 |
/*
|
644 |
public XMLEntity getXMLEntity() throws XMLException {
|
645 |
return null;
|
646 |
}*/
|
647 |
/*
|
648 |
public void setXMLEntity(XMLEntity xml) throws XMLException {
|
649 |
}*/
|
650 |
|
651 |
|
652 |
public String toString() { |
653 |
|
654 |
String ret = super.toString(); |
655 |
|
656 |
return "layer" + ret.substring(ret.indexOf('@') + 1); |
657 |
} |
658 |
|
659 |
public SelectableDataSource getRecordset() throws FMapDriverException { |
660 |
|
661 |
if (!isAvailable()) {
|
662 |
logger.debug("isAvailable() = FALSE, se devuelve null");
|
663 |
return null; |
664 |
} |
665 |
|
666 |
if (sds == null) { |
667 |
|
668 |
SelectableDataSource ds = source.getRecordset(); |
669 |
|
670 |
if (ds == null) { |
671 |
return null; |
672 |
} |
673 |
|
674 |
sds = ds; |
675 |
sds.setSelectionSupport(selectionSupport); |
676 |
|
677 |
} |
678 |
return sds;
|
679 |
} |
680 |
|
681 |
public void setRecordset(SelectableDataSource newSds) { |
682 |
sds = newSds; |
683 |
|
684 |
if (sds != null) { |
685 |
sds.setSelectionSupport(selectionSupport); |
686 |
} |
687 |
} |
688 |
|
689 |
public boolean isPropertiesMenuVisible(){ |
690 |
return true; |
691 |
} |
692 |
|
693 |
public void reload() throws FMapDriverException { |
694 |
super.reload();
|
695 |
try {
|
696 |
source.getDriver().reload(); |
697 |
} catch (Exception e) { |
698 |
throw new FMapDriverException(e.getMessage()); |
699 |
} |
700 |
if (this.getLegend() == null) |
701 |
setLegend(LegendFactory.createSingleSymbolLegend()); |
702 |
} |
703 |
|
704 |
public boolean isWritable() { |
705 |
return false; |
706 |
} |
707 |
|
708 |
public void wakeUp(boolean driver_is_already_open) { |
709 |
} |
710 |
|
711 |
public long getId() { |
712 |
return id;
|
713 |
} |
714 |
|
715 |
public StringBuffer toXML(String name, String projectPath) { |
716 |
StringBuffer buff = new StringBuffer(); |
717 |
buff.append("<" + name +">\n"); |
718 |
|
719 |
|
720 |
buff.append("</" + name +">\n"); |
721 |
return buff;
|
722 |
} |
723 |
|
724 |
public void clean() { |
725 |
logger.warn("This cleaning method is EMPTY. Subclasses should override it!");
|
726 |
} |
727 |
|
728 |
} |