Revision 28223

View differences:

trunk/extensions/extDerivedGeometries/.classpath
15 15
	<classpathentry kind="lib" path="/libFMap/lib/driver-manager-1.1.jar" sourcepath="/libDriverManager"/>
16 16
	<classpathentry kind="lib" path="/libFMap/lib/jts-1.9.jar"/>
17 17
	<classpathentry kind="lib" path="/_fwAndami/lib/log4j-1.2.8.jar"/>
18
	<classpathentry combineaccessrules="false" kind="src" path="/extQuickInfo"/>
19 18
	<classpathentry kind="output" path="bin"/>
20 19
</classpath>
trunk/extensions/extDerivedGeometries/src/es/iver/derivedGeom/utils/FShapeTypeNames.java
1
package es.iver.derivedGeom.utils;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

  
25
import com.iver.andami.PluginServices;
26
import com.iver.cit.gvsig.fmap.core.FShape;
27

  
28
/**
29
 * <p>Utility to convert a shape type in its representation in characters.</p>
30
 * 
31
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
32
 */
33
public class FShapeTypeNames {
34
	/**
35
	 * <p>Returns an <code>String</code> that represents a <code>FShape</code> type.</p>
36
	 * 
37
	 * @param type a type defined in {@link FShape FShape}
38
	 * @return an <code>String</code> that represents the type
39
	 */
40
	public static String getFShapeTypeName(int type) {
41
		switch(type) {
42
			case FShape.NULL:
43
				return "NULL";
44
			case FShape.POINT:
45
				return PluginServices.getText(null, "POINT");
46
			case FShape.LINE:
47
				return PluginServices.getText(null, "LINE");
48
			case FShape.POLYGON:
49
				return PluginServices.getText(null, "POLYGON");
50
			case FShape.TEXT:
51
				return PluginServices.getText(null, "TEXT");
52
			case FShape.MULTI:
53
				return PluginServices.getText(null, "MULTI");
54
			case FShape.MULTIPOINT:
55
				return PluginServices.getText(null, "MULTIPOINT");
56
			case FShape.CIRCLE:
57
				return PluginServices.getText(null, "CIRCLE");
58
			case FShape.ARC:
59
				return PluginServices.getText(null, "ARC");
60
			case FShape.ELLIPSE:
61
				return PluginServices.getText(null, "ELLIPSE");
62
			case FShape.Z:
63
				return "Z";
64
			default:
65
				return PluginServices.getText(null, "UNKNOWN");
66
		}
67
	}
68
}
0 69

  
trunk/extensions/extDerivedGeometries/src/es/iver/derivedGeom/gui/AddGeometricInfoPanel.java
71 71
import org.gvsig.gui.beans.progresspanel.ProgressPanel;
72 72
import org.gvsig.gui.beans.specificcaretposition.JTextFieldWithSCP;
73 73
import org.gvsig.gui.javax.swing.jLabelCellRenderer.JLabelCellRenderer;
74
import org.gvsig.quickInfo.utils.FShapeTypeNames;
75 74

  
76 75
import com.hardcode.gdbms.driver.exceptions.InitializeDriverException;
77 76
import com.hardcode.gdbms.driver.exceptions.InitializeWriterException;
78 77
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
78
import com.hardcode.gdbms.engine.data.driver.DriverException;
79 79
import com.iver.andami.PluginServices;
80 80
import com.iver.andami.messages.NotificationManager;
81 81
import com.iver.andami.ui.mdiManager.IWindow;
......
102 102
import com.iver.utiles.swing.JComboBox;
103 103

  
104 104
import es.iver.derivedGeom.process.AddGeometricInfoProcess;
105
import es.iver.derivedGeom.utils.FShapeTypeNames;
105 106
import es.iver.derivedGeom.utils.GeomInfo;
106 107
import es.iver.derivedGeom.utils.GeomInfoFactory;
107 108
import es.iver.derivedGeom.utils.StringUtilitiesExtended;
trunk/extensions/extDerivedGeometries/src/es/iver/derivedGeom/gui/LayerAndProcessSelectionPanel.java
54 54

  
55 55
import org.gvsig.gui.beans.AcceptCancelPanel;
56 56
import org.gvsig.gui.beans.specificcaretposition.JTextFieldWithSCP;
57
import org.gvsig.quickInfo.gui.QuickInfoDataSelectionPanel;
58
import org.gvsig.quickInfo.utils.FShapeTypeNames;
59 57

  
60 58
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
61 59
import com.iver.andami.PluginServices;
......
71 69
import com.iver.utiles.SimpleFileFilter;
72 70

  
73 71
import es.iver.derivedGeom.process.DerivedGeometryProcessParameters;
72
import es.iver.derivedGeom.utils.FShapeTypeNames;
74 73

  
75 74
/**
76 75
 * 
trunk/extensions/extDerivedGeometries/src/es/iver/derivedGeom/process/AddDerivedGeometrySHPProcess.java
36 36
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent;
37 37
import org.gvsig.gui.beans.incrementabletask.IncrementableProcess;
38 38
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
39
import org.gvsig.quickInfo.utils.geometries.GeometryUtilities;
40 39

  
41 40
import com.hardcode.gdbms.engine.values.Value;
42 41
import com.hardcode.gdbms.engine.values.ValueFactory;
......
50 49
import com.iver.cit.gvsig.fmap.core.DefaultFeature;
51 50
import com.iver.cit.gvsig.fmap.core.FPoint2D;
52 51
import com.iver.cit.gvsig.fmap.core.FShape;
52
import com.iver.cit.gvsig.fmap.core.GeometryUtilities;
53 53
import com.iver.cit.gvsig.fmap.core.IGeometry;
54 54
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
55 55
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
trunk/extensions/extDerivedGeometries/src/es/iver/derivedGeom/process/AddGeometricInfoProcess.java
37 37
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
38 38
import org.gvsig.gui.beans.incrementabletask.IncrementableProcess;
39 39
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
40
import org.gvsig.quickInfo.utils.geometries.GeometryInfo;
41
import org.gvsig.quickInfo.utils.geometries.GeometryUtilities;
42 40

  
43 41
import com.hardcode.gdbms.engine.values.Value;
44 42
import com.hardcode.gdbms.engine.values.ValueFactory;
......
55 53
import com.iver.cit.gvsig.fmap.core.FPoint2D;
56 54
import com.iver.cit.gvsig.fmap.core.FPoint3D;
57 55
import com.iver.cit.gvsig.fmap.core.FShape;
56
import com.iver.cit.gvsig.fmap.core.GeometryUtilities;
58 57
import com.iver.cit.gvsig.fmap.core.IGeometry;
59 58
import com.iver.cit.gvsig.fmap.drivers.FieldDescription;
60 59
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition;
......
327 326
			percentage = 33;
328 327

  
329 328
			GeomInfo field;
330
			GeometryInfo gInfo;
329
//			GeometryInfo gInfo;
331 330
			AddedFieldInfo addedField = null;
332 331
			int i, j;
333 332
			String operationName = PluginServices.getText(null, "setGeomInfo_");
......
554 553
							}
555 554
							else {
556 555
								try {
557
									gInfo = GeometryUtilities.getGeometryPoints(mapControl, geometry);
558

  
559
									c_value = GeometryUtilities.getLength(layer, shape, gInfo);
556
									c_value = GeometryUtilities.getLength(layer.getMapContext().getViewPort(), geometry);
560 557
								}
561 558
								catch (Exception e) {
562 559
									NotificationManager.showMessageError(PluginServices.getText(null, "Failed_calculating_perimeter_of_geometry"), e);
563
									gInfo = null;
564

  
565 560
									percentage += inc;
566 561
									continue;
567 562
								}
......
603 598
								/* 5.6- Disables the edition of the row */
