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 @ 45673

History | View | Annotate | Download (8.76 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
import org.cresques.cts.IProjection;
30

    
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.GeometryException;
33
import org.gvsig.fmap.geom.GeometryLocator;
34
import org.gvsig.fmap.geom.aggregate.MultiPoint;
35
import org.gvsig.fmap.geom.jts.MCoordinate;
36
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3DM;
37
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX;
38
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator;
39
import org.gvsig.fmap.geom.jts.util.JTSUtils;
40
import org.gvsig.fmap.geom.operation.GeometryOperationException;
41
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
42
import org.gvsig.fmap.geom.primitive.GeneralPathX;
43
import org.gvsig.fmap.geom.primitive.Point;
44
import org.gvsig.fmap.geom.type.GeometryType;
45

    
46
/**
47
 * @author fdiaz
48
 *
49
 */
50
public class Point3DM extends AbstractPoint {
51

    
52
    /**
53
     *
54
     */
55
    private static final long serialVersionUID = 5749444180040735731L;
56

    
57
    /**
58
   *
59
   */
60
    public Point3DM(IProjection proj, Coordinate coordinates) {
61
        super(Geometry.SUBTYPES.GEOM3DM, MCoordinate.convertCoordinate(coordinates));
62
    }
63

    
64
    /**
65
   *
66
   */
67
    public Point3DM() {
68
        this(null, JTSUtils.createMCoordinate(0, 0, 0, 0));
69
    }
70

    
71
    /**
72
  *
73
  */
74
    public Point3DM(double x, double y, double z, double m) {
75
        this(null, JTSUtils.createMCoordinate(x, y, z, m));
76
    }
77

    
78
    public Point3DM(IProjection proj, double x, double y, double z, double m) {
79
        this(proj, JTSUtils.createMCoordinate(x, y, z, m));
80
    }
81

    
82
    public double getZ() {
83
        return this.coordinate.z;
84
    }
85

    
86
    public double getM() {
87
        return ((org.hibernate.spatial.jts.mgeom.MCoordinate) this.coordinate).m;
88
    }
89

    
90
    /*
91
     * (non-Javadoc)
92
     *
93
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
94
     */
95
    public int getDimension() {
96
        return 4;
97
    }
98

    
99
    /*
100
     * (non-Javadoc)
101
     *
102
     * @see org.gvsig.fmap.geom.Geometry#getGeometryType()
103
     */
104
    public GeometryType getGeometryType() {
105
        try {
106
            return GeometryLocator.getGeometryManager()
107
                .getGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3DM);
108
        } catch (Exception e) {
109
            return null;
110
        }
111
    }
112

    
113
    /*
114
     * (non-Javadoc)
115
     *
116
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
117
     */
118
    public Point cloneGeometry() {
119
        return new Point3DM(this.getProjection(), MCoordinate.convertCoordinate((Coordinate) coordinate.clone()));
120
    }
121

    
122
    /*
123
     * (non-Javadoc)
124
     *
125
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
126
     */
127
    public boolean is3D() {
128
        return true;
129
    }
130

    
131
    /*
132
     * (non-Javadoc)
133
     *
134
     * @see
135
     * org.gvsig.fmap.geom.jts.primitive.point.PointJTS#setJTSCoordinate(com
136
     * .vividsolutions.jts.geom.Coordinate)
137
     */
138
    public void setJTSCoordinate(Coordinate coordinate) {
139
        this.coordinate = coordinate;
140
    }
141

    
142
    /*
143
     * (non-Javadoc)
144
     *
145
     * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
146
     */
147
    public GeneralPathX getGeneralPath() {
148
        return new DefaultGeneralPathX(new PointIterator(null), true, getZ());
149
    }
150

    
151
    /*
152
     * (non-Javadoc)
153
     *
154
     * @see
155
     * org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
156
     * )
157
     */
158
    public PathIterator getPathIterator(AffineTransform at) {
159
        PointIterator pi = new PointIterator(at);
160
        return pi;
161
    }
162

    
163
    public class PointIterator extends GeneralPathXIterator {
164

    
165
        /** Transform applied on the coordinates during iteration */
166
        private AffineTransform at;
167

    
168
        /** True when the point has been read once */
169
        private boolean done;
170

    
171
        /**
172
         * Creates a new PointIterator object.
173
         *
174
         * @param p
175
         *            The polygon
176
         * @param at
177
         *            The affine transform applied to coordinates during
178
         *            iteration
179
         */
180
        public PointIterator(AffineTransform at) {
181
            super(new GeneralPathX());
182
            if (at == null) {
183
                at = new AffineTransform();
184
            }
185

    
186
            this.at = at;
187
            done = false;
188
        }
189

    
190
        /**
191
         * Return the winding rule for determining the interior of the path.
192
         *
193
         * @return <code>WIND_EVEN_ODD</code> by default.
194
         */
195
        public int getWindingRule() {
196
            return PathIterator.WIND_EVEN_ODD;
197
        }
198

    
199
        /**
200
         * @see java.awt.geom.PathIterator#next()
201
         */
202
        public void next() {
203
            done = true;
204
        }
205

    
206
        /**
207
         * @see java.awt.geom.PathIterator#isDone()
208
         */
209
        public boolean isDone() {
210
            return done;
211
        }
212

    
213
        /**
214
         * @see java.awt.geom.PathIterator#currentSegment(double[])
215
         */
216
        public int currentSegment(double[] coords) {
217
            coords[0] = getX();
218
            coords[1] = getY();
219
            coords[2] = getZ();
220
            at.transform(coords, 0, coords, 0, 1);
221

    
222
            return PathIterator.SEG_MOVETO;
223
        }
224

    
225
        /*
226
         * (non-Javadoc)
227
         *
228
         * @see java.awt.geom.PathIterator#currentSegment(float[])
229
         */
230
        public int currentSegment(float[] coords) {
231
            coords[0] = (float) getX();
232
            coords[1] = (float) getY();
233
            coords[2] = (float) getZ();
234

    
235
            at.transform(coords, 0, coords, 0, 1);
236

    
237
            return PathIterator.SEG_MOVETO;
238
        }
239
    }
240

    
241

    
242
    /* (non-Javadoc)
243
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
244
     */
245
    public MultiPoint toPoints() throws GeometryException {
246
        MultiPoint multiPoint = new MultiPoint3DM();
247
        multiPoint.addPoint(this);
248
        return multiPoint;
249
    }
250

    
251
    /* (non-Javadoc)
252
     * @see org.gvsig.fmap.geom.Geometry#offset(double)
253
     */
254
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
255
        return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance));
