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 / point / Point3D.java @ 42267
History | View | Annotate | Download (5.86 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.point; |
24 |
|
25 |
import java.awt.geom.AffineTransform; |
26 |
import java.awt.geom.PathIterator; |
27 |
|
28 |
import com.vividsolutions.jts.geom.Coordinate; |
29 |
|
30 |
import org.apache.commons.lang3.StringUtils; |
31 |
import org.hibernate.spatial.jts.mgeom.MCoordinate; |
32 |
|
33 |
import org.gvsig.fmap.geom.DirectPosition; |
34 |
import org.gvsig.fmap.geom.Geometry; |
35 |
import org.gvsig.fmap.geom.GeometryException; |
36 |
import org.gvsig.fmap.geom.GeometryLocator; |
37 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
38 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
39 |
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator; |
40 |
import org.gvsig.fmap.geom.jts.primitive.AbstractPrimitive; |
41 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
42 |
import org.gvsig.fmap.geom.primitive.Point; |
43 |
import org.gvsig.fmap.geom.type.GeometryType; |
44 |
|
45 |
|
46 |
/**
|
47 |
* @author fdiaz
|
48 |
*
|
49 |
*/
|
50 |
public class Point3D extends AbstractPoint { |
51 |
|
52 |
/**
|
53 |
*
|
54 |
*/
|
55 |
private static final long serialVersionUID = 7206091904842881396L; |
56 |
|
57 |
/**
|
58 |
*
|
59 |
*/
|
60 |
public Point3D(Coordinate coordinates) {
|
61 |
super(Geometry.SUBTYPES.GEOM3D, coordinates);
|
62 |
} |
63 |
|
64 |
/**
|
65 |
*
|
66 |
*/
|
67 |
public Point3D() {
|
68 |
this(new Coordinate(0, 0, 0)); |
69 |
} |
70 |
|
71 |
/**
|
72 |
*
|
73 |
*/
|
74 |
public Point3D(double x, double y, double z) { |
75 |
this(new Coordinate(x, y, z)); |
76 |
} |
77 |
|
78 |
|
79 |
public double getZ() { |
80 |
return this.coordinate.z; |
81 |
} |
82 |
|
83 |
/* (non-Javadoc)
|
84 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
85 |
*/
|
86 |
public int getDimension() { |
87 |
return 3; |
88 |
} |
89 |
|
90 |
/* (non-Javadoc)
|
91 |
* @see org.gvsig.fmap.geom.Geometry#getGeometryType()
|
92 |
*/
|
93 |
public GeometryType getGeometryType() {
|
94 |
try {
|
95 |
return GeometryLocator.getGeometryManager().getGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3D);
|
96 |
} catch (Exception e) { |
97 |
return null; |
98 |
} |
99 |
} |
100 |
|
101 |
/* (non-Javadoc)
|
102 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
103 |
*/
|
104 |
public Geometry cloneGeometry() {
|
105 |
return new Point3D((Coordinate)this.coordinate.clone()); |
106 |
} |
107 |
|
108 |
/* (non-Javadoc)
|
109 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
110 |
*/
|
111 |
public boolean is3D() { |
112 |
return true; |
113 |
} |
114 |
|
115 |
/* (non-Javadoc)
|
116 |
* @see org.gvsig.fmap.geom.jts.primitive.point.PointJTS#setJTSCoordinate(com.vividsolutions.jts.geom.Coordinate)
|
117 |
*/
|
118 |
public void setJTSCoordinate(Coordinate coordinate) { |
119 |
this.coordinate = coordinate;
|
120 |
} |
121 |
|
122 |
/**
|
123 |
* @param zValue
|
124 |
*/
|
125 |
public void setZ(double z) { |
126 |
this.coordinate.z = z;
|
127 |
} |
128 |
|
129 |
/*
|
130 |
* (non-Javadoc)
|
131 |
*
|
132 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
133 |
*/
|
134 |
public GeneralPathX getGeneralPath() {
|
135 |
return new DefaultGeneralPathX(new PointIterator(null), true, getZ()); |
136 |
} |
137 |
|
138 |
/*
|
139 |
* (non-Javadoc)
|
140 |
*
|
141 |
* @see
|
142 |
* org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
|
143 |
* )
|
144 |
*/
|
145 |
public PathIterator getPathIterator(AffineTransform at) { |
146 |
PointIterator pi = new PointIterator(at);
|
147 |
return pi;
|
148 |
} |
149 |
|
150 |
public class PointIterator extends GeneralPathXIterator { |
151 |
/** Transform applied on the coordinates during iteration */
|
152 |
private AffineTransform at; |
153 |
|
154 |
/** True when the point has been read once */
|
155 |
private boolean done; |
156 |
|
157 |
/**
|
158 |
* Creates a new PointIterator object.
|
159 |
*
|
160 |
* @param p The polygon
|
161 |
* @param at The affine transform applied to coordinates during iteration
|
162 |
*/
|
163 |
public PointIterator(AffineTransform at) { |
164 |
super(new GeneralPathX()); |
165 |
if (at == null) { |
166 |
at = new AffineTransform(); |
167 |
} |
168 |
|
169 |
this.at = at;
|
170 |
done = false;
|
171 |
} |
172 |
|
173 |
/**
|
174 |
* Return the winding rule for determining the interior of the path.
|
175 |
*
|
176 |
* @return <code>WIND_EVEN_ODD</code> by default.
|
177 |
*/
|
178 |
public int getWindingRule() { |
179 |
return PathIterator.WIND_EVEN_ODD; |
180 |
} |
181 |
|
182 |
/**
|
183 |
* @see java.awt.geom.PathIterator#next()
|
184 |
*/
|
185 |
public void next() { |
186 |
done = true;
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* @see java.awt.geom.PathIterator#isDone()
|
191 |
*/
|
192 |
public boolean isDone() { |
193 |
return done;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* @see java.awt.geom.PathIterator#currentSegment(double[])
|
198 |
*/
|
199 |
public int currentSegment(double[] coords) { |
200 |
coords[0] = getX();
|
201 |
coords[1] = getY();
|
202 |
coords[2] = getZ();
|
203 |
at.transform(coords, 0, coords, 0, 1); |
204 |
|
205 |
return PathIterator.SEG_MOVETO; |
206 |
} |
207 |
|
208 |
/* (non-Javadoc)
|
209 |
* @see java.awt.geom.PathIterator#currentSegment(float[])
|
210 |
*/
|
211 |
public int currentSegment(float[] coords) { |
212 |
coords[0] = (float) getX(); |
213 |
coords[1] = (float) getY(); |
214 |
coords[2] = (float) getZ(); |
215 |
|
216 |
at.transform(coords, 0, coords, 0, 1); |
217 |
|
218 |
return PathIterator.SEG_MOVETO; |
219 |
} |
220 |
} |
221 |
|
222 |
|
223 |
|
224 |
} |