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