Revision 74 trunk/org.gvsig.dwg/org.gvsig.dwg.lib/src/main/java/org/gvsig/dwg/lib/util/FMapUtil.java
FMapUtil.java | ||
---|---|---|
13 | 13 |
import org.gvsig.fmap.geom.GeometryLocator; |
14 | 14 |
import org.gvsig.fmap.geom.GeometryManager; |
15 | 15 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
16 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
|
16 | 17 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
17 |
import org.gvsig.fmap.geom.primitive.Curve;
|
|
18 |
import org.gvsig.fmap.geom.primitive.Line;
|
|
18 | 19 |
import org.gvsig.fmap.geom.primitive.Point; |
20 |
import org.gvsig.fmap.geom.primitive.Polygon; |
|
19 | 21 |
import org.gvsig.fmap.geom.primitive.Surface; |
20 | 22 |
|
21 |
|
|
22 | 23 |
/** |
23 | 24 |
* @author alzabord |
24 | 25 |
* |
25 | 26 |
*/ |
26 | 27 |
public class FMapUtil { |
27 | 28 |
|
28 |
// /** |
|
29 |
// * Method that changes a Point3D array to a FPolyline3D. Is useful to |
|
30 |
// * convert a polyline given by it points to a FPolyline3D, a polyline 3D in |
|
31 |
// * the FMap model object |
|
32 |
// * |
|
33 |
// * @param pts |
|
34 |
// * Array of Point3D that defines the polyline 3D that will be |
|
35 |
// * converted in a FPolyline3D |
|
36 |
// * @return FPolyline3D This FPolyline3D is build using the array of Point3D |
|
37 |
// * that is the argument of the method |
|
38 |
// */ |
|
39 |
// public static FPolyline3D points3DToFPolyline3D(List pts) { |
|
40 |
// GeneralPathX genPathX = getGeneralPathX(pts); |
|
41 |
// double[] elevations = new double[pts.size()]; |
|
42 |
// for (int i = 0; i < pts.size(); i++) { |
|
43 |
// elevations[i] = ((double[])pts.get(i))[2]; |
|
44 |
// } |
|
45 |
// return new FPolyline3D(genPathX, elevations); |
|
46 |
// } |
|
29 |
private static final GeometryManager gManager = GeometryLocator |
|
30 |
.getGeometryManager(); |
|
47 | 31 |
|
48 |
private static GeometryManager gManager = GeometryLocator
|
|
49 |
.getGeometryManager();
|
|
32 |
public static MultiCurve ptsToMultiLine(List<double[]> pts, int subType)
|
|
33 |
throws CreateGeometryException {
|
|
50 | 34 |
|
35 |
if (pts.size() < 2) { |
|
36 |
throw new IllegalArgumentException(); |
|
37 |
} |
|
51 | 38 |
|
39 |
Point point, prevPoint; |
|
40 |
Line line; |
|
52 | 41 |
|
53 |
// /** |
|
54 |
// * Method that changes a Point2D array to a FPolyline2D. Is useful to |
|
55 |
// * convert a polyline given by it points to a FPolyline2D, a polyline in the |
|
56 |
// * FMap model object |
|
57 |
// * |
|
58 |
// * @param pts |
|
59 |
// * Array of Point2D that defines the polyline that will be |
|
60 |
// * converted in a FPolyline2D |
|
61 |
// * @return FPolyline2D This FPolyline2D is build using the array of Point2D |
|
62 |
// * that is the argument of the method |
|
63 |
// */ |
|
64 |
// public static FPolyline2D points2DToFPolyline2D(List pts) { |
|
65 |
// GeneralPathX genPathX = getGeneralPathX(pts); |
|
66 |
// return new FPolyline2D(genPathX); |
|
67 |
// } |
|
42 |
MultiLine multi = gManager.createMultiLine(subType); |
|
43 |
prevPoint = FMapUtil.createPoint(subType, pts.get(0)); |
|
44 |
for (int i = 1; i < pts.size(); i++) { |
|
45 |
point = FMapUtil.createPoint(subType, pts.get(i)); |
|
46 |
line = gManager.createLine(subType); |
|
47 |
line.addVertex(prevPoint); |
|
48 |
line.addVertex(point); |
|
49 |
multi.addPrimitive(line); |
|
50 |
prevPoint = FMapUtil.createPoint(subType, pts.get(i)); |
|
51 |
} |
|
52 |
return multi; |
|
68 | 53 |
|
69 |
public static MultiCurve ptsToMultiCurve(List pts, int subType) |
|
70 |
throws CreateGeometryException { |
|
54 |
} |
|
71 | 55 |
|
72 |
if (pts.size() < 2) { |
|
73 |
throw new IllegalArgumentException(); |
|
74 |
} |
|
56 |
public static Surface ptsToPolygon(List<double[]> pts, int subType) |
|
57 |
throws CreateGeometryException { |
|
75 | 58 |
|
76 |
Point point, prevPoint; |
|
77 |
Curve curve; |
|
59 |
if (pts.size() < 3) { |
|
60 |
throw new IllegalArgumentException(); |
|
61 |
} |
|
78 | 62 |
|
79 |
MultiCurve multi = (MultiCurve) gManager.create( |
|
80 |
Geometry.TYPES.MULTICURVE, |
|
81 |
subType); |
|
82 |
prevPoint = FMapUtil.createPoint(subType, pts.get(0)); |
|
83 |
for (int i = 1; i < pts.size(); i++) { |
|
84 |
point = FMapUtil.createPoint(subType, pts.get(i)); |
|
85 |
curve = (Curve) gManager.create(Geometry.TYPES.CURVE, subType); |
|
86 |
curve.setPoints(prevPoint, point); |
|
87 |
multi.addCurve(curve); |
|
88 |
prevPoint = FMapUtil.createPoint(subType, pts.get(i)); |
|
89 |
} |
|
90 |
return multi; |
|
63 |
Polygon polygon = gManager.createPolygon(subType); |
|
91 | 64 |
|
92 |
} |
|
65 |
Iterator<double[]> iter = pts.iterator(); |
|
66 |
while (iter.hasNext()) { |
|
67 |
Point vertex = createPoint(subType, iter.next()); |
|
68 |
polygon.addVertex(vertex); |
|
69 |
} |
|
70 |
return polygon; |
|
71 |
} |
|
93 | 72 |
|
94 |
public static Surface ptsToPolygon(List pts, int subType) |
|
95 |
throws CreateGeometryException { |
|
73 |
public static Point createPoint(int subType, double[] point) throws CreateGeometryException { |
|
74 |
Point result = gManager.createPoint(point[0], point[1], subType); |
|
75 |
if (subType == Geometry.SUBTYPES.GEOM3D) { |
|
76 |
result.setCoordinateAt(Geometry.DIMENSIONS.Z, point[2]); |
|
77 |
} |
|
78 |
return result; |
|
79 |
} |
|
96 | 80 |
|
81 |
public static Point createPoint(int subType, Point2D point) throws CreateGeometryException { |
|
82 |
Point result = gManager.createPoint(point.getX(), point.getY(), subType); |
|
83 |
return result; |
|
84 |
} |
|
97 | 85 |
|
98 |
if (pts.size() < 3) { |
|
99 |
throw new IllegalArgumentException(); |
|
100 |
} |
|
86 |
public static Point createPoint(int subType, IDwgVertex dwgvertex) throws CreateGeometryException { |
|
87 |
double[] point = dwgvertex.getPoint(); |
|
88 |
Point result = gManager.createPoint(point[0], point[1], subType); |
|
89 |
if (subType == Geometry.SUBTYPES.GEOM3D) { |
|
90 |
result.setCoordinateAt(Geometry.DIMENSIONS.Z, point[2]); |
|
91 |
} |
|
92 |
return result; |
|
93 |
} |
|
101 | 94 |
|
102 |
Point cur; |
|
103 |
Surface surface = (Surface) gManager.create(Geometry.TYPES.SURFACE, |
|
104 |
subType); |
|
105 |
|
|
106 |
Iterator iter = pts.iterator(); |
|
107 |
while (iter.hasNext()) { |
|
108 |
cur = createPoint(subType, iter.next()); |
|
109 |
surface.addVertex(cur); |
|
110 |
} |
|
111 |
return surface; |
|
112 |
} |
|
113 |
|
|
114 |
public static Point createPoint(int subType, |
|
115 |
Object point) |
|
116 |
throws CreateGeometryException { |
|
117 |
Point result = (Point) gManager.create(Geometry.TYPES.POINT, subType); |
|
118 |
if (point instanceof double[]) { |
|
119 |
result.setCoordinates((double[]) point); |
|
120 |
} else if (point instanceof Point2D) { |
|
121 |
Point2D p = (Point2D) point; |
|
122 |
result.setX(p.getX()); |
|
123 |
result.setY(p.getY()); |
|
124 |
|
|
125 |
} else if (point instanceof IDwgVertex) { |
|
126 |
result.setCoordinates(((IDwgVertex) point).getPoint()); |
|
127 |
} else { |
|
128 |
throw new IllegalArgumentException(); |
|
129 |
} |
|
130 |
return result; |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* Devuelve la distancia desde angle1 a angle2. Angulo en radianes de |
|
135 |
* diferencia entre angle1 y angle2 en sentido antihorario |
|
136 |
* |
|
137 |
* @param angle1 angulo en radianes. Debe ser positivo y no dar ninguna |
|
138 |
* vuelta a la circunferencia |
|
139 |
* @param angle2 angulo en radianes. Debe ser positivo y no dar ninguna |
|
140 |
* vuelta a la circunferencia |
|
141 |
* |
|
142 |
* @return distancia entre los �ngulos |
|
143 |
*/ |
|
144 |
public static double angleDistance(double angle1, double angle2) { |
|
145 |
if (angle1 < angle2) { |
|
146 |
return angle2 - angle1; |
|
147 |
} else { |
|
148 |
return ((Math.PI * 2) - angle1) + angle2; |
|
149 |
} |
|
150 |
} |
|
95 |
/** |
|
96 |
* Devuelve la distancia desde angle1 a angle2. Angulo en radianes de |
|
97 |
* diferencia entre angle1 y angle2 en sentido antihorario |
|
98 |
* |
|
99 |
* @param angle1 angulo en radianes. Debe ser positivo y no dar ninguna |
|
100 |
* vuelta a la circunferencia |
|
101 |
* @param angle2 angulo en radianes. Debe ser positivo y no dar ninguna |
|
102 |
* vuelta a la circunferencia |
|
103 |
* |
|
104 |
* @return distancia entre los �ngulos |
|
105 |
*/ |
|
106 |
public static double angleDistance(double angle1, double angle2) { |
|
107 |
if (angle1 < angle2) { |
|
108 |
return angle2 - angle1; |
|
109 |
} else { |
|
110 |
return ((Math.PI * 2) - angle1) + angle2; |
|
111 |
} |
|
112 |
} |
|
151 | 113 |
} |
Also available in: Unified diff