256
    }
257

    
258
    public String toString() {
259
        StringBuilder builder = new StringBuilder();
260
        builder.append("POINT ZM (");
261
        for( int i=0; i<this.getDimension()-1; i++) {
262
            builder.append(this.getCoordinateAt(i));
263
            builder.append(" ");
264
        }
265
        builder.append(this.getCoordinateAt(this.getDimension()-1));
266
        builder.append(")");
267
        return builder.toString();
268
    }
269
    
270
    @Override
271
    public boolean equals(Object obj) {
272
        if( obj == null ) {
273
            return false;
274
        }
275
        Point other;
276
        try {
277
            other = (Point) obj;
278
        } catch(ClassCastException e) {
279
            return false;
280
        }
281
        if( this.getGeometryType().getSubType() != other.getGeometryType().getSubType() ) {
282
            return false;
283
        }
284
        if( this.coordinate.x != other.getX() ) {
285
            return false;
286
        }
287
        if( this.coordinate.y != other.getY() ) {
288
            return false;
289
        }
290
        if( this.coordinate.z != other.getCoordinateAt(2)) {
291
            return false;
292
        }
293
        if( ((MCoordinate)this.coordinate).m != other.getCoordinateAt(3)) {
294
            return false;
295
        }
296
        return true;
297
    }    
298
    public Point force3D() {
299
        Point3D p = new Point3D(this.getProjection(), this.coordinate.x, this.coordinate.y, this.coordinate.z);
300
        return p;
301
    }
302

    
303
    public Point force2DM() {
304
        Point2DM p = new Point2DM(this.getProjection(), this.coordinate.x, this.coordinate.y, ((MCoordinate)this.coordinate).m);
305
        return p;
306
    }
307

    
308
    public Point force3DM() {
309
        Point3DM p = new Point3DM(this.getProjection(), this.coordinate.x, this.coordinate.y, this.coordinate.z, ((MCoordinate)this.coordinate).m);
310
        return p;
311
    }
312

    
313
}