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 / Point3DM.java @ 47346
History | View | Annotate | Download (9.26 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 com.vividsolutions.jts.geom.Coordinate; |
26 |
import java.awt.geom.AffineTransform; |
27 |
import java.awt.geom.PathIterator; |
28 |
import org.cresques.cts.IProjection; |
29 |
import org.gvsig.fmap.geom.Geometry; |
30 |
import org.gvsig.fmap.geom.GeometryException; |
31 |
import org.gvsig.fmap.geom.GeometryLocator; |
32 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
33 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3DM; |
34 |
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
35 |
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator; |
36 |
import org.gvsig.fmap.geom.jts.mgeom.MCoordinate; |
37 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
38 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
39 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
40 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
41 |
import org.gvsig.fmap.geom.primitive.Point; |
42 |
import org.gvsig.fmap.geom.primitive.PointM; |
43 |
import org.gvsig.fmap.geom.type.GeometryType; |
44 |
|
45 |
/**
|
46 |
* @author fdiaz
|
47 |
*
|
48 |
*/
|
49 |
public class Point3DM extends AbstractPoint implements PointM { |
50 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
private static final long serialVersionUID = 5749444180040735731L; |
55 |
|
56 |
/**
|
57 |
*
|
58 |
* @param proj
|
59 |
* @param coordinates
|
60 |
*/
|
61 |
public Point3DM(IProjection proj, Coordinate coordinates) {
|
62 |
super(Geometry.SUBTYPES.GEOM3DM, MCoordinate.convertCoordinate(coordinates));
|
63 |
} |
64 |
|
65 |
/**
|
66 |
*
|
67 |
*/
|
68 |
public Point3DM() {
|
69 |
this(null, JTSUtils.createMCoordinate(0, 0, 0, 0)); |
70 |
} |
71 |
|
72 |
/**
|
73 |
*
|
74 |
* @param x
|
75 |
* @param y
|
76 |
* @param z
|
77 |
* @param m
|
78 |
*/
|
79 |
public Point3DM(double x, double y, double z, double m) { |
80 |
this(null, JTSUtils.createMCoordinate(x, y, z, m)); |
81 |
} |
82 |
|
83 |
public Point3DM(IProjection proj, double x, double y, double z, double m) { |
84 |
this(proj, JTSUtils.createMCoordinate(x, y, z, m));
|
85 |
} |
86 |
|
87 |
public double getZ() { |
88 |
return this.coordinate.z; |
89 |
} |
90 |
|
91 |
@Override
|
92 |
public double getM() { |
93 |
return ((MCoordinate) this.coordinate).m; |
94 |
} |
95 |
|
96 |
/*
|
97 |
* (non-Javadoc)
|
98 |
*
|
99 |
* @see org.gvsig.fmap.geom.Geometry#getDimension()
|
100 |
*/
|
101 |
@Override
|
102 |
public int getDimension() { |
103 |
return 4; |
104 |
} |
105 |
|
106 |
/*
|
107 |
* (non-Javadoc)
|
108 |
*
|
109 |
* @see org.gvsig.fmap.geom.Geometry#getGeometryType()
|
110 |
*/
|
111 |
@Override
|
112 |
public GeometryType getGeometryType() {
|
113 |
try {
|
114 |
return GeometryLocator.getGeometryManager()
|
115 |
.getGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3DM); |
116 |
} catch (Exception e) { |
117 |
return null; |
118 |
} |
119 |
} |
120 |
|
121 |
/*
|
122 |
* (non-Javadoc)
|
123 |
*
|
124 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
125 |
*/
|
126 |
@Override
|
127 |
public Point cloneGeometry() { |
128 |
Point3DM clone = new Point3DM(this.getProjection(), MCoordinate.convertCoordinate((Coordinate) coordinate.clone())); |
129 |
clone.setProjection(this.getProjection());
|
130 |
return clone;
|
131 |
} |
132 |
|
133 |
/*
|
134 |
* (non-Javadoc)
|
135 |
*
|
136 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
|
137 |
*/
|
138 |
@Override
|
139 |
public boolean is3D() { |
140 |
return true; |
141 |
} |
142 |
|
143 |
/*
|
144 |
* (non-Javadoc)
|
145 |
*
|
146 |
* @see
|
147 |
* org.gvsig.fmap.geom.jts.primitive.point.PointJTS#setJTSCoordinate(com
|
148 |
* .vividsolutions.jts.geom.Coordinate)
|
149 |
*/
|
150 |
@Override
|
151 |
public void setJTSCoordinate(Coordinate coordinate) { |
152 |
this.coordinate = coordinate;
|
153 |
} |
154 |
|
155 |
/*
|
156 |
* (non-Javadoc)
|
157 |
*
|
158 |
* @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
|
159 |
*/
|
160 |
@Override
|
161 |
public GeneralPathX getGeneralPath() {
|
162 |
return new DefaultGeneralPathX(new PointIterator(null), true, getZ()); |
163 |
} |
164 |
|
165 |
/*
|
166 |
* (non-Javadoc)
|
167 |
*
|
168 |
* @see
|
169 |
* org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
|
170 |
* )
|
171 |
*/
|
172 |
@Override
|
173 |
public PathIterator getPathIterator(AffineTransform at) { |
174 |
PointIterator pi = new PointIterator(at);
|
175 |
return pi;
|
176 |
} |
177 |
|
178 |
public class PointIterator extends GeneralPathXIterator { |
179 |
|
180 |
/** Transform applied on the coordinates during iteration */
|
181 |
private final AffineTransform at; |
182 |
|
183 |
/** True when the point has been read once */
|
184 |
private boolean done; |
185 |
|
186 |
/**
|
187 |
* Creates a new PointIterator object.
|
188 |
*
|
189 |
* @param at
|
190 |
* The affine transform applied to coordinates during
|
191 |
* iteration
|
192 |
*/
|
193 |
public PointIterator(AffineTransform at) { |
194 |
super(new GeneralPathX()); |
195 |
if (at == null) { |
196 |
at = new AffineTransform(); |
197 |
} |
198 |
|
199 |
this.at = at;
|
200 |
done = false;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* Return the winding rule for determining the interior of the path.
|
205 |
*
|
206 |
* @return <code>WIND_EVEN_ODD</code> by default.
|
207 |
*/
|
208 |
@Override
|
209 |
public int getWindingRule() { |
210 |
return PathIterator.WIND_EVEN_ODD; |
211 |
} |
212 |
|
213 |
/**
|
214 |
* @see java.awt.geom.PathIterator#next()
|
215 |
*/
|
216 |
@Override
|
217 |
public void next() { |
218 |
done = true;
|
219 |
} |
220 |
|
221 |
/**
|
222 |
* @see java.awt.geom.PathIterator#isDone()
|
223 |
*/
|
224 |
@Override
|
225 |
public boolean isDone() { |
226 |
return done;
|
227 |
} |
228 |
|
229 |
/**
|
230 |
* @param coords
|
231 |
* @return
|
232 |
* @see java.awt.geom.PathIterator#currentSegment(double[])
|
233 |
*/
|
234 |
@Override
|
235 |
public int currentSegment(double[] coords) { |
236 |
coords[0] = getX();
|
237 |
coords[1] = getY();
|
238 |
coords[2] = getZ();
|
239 |
at.transform(coords, 0, coords, 0, 1); |
240 |
|
241 |
return PathIterator.SEG_MOVETO; |
242 |
} |
243 |
|
244 |
/*
|
245 |
* (non-Javadoc)
|
246 |
*
|
247 |
* @see java.awt.geom.PathIterator#currentSegment(float[])
|
248 |
*/
|
249 |
@Override
|
250 |
public int currentSegment(float[] coords) { |
251 |
coords[0] = (float) getX(); |
252 |
coords[1] = (float) getY(); |
253 |
coords[2] = (float) getZ(); |
254 |
|
255 |
at.transform(coords, 0, coords, 0, 1); |
256 |
|
257 |
return PathIterator.SEG_MOVETO; |
258 |
} |
259 |
} |
260 |
|
261 |
|
262 |
/* (non-Javadoc)
|
263 |
* @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
264 |
*/
|
265 |
@Override
|
266 |
public MultiPoint toPoints() throws GeometryException { |
267 |
MultiPoint multiPoint = new MultiPoint3DM();
|
268 |
multiPoint.addPoint(this);
|
269 |
return multiPoint;
|
270 |
} |
271 |
|
272 |
/* (non-Javadoc)
|
273 |
* @see org.gvsig.fmap.geom.Geometry#offset(double)
|
274 |
*/
|
275 |
@Override
|
276 |
public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException { |
277 |
return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance)); |
278 |
} |
279 |
|
280 |
@Override
|
281 |
public String toString() { |
282 |
StringBuilder builder = new StringBuilder(); |
283 |
builder.append("POINT ZM (");
|
284 |
for( int i=0; i<this.getDimension()-1; i++) { |
285 |
builder.append(this.getCoordinateAt(i));
|
286 |
builder.append(" ");
|
287 |
} |
288 |
builder.append(this.getCoordinateAt(this.getDimension()-1)); |
289 |
builder.append(")");
|
290 |
return builder.toString();
|
291 |
} |
292 |
|
293 |
@Override
|
294 |
public boolean equals(Object obj) { |
295 |
if( obj == null ) { |
296 |
return false; |
297 |
} |
298 |
Point other;
|
299 |
try {
|
300 |
other = (Point) obj;
|
301 |
} catch(ClassCastException e) { |
302 |
return false; |
303 |
} |
304 |
if( this.getGeometryType().getSubType() != other.getGeometryType().getSubType() ) { |
305 |
return false; |
306 |
} |
307 |
if( this.coordinate.x != other.getX() ) { |
308 |
return false; |
309 |
} |
310 |
if( this.coordinate.y != other.getY() ) { |
311 |
return false; |
312 |
} |
313 |
if( this.coordinate.z != other.getCoordinateAt(2)) { |
314 |
return false; |
315 |
} |
316 |
if( ((MCoordinate)this.coordinate).m != other.getCoordinateAt(3)) { |
317 |
return false; |
318 |
} |
319 |
return true; |
320 |
} |
321 |
@Override
|
322 |
public Point force3D() { |
323 |
Point3D p = new Point3D(this.getProjection(), this.coordinate.x, this.coordinate.y, this.coordinate.z); |
324 |
return p;
|
325 |
} |
326 |
|
327 |
@Override
|
328 |
public Point force2DM() { |
329 |
Point2DM p = new Point2DM(this.getProjection(), this.coordinate.x, this.coordinate.y, ((MCoordinate)this.coordinate).m); |
330 |
return p;
|
331 |
} |
332 |
|
333 |
@Override
|
334 |
public Point force3DM() { |
335 |
Point3DM p = new Point3DM(this.getProjection(), this.coordinate.x, this.coordinate.y, this.coordinate.z, ((MCoordinate)this.coordinate).m); |
336 |
return p;
|
337 |
} |
338 |
|
339 |
} |