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 / circle / BaseCircle2DZM.java @ 47432
History | View | Annotate | Download (6.97 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.circle; |
24 |
|
25 |
import com.vividsolutions.jts.geom.Coordinate; |
26 |
import java.awt.geom.PathIterator; |
27 |
import org.gvsig.fmap.geom.GeometryException; |
28 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
29 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
30 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
31 |
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D; |
32 |
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3DM; |
33 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3D; |
34 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3DM; |
35 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D; |
36 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3DM; |
37 |
import org.gvsig.fmap.geom.jts.mgeom.MCoordinate; |
38 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D; |
39 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3DM; |
40 |
import org.gvsig.fmap.geom.jts.primitive.point.Point2DM; |
41 |
import org.gvsig.fmap.geom.jts.primitive.point.Point3D; |
42 |
import org.gvsig.fmap.geom.jts.primitive.point.Point3DM; |
43 |
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS; |
44 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D; |
45 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM; |
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 |
/**
|
54 |
* @author fdiaz
|
55 |
*
|
56 |
*/
|
57 |
public abstract class BaseCircle2DZM extends AbstractCircle { |
58 |
|
59 |
/**
|
60 |
* @param type
|
61 |
* @param subtype
|
62 |
* @param center
|
63 |
* @param radius
|
64 |
*/
|
65 |
public BaseCircle2DZM(int type, int subtype, Point center, double radius) { |
66 |
super(type, subtype, center, radius);
|
67 |
} |
68 |
|
69 |
/**
|
70 |
* @param circle
|
71 |
* @param geom2d
|
72 |
*/
|
73 |
public BaseCircle2DZM(int type, int subtype) { |
74 |
super(type,subtype);
|
75 |
} |
76 |
|
77 |
/*
|
78 |
* (non-Javadoc)
|
79 |
*
|
80 |
* @see
|
81 |
* org.gvsig.fmap.geom.primitive.Circle#setPoints(org.gvsig.fmap.geom.primitive
|
82 |
* .Point, org.gvsig.fmap.geom.primitive.Point,
|
83 |
* org.gvsig.fmap.geom.primitive.Point)
|
84 |
*/
|
85 |
public void setPoints(Point p1, Point p2, Point p3) { |
86 |
this.center = new Point3DM(p1.getProjection(),JTSUtils.getCircumcentre(p1, p2, p3)); |
87 |
//Por si los tres puntos no tienen la misma z o la misma m
|
88 |
Point3DM aPoint = new Point3DM(p1.getX(), p1.getY(), ((Point3DM)center).getZ(), ((Point3DM)center).getM());
|
89 |
this.radius = ((PointJTS) this.center).getJTS().distance(aPoint.getJTS()); |
90 |
this.setProjection(this.center.getProjection()); |
91 |
} |
92 |
|
93 |
/*
|
94 |
* (non-Javadoc)
|
95 |
*
|
96 |
* @see
|
97 |
* org.gvsig.fmap.geom.jts.primitive.surface.circle.AbstractCircle#fixPoint
|
98 |
* (org.gvsig.fmap.geom.primitive.Point)
|
99 |
*/
|
100 |
@Override
|
101 |
protected Point fixPoint(Point point) { |
102 |
if (point instanceof Point3DM) { |
103 |
return point;
|
104 |
} |
105 |
if (point instanceof Point3D) { |
106 |
return new Point3DM(point.getX(), point.getY(), ((Point3D) point).getZ(), 0); |
107 |
} |
108 |
if (point instanceof Point2DM) { |
109 |
return new Point3DM(point.getX(), point.getY(), 0, ((Point2DM) point).getM()); |
110 |
} |
111 |
return new Point3DM(point.getX(), point.getY(), 0, 0); |
112 |
} |
113 |
|
114 |
/**
|
115 |
* @return
|
116 |
*/
|
117 |
protected ArrayListCoordinateSequence getJTSCoordinates() {
|
118 |
PathIterator pi = getPathIterator(null); |
119 |
ArrayListCoordinateSequence coordinates = new ArrayListCoordinateSequence();
|
120 |
|
121 |
Point3DM c = (Point3DM)getCenter(); |
122 |
double zValue = c.getZ();
|
123 |
double mValue = c.getM();
|
124 |
double coords[] = new double[6]; |
125 |
while (!pi.isDone()) {
|
126 |
switch (pi.currentSegment(coords)) {
|
127 |
case PathIterator.SEG_MOVETO: |
128 |
coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue)); |
129 |
break;
|
130 |
case PathIterator.SEG_LINETO: |
131 |
coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue)); |
132 |
break;
|
133 |
case PathIterator.SEG_QUADTO: |
134 |
coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue)); |
135 |
coordinates.add(new MCoordinate(coords[2], coords[3], zValue, mValue)); |
136 |
break;
|
137 |
case PathIterator.SEG_CUBICTO: |
138 |
coordinates.add(new MCoordinate(coords[0], coords[1], zValue, mValue)); |
139 |
coordinates.add(new MCoordinate(coords[2], coords[3], zValue, mValue)); |
140 |
coordinates.add(new MCoordinate(coords[4], coords[5], zValue, mValue)); |
141 |
break;
|
142 |
case PathIterator.SEG_CLOSE: |
143 |
coordinates.add(coordinates.get(0));
|
144 |
break;
|
145 |
} |
146 |
pi.next(); |
147 |
} |
148 |
if(!coordinates.get(0).equals(coordinates.get(coordinates.size()-1))){ |
149 |
coordinates.add((Coordinate)coordinates.get(0).clone());
|
150 |
} |
151 |
return coordinates;
|
152 |
} |
153 |
|
154 |
/* (non-Javadoc)
|
155 |
* @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
156 |
*/
|
157 |
public MultiPoint toPoints() throws GeometryException { |
158 |
MultiPoint multiPoint = new MultiPoint3DM();
|
159 |
Coordinate[] coordinates = getJTS().getCoordinates();
|
160 |
multiPoint.ensureCapacity(coordinates.length); |
161 |
for (int i = 0; i < coordinates.length; i++) { |
162 |
multiPoint.addPoint(new Point3DM(this.getProjection(), coordinates[i])); |
163 |
} |
164 |
return multiPoint;
|
165 |
} |
166 |
|
167 |
/* (non-Javadoc)
|
168 |
* @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
169 |
*/
|
170 |
public MultiLine toLines() throws GeometryException { |
171 |
MultiLine multiLine = new MultiLine3DM();
|
172 |
Line line = new Line3DM(getJTS().getCoordinates()); |
173 |
multiLine.addPrimitive(line); |
174 |
return multiLine;
|
175 |
} |
176 |
|
177 |
/* (non-Javadoc)
|
178 |
* @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
179 |
*/
|
180 |
public MultiPolygon toPolygons() throws GeometryException { |
181 |
MultiPolygon multiPolygon = new MultiPolygon3DM();
|
182 |
Polygon polygon = new Polygon3DM(getJTS().getCoordinates()); |
183 |
multiPolygon.addPrimitive(polygon); |
184 |
return multiPolygon;
|
185 |
} |
186 |
|
187 |
|
188 |
} |