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 | 42267 | fdiaz | /* 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 | 45762 | fdiaz | import java.awt.geom.PathIterator; |
27 | 42267 | fdiaz | import org.gvsig.fmap.geom.Geometry; |
28 | 42269 | fdiaz | 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 | 47432 | fdiaz | import org.gvsig.fmap.geom.jts.aggregate.MultiLine2DM; |
33 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D; |
34 | 47432 | fdiaz | import org.gvsig.fmap.geom.jts.aggregate.MultiPoint2DM; |
35 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3D; |
36 | 47432 | fdiaz | import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon2DM; |
37 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D; |
38 | 47432 | fdiaz | import org.gvsig.fmap.geom.jts.mgeom.MCoordinate; |
39 | import org.gvsig.fmap.geom.jts.primitive.curve.line.Line2DM; |
||
40 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D; |
41 | 47432 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.Point2DM; |
42 | 42267 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.Point3D; |
43 | import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
||
44 | 47432 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2DM; |
45 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D; |
46 | 42267 | fdiaz | import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
47 | import org.gvsig.fmap.geom.jts.util.JTSUtils; |
||
48 | 42269 | fdiaz | import org.gvsig.fmap.geom.primitive.Line; |
49 | 42267 | fdiaz | import org.gvsig.fmap.geom.primitive.Point; |
50 | 42269 | fdiaz | import org.gvsig.fmap.geom.primitive.Polygon; |
51 | 42267 | fdiaz | |
52 | /**
|
||
53 | * @author fdiaz
|
||
54 | *
|
||
55 | */
|
||
56 | 47432 | fdiaz | public class Arc2DM extends AbstractArc { |
57 | 42267 | fdiaz | |
58 | /**
|
||
59 | *
|
||
60 | */
|
||
61 | private static final long serialVersionUID = -5691008010954470053L; |
||
62 | 47432 | fdiaz | private double mValue = Double.NaN; |
63 | 42267 | fdiaz | |
64 | /**
|
||
65 | * @param subtype
|
||
66 | */
|
||
67 | 47432 | fdiaz | public Arc2DM() {
|
68 | 42267 | fdiaz | 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 | 45242 | fdiaz | 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 | 42267 | fdiaz | |
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 | 44099 | jjdelcerro | Point3D center = new Point3D(this.getProjection(), JTSUtils.getCircumcentre(init, middle, end)); |
110 | 42267 | fdiaz | return center;
|
111 | } |
||
112 | |||
113 | /*
|
||
114 | * (non-Javadoc)
|
||
115 | *
|
||
116 | * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
||
117 | */
|
||
118 | 47346 | fdiaz | @Override
|
119 | 42267 | fdiaz | public Geometry cloneGeometry() {
|
120 | 47432 | fdiaz | Arc2DM arc2D = new Arc2DM();
|
121 | 42283 | fdiaz | arc2D.setPoints((Point)init.cloneGeometry(), (Point)middle.cloneGeometry(), (Point)end.cloneGeometry()); |
122 | 47346 | fdiaz | arc2D.setProjection(this.getProjection());
|
123 | 42267 | fdiaz | 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 | 47432 | fdiaz | if (point instanceof Point2DM) { |
136 | Point2DM point2DM = (Point2DM) point; |
||
137 | if (Double.isNaN(mValue) && !(Double.isNaN(point2DM.getM()))) { |
||
138 | mValue = point2DM.getM(); |
||
139 | 42267 | fdiaz | if (init!=null) { |
140 | 47432 | fdiaz | ((Point2DM) init).setM(mValue); |
141 | 42267 | fdiaz | } |
142 | if (middle!=null) { |
||
143 | 47432 | fdiaz | ((Point2DM) middle).setM(mValue); |
144 | 42267 | fdiaz | } |
145 | if (end!=null) { |
||
146 | 47432 | fdiaz | ((Point2DM) end).setM(mValue); |
147 | 42267 | fdiaz | } |
148 | 47432 | fdiaz | return point2DM;
|
149 | 42267 | fdiaz | } |
150 | } |
||
151 | 47432 | fdiaz | return new Point3D(point.getX(), point.getY(), Double.isNaN(mValue)?0:mValue); |
152 | 42267 | fdiaz | } |
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 | 47432 | fdiaz | coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue)); |
168 | 42267 | fdiaz | break;
|
169 | case PathIterator.SEG_LINETO: |
||
170 | 47432 | fdiaz | coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue)); |
171 | 42267 | fdiaz | break;
|
172 | case PathIterator.SEG_QUADTO: |
||
173 | 47432 | fdiaz | coordinates.add(new MCoordinate(coords[0], coords[1], Double.NaN, mValue)); |
174 | coordinates.add(new MCoordinate(coords[2], coords[3], Double.NaN, mValue)); |
||
175 | 42267 | fdiaz | break;
|
176 | case PathIterator.SEG_CUBICTO: |
||
177 | 47432 | fdiaz | 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 | 42267 | fdiaz | break;
|
181 | case PathIterator.SEG_CLOSE: |
||
182 | coordinates.add(coordinates.get(0));
|
||
183 | break;
|
||
184 | } |
||
185 | pi.next(); |
||
186 | } |
||
187 | 42268 | fdiaz | return JTSUtils.createJTSLineString(coordinates);
|
188 | 42267 | fdiaz | } |
189 | 42269 | fdiaz | |
190 | /* (non-Javadoc)
|
||
191 | * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
||
192 | */
|
||
193 | public MultiPoint toPoints() throws GeometryException { |
||
194 | 47432 | fdiaz | MultiPoint multiPoint = new MultiPoint2DM();
|
195 | 42269 | fdiaz | Coordinate[] coordinates = getJTS().getCoordinates();
|
196 | 42271 | fdiaz | multiPoint.ensureCapacity(coordinates.length); |
197 | 42269 | fdiaz | for (int i = 0; i < coordinates.length; i++) { |
198 | 47432 | fdiaz | multiPoint.addPoint(new Point2DM(this.getProjection(), coordinates[i].x, coordinates[i].y, mValue)); |
199 | 42269 | fdiaz | } |
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 | 47432 | fdiaz | MultiLine multiLine = new MultiLine2DM();
|
208 | Line line = new Line2DM(getJTS().getCoordinates()); |
||
209 | 42269 | fdiaz | 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 | 47432 | fdiaz | MultiPolygon multiPolygon = new MultiPolygon2DM();
|
218 | Polygon polygon = new Polygon2DM(getJTS().getCoordinates()); |
||
219 | 42269 | fdiaz | multiPolygon.addPrimitive(polygon); |
220 | return multiPolygon;
|
||
221 | } |
||
222 | 42267 | fdiaz | } |