604 599
								vea.endComplexRow(operationName);
605 600

  
606
								gInfo = null;
607

  
608 601
								/* 5.7- Increments the counter of the fields added */
609 602
								n_fields_added ++;
610 603
							}
......
636 629
								continue;
637 630
							}
638 631
							else {
639
								try {
640
									gInfo = GeometryUtilities.getGeometryPoints(mapControl, geometry);
641
								} catch (Exception e) {
642
									NotificationManager.showMessageError(PluginServices.getText(null, "Failed_calculating_geometry_points"), e);
643
									gInfo = null;
644 632

  
645
									percentage += inc;
646
									continue;
647
								}
648

  
649 633
								/* 5.2- Enables the edition of the row */
650 634
								if (cancelProcess.isCanceled()) {
651 635
									throw new InterruptedException();
......
669 653
									case GeomInfo.PERIMETER:
670 654
										/* PERIMETER */
671 655
										try {
672
											c_value = GeometryUtilities.getLength(layer, shape, gInfo);
656
											c_value = GeometryUtilities.getLength(layer.getMapContext().getViewPort(), geometry);
673 657
										}
674 658
										catch (Exception e) {
675 659
											NotificationManager.showMessageError(PluginServices.getText(null, "Failed_calculating_perimeter_of_geometry"), e);
676
											gInfo = null;
677

  
678 660
											percentage += inc;
679 661
											continue;
680 662
										}
......
684 666
									case GeomInfo.AREA:
685 667
										/* AREA */
686 668
										try {
687
											c_value = GeometryUtilities.getArea(layer, shape, gInfo);
669
											c_value = GeometryUtilities.getArea(layer, geometry);
688 670
										}
689 671
										catch (Exception e) {
690 672
											NotificationManager.showMessageError(PluginServices.getText(null, "Failed_calculating_area_of_geometry"), e);
691
											gInfo = null;
692
		
693 673
											percentage += inc;
694 674
											continue;
695 675
										}
......
716 696
								/* 5.6- Disables the edition of the row */
717 697
								vea.endComplexRow(operationName);
718 698

  
719
								gInfo = null;
720

  
721 699
								/* 5.7- Increments the counter of the fields added */
722 700
								n_fields_added ++;
723 701
							}
trunk/extensions/extQuickInfo/src-test/org/gvsig/quickInfo/TestQuickInfoFLayerSelected.java
36 36

  
37 37
import org.gvsig.quickInfo.i18n.Messages;
38 38

  
39

  
40 39
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
41 40

  
42 41
/**
trunk/extensions/extQuickInfo/src-test/org/gvsig/quickInfo/TestQuickInfoToolTipText.java
32 32
import javax.swing.JOptionPane;
33 33
import javax.swing.JPanel;
34 34

  
35
import org.gvsig.quickInfo.i18n.Messages;
36
import org.gvsig.quickInfo.utils.xml.XML_DOM_Utilities;
35 37
import org.w3c.dom.Document;
36 38

  
37 39
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
38 40

  
39
import org.gvsig.quickInfo.i18n.Messages;
40
import org.gvsig.quickInfo.utils.xml.XML_DOM_Utilities;
41

  
42 41
/**
43 42
 * <p>Tests the creation of tool tip text according the style of the "quick information" tool.</p>
44 43
 * 
trunk/extensions/extQuickInfo/src/org/gvsig/quickInfo/tools/QuickInfoListener.java
45 45
import org.gvsig.quickInfo.FormatDecimalNumber;
46 46
import org.gvsig.quickInfo.GeometryIDInfo;
47 47
import org.gvsig.quickInfo.QuickInfoFLayerSelected;
48
import org.gvsig.quickInfo.utils.geometries.GeometryInfo;
49
import org.gvsig.quickInfo.utils.geometries.GeometryUtilities;
50 48

  
51 49
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
52 50
import com.hardcode.gdbms.engine.data.DataSource;
......
63 61
import com.iver.cit.gvsig.fmap.core.FPolyline2D;
64 62
import com.iver.cit.gvsig.fmap.core.FPolyline3D;
65 63
import com.iver.cit.gvsig.fmap.core.FShape;
64
import com.iver.cit.gvsig.fmap.core.GeometryUtilities;
66 65
import com.iver.cit.gvsig.fmap.core.IGeometry;
67 66
import com.iver.cit.gvsig.fmap.layers.FBitSet;
68 67
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
......
277 276

  
278 277
				Vector cFieldsToRestore = null;
279 278
				GeometryIDInfo gIDInfo = null;
280
				GeometryInfo gInfo = null;
281 279

  
282 280
				for (int j = bs.nextSetBit(0); j >= 0; j = bs.nextSetBit(j + 1)) {
283 281
					if (infoSelected.getLayerFields().size() > 0) {
......
303 301
							ReadableVectorial rv = ((FLyrVect)layer).getSource();
304 302

  
305 303
							rv.start();
306
							IGeometry geometry = (IGeometry) rv.getShape(j);
304
							IGeometry geometry = rv.getShape(j);
307 305
							rv.stop();
308 306

  
309 307
							Shape shape = null;
......
393 391
									key = PluginServices.getText(this, "Length");
394 392
									values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
395 393
									if (values != null) {
396
										gInfo = GeometryUtilities.getGeometryPoints(mapControl, geometry);
397

  
398 394
										try {
399
											perimeter = GeometryUtilities.getLength(infoSelected.getLayer(), shape, gInfo);
395
											perimeter = GeometryUtilities.getLength(infoSelected.getLayer().getMapContext().getViewPort(), geometry);
400 396

  
401 397
											values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters) + " " + nameDistanceUnits);
402 398
//											values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters, "?10", true) + " " + nameDistanceUnits);
......
413 409
//
414 410
//										xs_ar = ys_ar = null;
415 411
//										pls_n_points = null;
416
										
417
										gInfo = null;
418 412
									}
419 413
									break;
420 414
								case FShape.POLYGON:
......
422 416
									key = PluginServices.getText(this, "Area");
423 417
									values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
424 418
									if (values != null) {
425
										gInfo = GeometryUtilities.getGeometryPoints(mapControl, geometry);
426

  
427 419
										try {
428
											area = GeometryUtilities.getArea(infoSelected.getLayer(), shape, gInfo);
420
											area = GeometryUtilities.getArea(infoSelected.getLayer(), geometry);
429 421

  
430 422
											values.add(FormatDecimalNumber.formatDecimal(area / relationAreaUnitsToMeters2) + " " + nameAreaUnits);
431 423
//											values.add(FormatDecimalNumber.formatDecimal(area / relationAreaUnitsToMeters2, "?10", true) + " " + nameAreaUnits);
......
442 434
									key = PluginServices.getText(this, "Perimeter");
443 435
									values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
444 436
									if (values != null) {
445
										if (gInfo != null)
446
											gInfo = GeometryUtilities.getGeometryPoints(mapControl, geometry);
447

  
448 437
										try {
449
											perimeter = GeometryUtilities.getLength(infoSelected.getLayer(), shape, gInfo);
438
											perimeter = GeometryUtilities.getLength(infoSelected.getLayer().getMapContext().getViewPort(), geometry);
450 439

  
451 440
											values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters) + " " + nameDistanceUnits);
452 441
//											values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters, "?10", true) + " " + nameDistanceUnits);
......
458 447
											return;
459 448
										}
460 449
									}
461

  
462
									gInfo = null;
463 450
									break;
464 451
								case FShape.TEXT:
465 452
									break;
......
513 500
											key = PluginServices.getText(this, "Area");
514 501
											values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
515 502
											if (values != null) {
516
												gInfo = GeometryUtilities.getGeometryPoints(mapControl, geometry);
517 503

  
518 504
												try {
519
													area = GeometryUtilities.getArea(infoSelected.getLayer(), shape, gInfo);
505
													area = GeometryUtilities.getArea(infoSelected.getLayer(), geometry);
520 506

  
521 507
													values.add(FormatDecimalNumber.formatDecimal(area / relationAreaUnitsToMeters2) + " " + nameAreaUnits);
522 508
//													values.add(FormatDecimalNumber.formatDecimal(area / relationAreaUnitsToMeters2, "?10", true) + " " + nameAreaUnits);
......
535 521
											key = PluginServices.getText(this, "Perimeter");
536 522
											values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
537 523
											if (values != null) {
538
												if (gInfo != null)
539
													gInfo = GeometryUtilities.getGeometryPoints(mapControl, geometry);
540 524

  
541 525
												try {
542
													perimeter = GeometryUtilities.getLength(infoSelected.getLayer(), shape, gInfo);
526
													perimeter = GeometryUtilities.getLength(infoSelected.getLayer().getMapContext().getViewPort(), geometry);
543 527

  
544 528
													values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters) + " " + nameDistanceUnits);
545 529
//													values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters, "?10", true) + " " + nameDistanceUnits);
......
575 559
											cFieldsToRestore.add(text);
576 560
											map.remove(text);
577 561

  
578
											gInfo = null;
579 562
											continue;
580 563
										}
581 564
										else {
......
585 568
												key = PluginServices.getText(this, "Length");
586 569
												values = ((Vector)infoSelected.getCalculatedLayerFields().get(key));
587 570
												if (values != null) {
588
													gInfo = GeometryUtilities.getGeometryPoints(mapControl, geometry);
589 571

  
590 572
													try {
591
														perimeter = GeometryUtilities.getLength(infoSelected.getLayer(), shape, gInfo);
573
														perimeter = GeometryUtilities.getLength(infoSelected.getLayer().getMapContext().getViewPort(), geometry);
592 574

  
593 575
														values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters) + " " + nameDistanceUnits);
594 576
//														values.add(FormatDecimalNumber.formatDecimal(perimeter / relationDistanceUnitsToMeters, "?10", true) + " " + nameDistanceUnits);
......
625 607
												cFieldsToRestore.add(text);
626 608
												map.remove(text);
627 609

  
628
												gInfo = null;
629 610
												continue;
630 611
											}
631 612
											else {
trunk/extensions/extQuickInfo/src/org/gvsig/quickInfo/utils/geometries/GeometryInfo.java
1
package org.gvsig.quickInfo.utils.geometries;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

  
25
/**
26
 *
27
 *
28
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
29
 */
30
public class GeometryInfo {
31
	private Double[] xs_ar;
32
	private Double[] ys_ar;
33
	private Integer[] pols_n_points;
34
	
35
	public GeometryInfo() {
36
		xs_ar = null;
37
		ys_ar = null;
38
		pols_n_points = null;
39
	}
40

  
41
	public GeometryInfo(Double[] xs, Double[] ys, Integer[] pols_n_points) {
42
		xs_ar = xs;
43
		ys_ar = ys;
44
		this.pols_n_points = pols_n_points;
45
	}
46
	
47
	public Double[] getXs() {
48
		return xs_ar;
49
	}
50
	
51
	public Double[] getYs() {
52
		return ys_ar;
53
	}
54
	
55
	public Integer[] getPolygonsNumberOfPoints() {
56
		return pols_n_points;
57
	}
58
}
trunk/extensions/extQuickInfo/src/org/gvsig/quickInfo/utils/geometries/GeometryUtilities.java
1
package org.gvsig.quickInfo.utils.geometries;
2

  
3
/* gvSIG. Geographic Information System of the Valencian Government
4
 *
5
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
6
 * of the Valencian Government (CIT)
7
 * 
8
 * This program is free software; you can redistribute it and/or
9
 * modify it under the terms of the GNU General Public License
10
 * as published by the Free Software Foundation; either version 2
11
 * of the License, or (at your option) any later version.
12
 * 
13
 * This program is distributed in the hope that it will be useful,
14
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
 * GNU General Public License for more details.
17
 *  
18
 * You should have received a copy of the GNU General Public License
19
 * along with this program; if not, write to the Free Software
20
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
21
 * MA  02110-1301, USA.
22
 * 
23
 */
24

  
25
import java.awt.Shape;
26
import java.awt.geom.PathIterator;
27
import java.awt.geom.Point2D;
28
import java.util.ArrayList;
29

  
30
import com.iver.cit.gvsig.fmap.MapControl;
31
import com.iver.cit.gvsig.fmap.ViewPort;
32
import com.iver.cit.gvsig.fmap.core.FPoint2D;
33
import com.iver.cit.gvsig.fmap.core.FShape;
34
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
35
import com.iver.cit.gvsig.fmap.core.IGeometry;
36
import com.iver.cit.gvsig.fmap.core.ShapeFactory;
37
import com.iver.cit.gvsig.fmap.core.v02.FConverter;
38
import com.iver.cit.gvsig.fmap.layers.FLayer;
39
import com.iver.cit.gvsig.fmap.tools.geo.Geo;
40

  
41
/**
42
 *
43
 *
44
 * @author Vicente Caballero Navarro (vicente.caballero@iver.es)
45
 * @author Jaume Dom?nguez Faus (jaume.dominguez@iver.es)
46
 * @author C?sar Mart?nez Izquierdo (cesar.martinez@iver.es)
47
 * @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
48
 */
49
public class GeometryUtilities {
50
	public static double getLength(FLayer layer, Shape shape, Double[] xs, Double[] ys, Integer[] n_points) {
51
		if (layer.getProjection().isProjected()) {
52
			return FConverter.java2d_to_jts((FShape) shape).getLength();
53
		}
54
		else {
55
			// Only in geographic projections
56
			return getGeoCMultiLength(layer.getMapContext().getViewPort(), xs, ys, n_points);
57
		}
58
	}
59

  
60
	public static double getLength(FLayer layer, Shape shape, GeometryInfo gInfo) {
61
		if (layer.getProjection().isProjected()) {
62
			return FConverter.java2d_to_jts((FShape) shape).getLength();
63
		}
64
		else {
65
			// Only in geographic projections
66
			return getGeoCMultiLength(layer.getMapContext().getViewPort(), gInfo);
67
		}
68
	}
69

  
70
	public static double getArea(FLayer layer, Shape shape, Double[] xs, Double[] ys, Integer[] n_points) {
71
		if (layer.getProjection().isProjected()) {
72
			return FConverter.java2d_to_jts((FShape) shape).getArea();
73
		}
74
		else {
75
			// Only in geographic projections
76
			return getGeoCMultiArea(xs, ys, n_points);
77
		}
78
	}
79

  
80
	public static double getArea(FLayer layer, Shape shape, GeometryInfo gInfo) {
81
		if (layer.getProjection().isProjected()) {
82
			return FConverter.java2d_to_jts((FShape) shape).getArea();
83
		}
84
		else {
85
			// Only in geographic projections
86
			return getGeoCMultiArea(gInfo);
87
		}
88
	}	
89
	/**
90
	 * <p>Returns the area in geographical coordinates of the polygon, according the
91
	 *  <a href="http://en.wikipedia.org/wiki/Haversine_formula">Haversine function</a>.</p>
92
	 *
93
	 * @see Geo#sphericalPolyArea(double[], double[], int)
94
	 */
95
	public static double getGeoCMultiArea(Double[] xs, Double[] ys, Integer[] n_points) {
96
		double[] lat;
97
		double[] lon;
98
		
99
		double area = 0;
100
		int index = 0;
101

  
102
		// For each polygon
103
		for (int i = 0; i < n_points.length; i++) {
104
			lat = new double[n_points[i].intValue()];
105
			lon = new double[n_points[i].intValue()];
106

  
107
			for (int j = 0; j < lat.length; j++) {
108
				lon[j] = xs[index].doubleValue() / Geo.Degree;
109
				lat[j] = ys[index].doubleValue() / Geo.Degree;
110
				index++;
111
			}
112

  
113
			area += (Geo.sphericalPolyArea(lat, lon, lat.length-1) * Geo.SqM);
114
		}
115
		
116
		return area;
117
	}
118

  
119
	
120
	/**
121
	 * <p>Returns the area in geographical coordinates of the polygon, according the
122
	 *  <a href="http://en.wikipedia.org/wiki/Haversine_formula">Haversine function</a>.</p>
123
	 *
124
	 * @see Geo#sphericalPolyArea(double[], double[], int)
125
	 */
126
	public static double getGeoCMultiArea(GeometryInfo gInfo) {
127
		return getGeoCMultiArea(gInfo.getXs(), gInfo.getYs(), gInfo.getPolygonsNumberOfPoints());
128
	}
129
	
130
	
131
	/** 
132
	 * <p>Returns the perimeter in geographical coordinates of the polygon, according the
133
	 *  <a href="http://en.wikipedia.org/wiki/Haversine_formula">Haversine function</a>.</p>
134
	 *
135
	 * 
136
	 */
137
	public static double getGeoCMultiLength(ViewPort vp, Double[] xs, Double[] ys, Integer[] n_points) {
138
		Point2D p1, p2;
139
		int index = 0;
140
		double polygon_perimeter = 0;
141
		double perimeter = 0;
142

  
143
		// For each polygon/polyline
144
		for (int i = 0; i < n_points.length; i++) {
145
			polygon_perimeter = 0;
146
			p1 = new Point2D.Double(xs[index].doubleValue(), ys[index].doubleValue());
147
			index ++;
148

  
149
			for (int j = 1; j < (n_points[i].intValue()); j++) {
150
				p2 = new Point2D.Double(xs[index].doubleValue(), ys[index].doubleValue());
151

  
152
				polygon_perimeter += vp.distanceWorld(p1, p2);
153
				p1 = p2;
154

  
155
				index ++;
156
			}
157

  
158
			perimeter += polygon_perimeter;
159
		}
160

  
161
		return perimeter;
162
	}
163
	
164
	/**
165
	 * <p>Returns the area in geographical coordinates of the polygon, according the
166
	 *  <a href="http://en.wikipedia.org/wiki/Haversine_formula">Haversine function</a>.</p>
167
	 *
168
	 * @see Geo#sphericalPolyArea(double[], double[], int)
169
	 */
170
	public static double getGeoCMultiLength(ViewPort vp, GeometryInfo gInfo) {
171
		return getGeoCMultiLength(vp, gInfo.getXs(), gInfo.getYs(), gInfo.getPolygonsNumberOfPoints());
172
	}
173
	
174
	   
175
    public static GeometryInfo getGeometryPoints(MapControl mapControl, IGeometry geometry) {
176
    	// We don't need calculate the points if the projection is projected
177
    	if (mapControl.getProjection().isProjected())
178
    		return null;
179
    	
180
		ArrayList xs, ys, n_points;
181
		PathIterator it;
182

  
183
		it = geometry.getPathIterator(null, FConverter.FLATNESS);
184

  
185
		double[] newCoords = new double[6]; // Can receive as much 6 coordinates (3 points)
186
		int currentType;
187

  
188
		Point2D point = new Point2D.Double();
189
		Point2D firstPoint = new Point2D.Double();
190

  
191
		xs = new ArrayList();
192
		ys = new ArrayList();
193
		n_points = new ArrayList();
194
		int numPoints = 0;
195

  
196
		// Get first point
197
		if (! it.isDone()) {
198
			currentType = it.currentSegment(newCoords);
199

  
200
			switch (currentType) {
201
				case PathIterator.SEG_MOVETO:
202
					firstPoint.setLocation(newCoords[0], newCoords[1]);
203
					numPoints = 1;
204
                	xs.add(new Double(firstPoint.getX()));
205
					ys.add(new Double(firstPoint.getY()));
206
					break;
207
                case PathIterator.SEG_LINETO:
208
                	firstPoint.setLocation(newCoords[0], newCoords[1]);
209
                	numPoints++;
210
                	xs.add(new Double(firstPoint.getX()));
211
					ys.add(new Double(firstPoint.getY()));
212
                    break;
213
                case PathIterator.SEG_QUADTO:
214
                	// Don't used
215
//                	firstPoint.setLocation(newCoords[0], newCoords[1]);
216
//                	numPoints++;
217
//                	xs.add(new Double(firstPoint.getX()));
218
//					ys.add(new Double(firstPoint.getY()));
219
//
220
//                	point.setLocation(newCoords[2], newCoords[3]);
221
//                	numPoints++;
222
//                	xs.add(new Double(point.getX()));
223
//					ys.add(new Double(point.getY()));
224
                    break;
225
                case PathIterator.SEG_CUBICTO:
226
                	// Don't used
227
//                	firstPoint.setLocation(newCoords[0], newCoords[1]);
228
//                	numPoints++;
229
//                	xs.add(new Double(firstPoint.getX()));
230
//					ys.add(new Double(firstPoint.getY()));
231
//					
232
//                	point.setLocation(newCoords[2], newCoords[3]);
233
//                	numPoints++;
234
//                	xs.add(new Double(point.getX()));
235
//					ys.add(new Double(point.getY()));
236
//					
237
//                	point.setLocation(newCoords[4], newCoords[5]);
238
//                	numPoints++;
239
//                	xs.add(new Double(point.getX()));
240
//					ys.add(new Double(point.getY()));
241
                    break;
242
                case PathIterator.SEG_CLOSE:
243
                	// Closes the polygon with the first point
244
                	// numPoints++;
245
                	// xs.add(new Double(point.getX()));
246
                	// ys.add(new Double(point.getY()));
247
                	// n_points.add(new Integer(numPoints));
248
                	// newGp.closePath();
249
                    break;
250
            }
251

  
252
			it.next();				
253
		}
254
		
255
		// Get the other points
256
		while (! it.isDone()) {
257
			currentType = it.currentSegment(newCoords);
258

  
259
			switch (currentType) {
260
				case PathIterator.SEG_MOVETO:
261
					// SEG_MOVETO -> New polygon
262
					n_points.add(new Integer(numPoints));
263
					firstPoint.setLocation(newCoords[0], newCoords[1]);
264
					xs.add(new Double(firstPoint.getX()));
265
					ys.add(new Double(firstPoint.getY()));
266
					numPoints = 1;
267
					break;
268
                case PathIterator.SEG_LINETO:
269
                	point.setLocation(newCoords[0], newCoords[1]);
270
					xs.add(new Double(point.getX()));
271
					ys.add(new Double(point.getY()));
272
                	numPoints++;
273
                	break;
274
                case PathIterator.SEG_QUADTO:
275
                	// Don't used
276
//					point.setLocation(newCoords[0], newCoords[1]);
277
//					xs.add(new Double(point.getX()));
278
//					ys.add(new Double(point.getY()));
279
//					numPoints++;
280
//					
281
//					point.setLocation(newCoords[2], newCoords[3]);
282
//					xs.add(new Double(point.getX()));
283
//					ys.add(new Double(point.getY()));
284
//					numPoints++;
285
                    break;
286
                case PathIterator.SEG_CUBICTO:
287
                	// Don't used
288
//					point.setLocation(newCoords[0], newCoords[1]);
289
//					xs.add(new Double(point.getX()));
290
//					ys.add(new Double(point.getY()));
291
//					numPoints++;
292
//					
293
//					point.setLocation(newCoords[2], newCoords[3]);
294
//					xs.add(new Double(point.getX()));
295
//					ys.add(new Double(point.getY()));
296
//					numPoints++;
297
//					
298
//					point.setLocation(newCoords[4], newCoords[5]);
299
//					xs.add(new Double(point.getX()));
300
//					ys.add(new Double(point.getY()));
301
//					numPoints++;
302
                    break;
303
                case PathIterator.SEG_CLOSE:
304
                	// Closes the polygon with the first point
305
                	xs.add(new Double(firstPoint.getX()));
306
					ys.add(new Double(firstPoint.getY()));
307
					numPoints++;
308
//					n_points.add(new Integer(numPoints));
309
                    break;
310
            }
311

  
312
			it.next();
313
		}
314
		
315
		n_points.add(new Integer(numPoints));
316

  
317
		GeometryInfo gInfo = new GeometryInfo((Double[])xs.toArray(new Double[0]), (Double[])ys.toArray(new Double[0]), (Integer[])n_points.toArray(new Integer[0]));
318

  
319
		return gInfo;
320
		// Shows the number of points of the polygons of the geometry 		
321
		//	for (int i = 0; i < pls_n_points.length; i++) {
322
		//		System.out.println("Number of points: " + pls_n_points[i].intValue());
323
		//	}
324
    }
325
    
326
    /**
327
     * 
328
     * 
329
     * @param geometry
330
     * @param vP
331
     * @param isClosed <code>true</code> if it's a polygon
332
     * @return
333
     */
334
    public static IGeometry polyline2DToMapCoordinates(IGeometry geometry, ViewPort vP, boolean isClosed) {
335
    	PathIterator it = geometry.getPathIterator(null);
336
    	double[] newCoords = new double[6]; // Can receive as much 6 coordinates (3 points)
337
    	int currentType;
338
    	Point2D firstPoint = new Point2D.Double(), point = new Point2D.Double();
339
		GeneralPathX gP = new GeneralPathX();
340

  
341
		// Get first point
342
		if (! it.isDone()) {
343
			currentType = it.currentSegment(newCoords);
344

  
345
			switch (currentType) {
346
				case PathIterator.SEG_MOVETO:
347
					firstPoint.setLocation(newCoords[0], newCoords[1]);
348
					break;
349
                case PathIterator.SEG_LINETO:
350
					firstPoint.setLocation(newCoords[0], newCoords[1]);
351
                    break;
352
                case PathIterator.SEG_QUADTO:
353
                	// Don't used
354
                    break;
355
                case PathIterator.SEG_CUBICTO:
356
                	// Don't used
357
                    break;
358
                case PathIterator.SEG_CLOSE:
359
                    break;
360
            }
361

  
362
			it.next();				
363
		}
364

  
365
		if (firstPoint == null)
366
			return null;
367
		
368
		firstPoint = vP.toMapPoint(firstPoint);
369
		gP.moveTo(firstPoint.getX(), firstPoint.getY());
370

  
371
		
372
		// Get the other points
373
		while (! it.isDone()) {
374
			currentType = it.currentSegment(newCoords);
375

  
376
			switch (currentType) {
377
				case PathIterator.SEG_MOVETO:
378
					// SEG_MOVETO -> New polygon
379
					firstPoint.setLocation(newCoords[0], newCoords[1]);
380
					firstPoint = vP.toMapPoint(firstPoint);
381
					gP.moveTo(firstPoint.getX(), firstPoint.getY());
382
					break;
383
                case PathIterator.SEG_LINETO:
384
					point.setLocation(newCoords[0], newCoords[1]);
385
					point = vP.toMapPoint(point);
386
					gP.lineTo(point.getX(), point.getY());
387
                	break;
388
                case PathIterator.SEG_QUADTO:
389
                	// Don't used
390
                    break;
391
                case PathIterator.SEG_CUBICTO:
392
                	// Don't used
393
                    break;
394
                case PathIterator.SEG_CLOSE:
395
                	if (isClosed) {
396
                		// Closes the polygon with the first point
397
						gP.moveTo(firstPoint.getX(), firstPoint.getY());
398
                	}
399

  
400
					gP.closePath();
401
                    break;
402
            }
403

  
404
			it.next();
405
		}
406

  
407
		if (isClosed)
408
			return ShapeFactory.createPolygon2D(gP);
409
		else
410
			return ShapeFactory.createPolyline2D(gP);
411
    }
412

  
413
    public static IGeometry closeLine(IGeometry line) {
414
    	PathIterator it = line.getPathIterator(null);
415
    	double[] newCoords = new double[6]; // Can receive as much 6 coordinates (3 points)
416
    	Point2D firstPoint = new Point2D.Double(), point = new Point2D.Double();
417
		GeneralPathX gP = new GeneralPathX();
418
    	int currentType;
419
    	boolean closed = false;
420
    	long numPoints = 0;
421
    	
422
		while (! it.isDone()) {
423
			currentType = it.currentSegment(newCoords);
424

  
425
			switch (currentType) {
426
				case PathIterator.SEG_MOVETO:
427
					// SEG_MOVETO -> New polygon
428
					firstPoint.setLocation(newCoords[0], newCoords[1]);
429
				//	firstPoint = vP.toMapPoint(firstPoint);
430
					gP.moveTo(firstPoint.getX(), firstPoint.getY());
431
					numPoints ++;
432
					break;
433
                case PathIterator.SEG_LINETO:
434
					point.setLocation(newCoords[0], newCoords[1]);
435
					//point = vP.toMapPoint(point);
436
					gP.lineTo(point.getX(), point.getY());
437
					numPoints ++;
438
                	break;
439
                case PathIterator.SEG_QUADTO:
440
                	// Don't used
441
                    break;
442
                case PathIterator.SEG_CUBICTO:
443
                	// Don't used
444
                    break;
445
                case PathIterator.SEG_CLOSE:
446
                	// Closes the line with the first point
447
					//gP.lineTo(firstPoint.getX(), firstPoint.getY());
448
                	numPoints ++;
449
					gP.closePath();
450
					closed = true;
451
                    break;
452
            }
453

  
454
			it.next();
455
		}
456

  
457
		// Only can close (convert to polygons) the lines which are composed by more than 2 points
458
		if (numPoints < 3)
459
			return null;
460

  
461
		// Forces to close the multi-line
462
		if ((! closed) && (firstPoint != null)) {
463
			//gP.lineTo(firstPoint.getX(), firstPoint.getY());
464
			numPoints ++;
465
			gP.closePath();
466
		}
467

  
468
		return ShapeFactory.createPolygon2D(gP);
469
    }
470

  
471
    /**
472
     * 
473
     * @param points
474
     * @return
475
     */
476
    public static IGeometry getPolyLine2D(FPoint2D[] points) {
477
    	if (points.length < 2)
478
    		return null;
479
    	
480
    	// Creates the general path of the new polyline
481
    	GeneralPathX gPath = new GeneralPathX();
482
    	
483
    	gPath.moveTo(points[0].getX(), points[0].getY());
484
    	
485
    	for (int i = 1; i < points.length; i++) {
486
    		gPath.lineTo(points[i].getX(), points[i].getY());
487
		}
488

  
489
    	return ShapeFactory.createPolyline2D(gPath);
490
    }
491
    
492
    /**
493
     * 
494
     * @param points
495
     * @return
496
     */
497
    public static IGeometry getPolygon2D(FPoint2D[] points) {
498
    	if (points.length < 3)
499
    		return null;
500
    	
501
    	// Creates the general path of the new polygon
502
    	GeneralPathX gPath = new GeneralPathX();
503
    	
504
    	gPath.moveTo(points[0].getX(), points[0].getY());
505
    	
506
    	for (int i = 1; i < points.length; i++) {
507
    		gPath.lineTo(points[i].getX(), points[i].getY());
508
		}
509
    	
510
    	// Forces to close the polygon
511
    	gPath.closePath();
512

  
513
    	return ShapeFactory.createPolygon2D(gPath);
514
    }
515
}
trunk/extensions/extQuickInfo/src/org/gvsig/quickInfo/QuickInfoToolExtension.java
22 22
 * 
23 23
 */
24 24

  
25
import org.gvsig.quickInfo.gui.QuickInfoDataSelectionPanel;
26

  
25 27
import com.iver.andami.PluginServices;
26 28
import com.iver.andami.plugins.Extension;
27 29
import com.iver.cit.gvsig.fmap.MapContext;
......
31 33
import com.iver.cit.gvsig.project.documents.view.IProjectView;
32 34
import com.iver.cit.gvsig.project.documents.view.gui.View;
33 35

  
34
import org.gvsig.quickInfo.gui.QuickInfoDataSelectionPanel;
35

  
36 36
/**
37 37
 * <p><a href="http://www.gvsig.com/">gvSIG</a> extension.</p>
38 38
 * <p>Tool that displays the selected information that the cursor points on the active view.</p>
trunk/extensions/extQuickInfo/src/org/gvsig/quickInfo/QuickInfoFLayerSelected.java
31 31
import javax.xml.parsers.DocumentBuilder;
32 32
import javax.xml.parsers.DocumentBuilderFactory;
33 33

  
34
import org.gvsig.quickInfo.utils.xml.XML_DOM_Utilities;
34 35
import org.w3c.dom.Comment;
35 36
import org.w3c.dom.Document;
36 37
import org.w3c.dom.Element;
......
39 40
import com.iver.andami.messages.NotificationManager;
40 41
import com.iver.cit.gvsig.fmap.layers.FLayer;
41 42

  
42
import org.gvsig.quickInfo.utils.xml.XML_DOM_Utilities;
43

  
44 43
/**
45 44
 * <p>Stores the information selected of a layer's point.</p>
46 45
 * 
trunk/extensions/extQuickInfo/src/org/gvsig/quickInfo/gui/QuickInfoDataSelectionPanel.java
64 64
import javax.swing.table.TableCellRenderer;
65 65
import javax.swing.table.TableModel;
66 66

  
67
import org.gvsig.gui.beans.AcceptCancelPanel;
68
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
69
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent;
70
import org.gvsig.gui.beans.incrementabletask.IncrementableProcess;
71
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
72
import org.gvsig.gui.beans.progresspanel.ProgressPanel;
73
import org.gvsig.quickInfo.QuickInfoFLayerSelected;
74
import org.gvsig.quickInfo.tools.QuickInfoListener;
75
import org.gvsig.quickInfo.utils.FShapeTypeNames;
76
import org.gvsig.quickInfo.utils.SQLTypeNames;
67 77

  
68 78
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
79
import com.hardcode.gdbms.engine.data.driver.DriverException;
69 80
import com.iver.andami.PluginServices;
70 81
import com.iver.andami.messages.NotificationManager;
71 82
import com.iver.andami.ui.mdiManager.IWindow;
......
82 93
import com.iver.cit.gvsig.fmap.tools.Listeners.PointListener;
83 94
import com.iver.cit.gvsig.project.documents.view.toc.TocItemBranch;
84 95

  
85
import org.gvsig.gui.beans.AcceptCancelPanel;
86
import org.gvsig.gui.beans.buttonspanel.ButtonsPanel;
87
import org.gvsig.gui.beans.incrementabletask.IncrementableEvent;
88
import org.gvsig.gui.beans.incrementabletask.IncrementableProcess;
89
import org.gvsig.gui.beans.incrementabletask.IncrementableTask;
90
import org.gvsig.gui.beans.progresspanel.ProgressPanel;
91
import org.gvsig.quickInfo.tools.QuickInfoListener;
92
import org.gvsig.quickInfo.QuickInfoFLayerSelected;
93
import org.gvsig.quickInfo.utils.FShapeTypeNames;
94
import org.gvsig.quickInfo.utils.SQLTypeNames;
95

  
96 96
/**
97 97
 * <p>Panel where user will select the layer and its fields to display as a <i>quick information tool</i>
98 98
 *  on a <code>MapControl</code> object.</p>

Also available in: Unified diff