svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libDwg / src / org / gvsig / dwg / lib / util / FMapUtil.java @ 29001
History | View | Annotate | Download (3.64 KB)
1 |
/*
|
---|---|
2 |
* Created on 18-ene-2007 by azabala
|
3 |
*
|
4 |
*/
|
5 |
package org.gvsig.dwg.lib.util; |
6 |
|
7 |
import java.awt.geom.Point2D; |
8 |
import java.util.Iterator; |
9 |
import java.util.List; |
10 |
|
11 |
import org.gvsig.dwg.lib.IDwgVertex; |
12 |
import org.gvsig.fmap.geom.Geometry; |
13 |
import org.gvsig.fmap.geom.GeometryLocator; |
14 |
import org.gvsig.fmap.geom.GeometryManager; |
15 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
16 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
17 |
import org.gvsig.fmap.geom.primitive.Curve; |
18 |
import org.gvsig.fmap.geom.primitive.Point; |
19 |
import org.gvsig.fmap.geom.primitive.Surface; |
20 |
|
21 |
|
22 |
/**
|
23 |
* @author alzabord
|
24 |
*
|
25 |
*/
|
26 |
public class FMapUtil { |
27 |
// /**
|
28 |
// * Method that changes a Point3D array to a FPolyline3D. Is useful to
|
29 |
// * convert a polyline given by it points to a FPolyline3D, a polyline 3D in
|
30 |
// * the FMap model object
|
31 |
// *
|
32 |
// * @param pts
|
33 |
// * Array of Point3D that defines the polyline 3D that will be
|
34 |
// * converted in a FPolyline3D
|
35 |
// * @return FPolyline3D This FPolyline3D is build using the array of Point3D
|
36 |
// * that is the argument of the method
|
37 |
// */
|
38 |
// public static FPolyline3D points3DToFPolyline3D(List pts) {
|
39 |
// GeneralPathX genPathX = getGeneralPathX(pts);
|
40 |
// double[] elevations = new double[pts.size()];
|
41 |
// for (int i = 0; i < pts.size(); i++) {
|
42 |
// elevations[i] = ((double[])pts.get(i))[2];
|
43 |
// }
|
44 |
// return new FPolyline3D(genPathX, elevations);
|
45 |
// }
|
46 |
|
47 |
private static GeometryManager gManager = GeometryLocator |
48 |
.getGeometryManager(); |
49 |
|
50 |
|
51 |
|
52 |
// /**
|
53 |
// * Method that changes a Point2D array to a FPolyline2D. Is useful to
|
54 |
// * convert a polyline given by it points to a FPolyline2D, a polyline in the
|
55 |
// * FMap model object
|
56 |
// *
|
57 |
// * @param pts
|
58 |
// * Array of Point2D that defines the polyline that will be
|
59 |
// * converted in a FPolyline2D
|
60 |
// * @return FPolyline2D This FPolyline2D is build using the array of Point2D
|
61 |
// * that is the argument of the method
|
62 |
// */
|
63 |
// public static FPolyline2D points2DToFPolyline2D(List pts) {
|
64 |
// GeneralPathX genPathX = getGeneralPathX(pts);
|
65 |
// return new FPolyline2D(genPathX);
|
66 |
// }
|
67 |
|
68 |
public static MultiCurve ptsToMultiCurve(List pts, int subType) |
69 |
throws CreateGeometryException {
|
70 |
|
71 |
if (pts.size() < 2) { |
72 |
throw new IllegalArgumentException(); |
73 |
} |
74 |
|
75 |
Point point, prevPoint;
|
76 |
Curve curve; |
77 |
|
78 |
MultiCurve multi = (MultiCurve) gManager.create( |
79 |
Geometry.TYPES.MULTICURVE, |
80 |
subType); |
81 |
prevPoint = FMapUtil.createPoint(subType, pts.get(0));
|
82 |
for (int i = 1; i < pts.size(); i++) { |
83 |
point = FMapUtil.createPoint(subType, pts.get(i)); |
84 |
curve = (Curve) gManager.create(Geometry.TYPES.CURVE, subType); |
85 |
curve.setPoints(prevPoint, point); |
86 |
multi.addCurve(curve); |
87 |
prevPoint = point; |
88 |
} |
89 |
return multi;
|
90 |
|
91 |
} |
92 |
|
93 |
public static Surface ptsToPolygon(List pts, int subType) |
94 |
throws CreateGeometryException {
|
95 |
|
96 |
|
97 |
if (pts.size() < 3) { |
98 |
throw new IllegalArgumentException(); |
99 |
} |
100 |
|
101 |
Point cur;
|
102 |
Surface surface = (Surface) gManager.create(Geometry.TYPES.SURFACE, |
103 |
subType); |
104 |
|
105 |
Iterator iter = pts.iterator();
|
106 |
while (iter.hasNext()) {
|
107 |
cur = createPoint(subType, iter.next()); |
108 |
surface.addVertex(cur); |
109 |
} |
110 |
return surface;
|
111 |
} |
112 |
|
113 |
public static Point createPoint(int subType, |
114 |
Object point)
|
115 |
throws CreateGeometryException {
|
116 |
Point result = (Point) gManager.create(Geometry.TYPES.POINT, subType); |
117 |
if (point instanceof double[]) { |
118 |
result.setCoordinates((double[]) point); |
119 |
} else if (point instanceof Point2D) { |
120 |
Point2D p = (Point2D) point; |
121 |
result.setX(p.getX()); |
122 |
result.setY(p.getY()); |
123 |
|
124 |
} else if (point instanceof IDwgVertex) { |
125 |
result.setCoordinates(((IDwgVertex) point).getPoint()); |
126 |
} else {
|
127 |
throw new IllegalArgumentException(); |
128 |
} |
129 |
return result;
|
130 |
} |
131 |
|
132 |
} |