Statistics
| Revision:

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
/* 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
    /**
92
     * @param zValue
93
     */
94
    public void setZ(double z) {
95
        this.coordinate.z = z;
96
    }
97

    
98
    @Override
99
    public double getM() {
100
        return ((MCoordinate) this.coordinate).m;
101
    }
102

    
103
    @Override
104
    public void setM(double m) {
105
        ((MCoordinate)this.coordinate).m = m;
106
    }
107
    
108
    /*
109
     * (non-Javadoc)
110
     *
111
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
112
     */
113
    @Override
114
    public int getDimension() {
115
        return 4;
116
    }
117

    
118
    /*
119
     * (non-Javadoc)
120
     *
121
     * @see org.gvsig.fmap.geom.Geometry#getGeometryType()
122
     */
123
    @Override
124
    public GeometryType getGeometryType() {
125
        try {
126
            return GeometryLocator.getGeometryManager()
127
                .getGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3DM);
128
        } catch (Exception e) {
129
            return null;
130
        }
131
    }
132

    
133
    /*
134
     * (non-Javadoc)
135
     *
136
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
137
     */
138
    @Override
139
    public Point cloneGeometry() {
140
        Point3DM clone = new Point3DM(this.getProjection(), MCoordinate.convertCoordinate((Coordinate) coordinate.clone()));
141
        clone.setProjection(this.getProjection());
142
        return clone;
143
    }
144

    
145
    /*
146
     * (non-Javadoc)
147
     *
148
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
149
     */
150
    @Override
151
    public boolean is3D() {
152
        return true;
153
    }
154

    
155
    /*
156
     * (non-Javadoc)
157
     *
158
     * @see
159
     * org.gvsig.fmap.geom.jts.primitive.point.PointJTS#setJTSCoordinate(com
160
     * .vividsolutions.jts.geom.Coordinate)
161
     */
162
    @Override
163
    public void setJTSCoordinate(Coordinate coordinate) {
164
        this.coordinate = coordinate;
165
    }
166

    
167
    /*
168
     * (non-Javadoc)
169
     *
170
     * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
171
     */
172
    @Override
173
    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
    @Override
185
    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
        private final AffineTransform at;
194

    
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
        @Override
221
        public int getWindingRule() {
222
            return PathIterator.WIND_EVEN_ODD;
223
        }
224

    
225
        /**
226
         * @see java.awt.geom.PathIterator#next()
227
         */
228
        @Override
229
        public void next() {
230
            done = true;
231
        }
232

    
233
        /**
234
         * @see java.awt.geom.PathIterator#isDone()
235
         */
236
        @Override
237
        public boolean isDone() {
238
            return done;
239
        }
240

    
241
        /**
242
         * @param coords
243
         * @return 
244
         * @see java.awt.geom.PathIterator#currentSegment(double[])
245
         */
246
        @Override
247
        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
        @Override
262
        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

    
273

    
274
    /* (non-Javadoc)
275
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
276
     */
277
    @Override
278
    public MultiPoint toPoints() throws GeometryException {
279
        MultiPoint multiPoint = new MultiPoint3DM();
280
        multiPoint.addPoint(this);
281
        return multiPoint;
282
    }
283

    
284
    /* (non-Javadoc)
285
     * @see org.gvsig.fmap.geom.Geometry#offset(double)
286
     */
287
    @Override
288
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
289
        return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance));
290
    }
291

    
292
    @Override
293
    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
    
305
    @Override
306
    public boolean equals(Object obj) {
307
        if( obj == null ) {
308
            return false;
309
        }
310
        Point other;
311
        try {
312
            other = (Point) obj;
313
        } catch(ClassCastException e) {
314
            return false;
315
        }
316
        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
    @Override
334
    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
    @Override
340
    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
    @Override
346
    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
}