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 / surface / ellipse / Ellipse2DZ.java @ 42283
History | View | Annotate | Download (5.77 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.surface.ellipse; |
24 |
|
25 |
import java.awt.geom.PathIterator; |
26 |
|
27 |
import com.vividsolutions.jts.geom.Coordinate; |
28 |
|
29 |
import org.gvsig.fmap.geom.Geometry; |
30 |
import org.gvsig.fmap.geom.GeometryException; |
31 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
32 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
33 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
34 |
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D; |
35 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3D; |
36 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D; |
37 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D; |
38 |
import org.gvsig.fmap.geom.jts.primitive.point.Point3D; |
39 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D; |
40 |
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
41 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
42 |
import org.gvsig.fmap.geom.primitive.Line; |
43 |
import org.gvsig.fmap.geom.primitive.Point; |
44 |
import org.gvsig.fmap.geom.primitive.Polygon; |
45 |
|
46 |
|
47 |
/**
|
48 |
* @author fdiaz
|
49 |
*
|
50 |
*/
|
51 |
public class Ellipse2DZ extends AbstractEllipse { |
52 |
|
53 |
/**
|
54 |
*
|
55 |
*/
|
56 |
private static final long serialVersionUID = 3329324719860569909L; |
57 |
private double zValue = Double.NaN; |
58 |
|
59 |
/**
|
60 |
* @param subtype
|
61 |
*/
|
62 |
public Ellipse2DZ() {
|
63 |
super(Geometry.SUBTYPES.GEOM3D);
|
64 |
} |
65 |
|
66 |
|
67 |
/* (non-Javadoc)
|
68 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
69 |
*/
|
70 |
public Geometry cloneGeometry() {
|
71 |
Ellipse2DZ clone = new Ellipse2DZ();
|
72 |
clone.setPoints(init, end, ydist); |
73 |
return clone;
|
74 |
} |
75 |
|
76 |
/*
|
77 |
* (non-Javadoc)
|
78 |
*
|
79 |
* @see
|
80 |
* org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org
|
81 |
* .gvsig.fmap.geom.primitive.Point)
|
82 |
*/
|
83 |
@Override
|
84 |
protected Point fixPoint(Point point) { |
85 |
if (point instanceof Point3D) { |
86 |
Point3D point3D = (Point3D) point; |
87 |
if (Double.isNaN(zValue) && !(Double.isNaN(point3D.getZ()))) { |
88 |
zValue = point3D.getZ(); |
89 |
if (init!=null) { |
90 |
((Point3D) init).setZ(zValue); |
91 |
} |
92 |
if (end!=null) { |
93 |
((Point3D) end).setZ(zValue); |
94 |
} |
95 |
return point3D;
|
96 |
} |
97 |
} |
98 |
return new Point3D(point.getX(), point.getY(), Double.isNaN(zValue)?0:zValue); |
99 |
} |
100 |
|
101 |
/* (non-Javadoc)
|
102 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
|
103 |
*/
|
104 |
public com.vividsolutions.jts.geom.Geometry getJTS() {
|
105 |
PathIterator pi = getPathIterator(null); |
106 |
ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
|
107 |
|
108 |
double coords[] = new double[6]; |
109 |
while (!pi.isDone()) {
|
110 |
switch (pi.currentSegment(coords)) {
|
111 |
case PathIterator.SEG_MOVETO: |
112 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
113 |
break;
|
114 |
case PathIterator.SEG_LINETO: |
115 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
116 |
break;
|
117 |
case PathIterator.SEG_QUADTO: |
118 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
119 |
coordinates.add(new Coordinate(coords[2], coords[3], zValue)); |
120 |
break;
|
121 |
case PathIterator.SEG_CUBICTO: |
122 |
coordinates.add(new Coordinate(coords[0], coords[1], zValue)); |
123 |
coordinates.add(new Coordinate(coords[2], coords[3], zValue)); |
124 |
coordinates.add(new Coordinate(coords[4], coords[5], zValue)); |
125 |
break;
|
126 |
case PathIterator.SEG_CLOSE: |
127 |
coordinates.add((Coordinate)coordinates.get(0).clone());
|
128 |
break;
|
129 |
} |
130 |
pi.next(); |
131 |
} |
132 |
return JTSUtils.createJTSLinearRing(coordinates);
|
133 |
} |
134 |
|
135 |
/* (non-Javadoc)
|
136 |
* @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
137 |
*/
|
138 |
public MultiPoint toPoints() throws GeometryException { |
139 |
MultiPoint multiPoint = new MultiPoint3D();
|
140 |
Coordinate[] coordinates = getJTS().getCoordinates();
|
141 |
multiPoint.ensureCapacity(coordinates.length); |
142 |
for (int i = 0; i < coordinates.length; i++) { |
143 |
multiPoint.addPoint(new Point3D(coordinates[i]));
|
144 |
} |
145 |
return multiPoint;
|
146 |
} |
147 |
|
148 |
/* (non-Javadoc)
|
149 |
* @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
150 |
*/
|
151 |
public MultiLine toLines() throws GeometryException { |
152 |
MultiLine multiLine = new MultiLine3D();
|
153 |
Line line = new Line3D(getJTS().getCoordinates()); |
154 |
multiLine.addPrimitive(line); |
155 |
return multiLine;
|
156 |
} |
157 |
|
158 |
/* (non-Javadoc)
|
159 |
* @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
160 |
*/
|
161 |
public MultiPolygon toPolygons() throws GeometryException { |
162 |
MultiPolygon multiPolygon = new MultiPolygon3D();
|
163 |
Polygon polygon = new Polygon3D(getJTS().getCoordinates()); |
164 |
multiPolygon.addPrimitive(polygon); |
165 |
return multiPolygon;
|
166 |
} |
167 |
|
168 |
|
169 |
|
170 |
} |