svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / primitive / curve / arc / Arc2DM.java @ 47432
History | View | Annotate | Download (7.88 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2015 gvSIG Association
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.geom.jts.primitive.curve.arc; |
24 |
|
25 |
import com.vividsolutions.jts.geom.Coordinate; |
26 |
import java.awt.geom.PathIterator; |
27 |
import org.gvsig.fmap.geom.Geometry; |
28 |
import org.gvsig.fmap.geom.GeometryException; |
29 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
30 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
31 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
32 |
import org.gvsig.fmap.geom.jts.aggregate.MultiLine2DM; |
33 |
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D; |
34 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint2DM; |
35 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3D; |
36 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon2DM; |
37 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D; |
38 |
import org.gvsig.fmap.geom.jts.mgeom.MCoordinate; |
39 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2DM; |
40 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D; |
41 |
import org.gvsig.fmap.geom.jts.primitive.point.Point2DM; |
42 |
import org.gvsig.fmap.geom.jts.primitive.point.Point3D; |
43 |
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
44 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2DM; |
45 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D; |
46 |
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
47 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
48 |
import org.gvsig.fmap.geom.primitive.Line; |
49 |
import org.gvsig.fmap.geom.primitive.Point; |
50 |
import org.gvsig.fmap.geom.primitive.Polygon; |
51 |
|
52 |
/**
|
53 |
* @author fdiaz
|
54 |
*
|
55 |
*/
|
56 |
public class Arc2DM extends AbstractArc { |
57 |
|
58 |
/**
|
59 |
*
|
60 |
*/
|
61 |
private static final long serialVersionUID = -5691008010954470053L; |
62 |
private double mValue = Double.NaN; |
63 |
|
64 |
/**
|
65 |
* @param subtype
|
66 |
*/
|
67 |
public Arc2DM() {
|
68 |
super(Geometry.SUBTYPES.GEOM3D);
|
69 |
} |
70 |
|
71 |
/*
|
72 |
* (non-Javadoc)
|
73 |
*
|
74 |
* @see
|
75 |
* org.gvsig.fmap.geom.primitive.Arc#setPoints(org.gvsig.fmap.geom.primitive
|
76 |
* .Point, double, double, double)
|
77 |
*/
|
78 |
public void setPoints(Point center, double radius, double startAngle, double angleExt) { |
79 |
center = fixPoint(center); |
80 |
|
81 |
init = new Point3D(
|
82 |
center.getX()+radius*Math.cos(startAngle),
|
83 |
center.getY()+radius*Math.sin(startAngle),
|
84 |
((Point3D) center).getZ() |
85 |
); |
86 |
|
87 |
double midAngle = startAngle+angleExt/2; |
88 |
middle = new Point3D(
|
89 |
center.getX()+radius*Math.cos(midAngle),
|
90 |
center.getY()+radius*Math.sin(midAngle),
|
91 |
((Point3D) center).getZ() |
92 |
); |
93 |
|
94 |
end = new Point3D(
|
95 |
center.getX()+radius*Math.cos(startAngle+angleExt),
|
96 |
center.getY()+radius*Math.sin(startAngle+angleExt),
|
97 |
((Point3D) center).getZ() |
98 |
); |
99 |
|
100 |
} |
101 |
|
102 |
/*
|
103 |
* (non-Javadoc)
|
104 |
*
|
105 |
* @see org.gvsig.fmap.geom.primitive.Arc#getCenterPoint()
|
106 |
*/
|
107 |
public Point getCenterPoint() { |
108 |
((PointJTS) init).getJTS(); |
109 |
Point3D center = new Point3D(this.getProjection(), JTSUtils.getCircumcentre(init, middle, end)); |
110 |
return center;
|
111 |
} |
112 |
|
113 |
/*
|
114 |
* (non-Javadoc)
|
115 |
*
|
116 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
117 |
*/
|
118 |
@Override
|
119 |
public Geometry cloneGeometry() {
|
120 |
Arc2DM arc2D = new Arc2DM();
|
121 |
arc2D.setPoints((Point)init.cloneGeometry(), (Point)middle.cloneGeometry(), (Point)end.cloneGeometry()); |
122 |
arc2D.setProjection(this.getProjection());
|
123 |
return arc2D;
|
124 |
} |
125 |
|
126 |
/*
|
127 |
* (non-Javadoc)
|
128 |
*
|
129 |
* @see
|
130 |
* org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org
|
131 |
* .gvsig.fmap.geom.primitive.Point)
|
132 |
*/
|
133 |
@Override
|
134 |
protected Point fixPoint(Point point) { |
135 |
if (point instanceof Point2DM) { |
136 |
Point2DM point2DM = (Point2DM) point; |
137 |
if (Double.isNaN(mValue) && !(Double.isNaN(point2DM.getM()))) { |
138 |
mValue = point2DM.getM(); |
139 |
if (init!=null) { |
140 |
((Point2DM) init).setM(mValue); |
141 |
} |
142 |
if (middle!=null) { |
143 |
((Point2DM) middle).setM(mValue); |
144 |
} |
145 |
if (end!=null) { |
146 |
((Point2DM) end).setM(mValue); |
147 |
} |
148 |
return point2DM;
|
149 |
} |
150 |
} |
151 |
return new Point3D(point.getX(), point.getY(), Double.isNaN(mValue)?0:mValue); |
152 |
} |
153 |
|
154 |
/*
|
155 |
* (non-Javadoc)
|
156 |
*
|
157 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
|
158 |
*/
|
159 |
public com.vividsolutions.jts.geom.Geometry getJTS() {
|
160 |
PathIterator pi = getPathIterator(null); |
161 |
ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
|
162 |
|
163 |
double coords[] = new double[6]; |
164 |
while (!pi.isDone()) {
|
165 |
switch (pi.currentSegment(coords)) {
|
166 |
case PathIterator.SEG_MOVETO: |
167 |
coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue)); |
168 |
break;
|
169 |
case PathIterator.SEG_LINETO: |
170 |
coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue)); |
171 |
break;
|
172 |
case PathIterator.SEG_QUADTO: |
173 |
coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue)); |
174 |
coordinates.add(new MCoordinate(coords[2], coords[3], Double.NaN, mValue)); |
175 |
break;
|
176 |
case PathIterator.SEG_CUBICTO: |
177 |
coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue)); |
178 |
coordinates.add(new MCoordinate(coords[2], coords[3], Double.NaN, mValue)); |
179 |
coordinates.add(new MCoordinate(coords[4], coords[5], Double.NaN, mValue)); |
180 |
break;
|
181 |
case PathIterator.SEG_CLOSE: |
182 |
coordinates.add(coordinates.get(0));
|
183 |
break;
|
184 |
} |
185 |
pi.next(); |
186 |
} |
187 |
return JTSUtils.createJTSLineString(coordinates);
|
188 |
} |
189 |
|
190 |
/* (non-Javadoc)
|
191 |
* @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
192 |
*/
|
193 |
public MultiPoint toPoints() throws GeometryException { |
194 |
MultiPoint multiPoint = new MultiPoint2DM();
|
195 |
Coordinate[] coordinates = getJTS().getCoordinates();
|
196 |
multiPoint.ensureCapacity(coordinates.length); |
197 |
for (int i = 0; i < coordinates.length; i++) { |
198 |
multiPoint.addPoint(new Point2DM(this.getProjection(), coordinates[i].x, coordinates[i].y, mValue)); |
199 |
} |
200 |
return multiPoint;
|
201 |
} |
202 |
|
203 |
/* (non-Javadoc)
|
204 |
* @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
205 |
*/
|
206 |
public MultiLine toLines() throws GeometryException { |
207 |
MultiLine multiLine = new MultiLine2DM();
|
208 |
Line line = new Line2DM(getJTS().getCoordinates()); |
209 |
multiLine.addPrimitive(line); |
210 |
return multiLine;
|
211 |
} |
212 |
|
213 |
/* (non-Javadoc)
|
214 |
* @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
215 |
*/
|
216 |
public MultiPolygon toPolygons() throws GeometryException { |
217 |
MultiPolygon multiPolygon = new MultiPolygon2DM();
|
218 |
Polygon polygon = new Polygon2DM(getJTS().getCoordinates()); |
219 |
multiPolygon.addPrimitive(polygon); |
220 |
return multiPolygon;
|
221 |
} |
222 |
} |