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

History | View | Annotate | Download (7.14 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.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.GeometryException;
32
import org.gvsig.fmap.geom.GeometryLocator;
33
import org.gvsig.fmap.geom.aggregate.MultiPoint;
34
import org.gvsig.fmap.geom.jts.MCoordinate;
35
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3DM;
36
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX;
37
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator;
38
import org.gvsig.fmap.geom.jts.util.JTSUtils;
39
import org.gvsig.fmap.geom.operation.GeometryOperationException;
40
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
41
import org.gvsig.fmap.geom.primitive.GeneralPathX;
42
import org.gvsig.fmap.geom.type.GeometryType;
43

    
44
/**
45
 * @author fdiaz
46
 *
47
 */
48
public class Point3DM extends AbstractPoint {
49

    
50
    /**
51
     *
52
     */
53
    private static final long serialVersionUID = 5749444180040735731L;
54

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

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

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

    
76
    public double getZ() {
77
        return this.coordinate.z;
78
    }
79

    
80
    public double getM() {
81
        return ((org.hibernate.spatial.jts.mgeom.MCoordinate) this.coordinate).m;
82
    }
83

    
84
    /*
85
     * (non-Javadoc)
86
     *
87
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
88
     */
89
    public int getDimension() {
90
        return 4;
91
    }
92

    
93
    /*
94
     * (non-Javadoc)
95
     *
96
     * @see org.gvsig.fmap.geom.Geometry#getGeometryType()
97
     */
98
    public GeometryType getGeometryType() {
99
        try {
100
            return GeometryLocator.getGeometryManager()
101
                .getGeometryType(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3DM);
102
        } catch (Exception e) {
103
            return null;
104
        }
105
    }
106

    
107
    /*
108
     * (non-Javadoc)
109
     *
110
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
111
     */
112
    public Geometry cloneGeometry() {
113
        return new Point3DM(MCoordinate.convertCoordinate((Coordinate) coordinate.clone()));
114
    }
115

    
116
    /*
117
     * (non-Javadoc)
118
     *
119
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
120
     */
121
    public boolean is3D() {
122
        return true;
123
    }
124

    
125
    /*
126
     * (non-Javadoc)
127
     *
128
     * @see
129
     * org.gvsig.fmap.geom.jts.primitive.point.PointJTS#setJTSCoordinate(com
130
     * .vividsolutions.jts.geom.Coordinate)
131
     */
132
    public void setJTSCoordinate(Coordinate coordinate) {
133
        this.coordinate = coordinate;
134
    }
135

    
136
    /*
137
     * (non-Javadoc)
138
     *
139
     * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
140
     */
141
    public GeneralPathX getGeneralPath() {
142
        return new DefaultGeneralPathX(new PointIterator(null), true, getZ());
143
    }
144

    
145
    /*
146
     * (non-Javadoc)
147
     *
148
     * @see
149
     * org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
150
     * )
151
     */
152
    public PathIterator getPathIterator(AffineTransform at) {
153
        PointIterator pi = new PointIterator(at);
154
        return pi;
155
    }
156

    
157
    public class PointIterator extends GeneralPathXIterator {
158

    
159
        /** Transform applied on the coordinates during iteration */
160
        private AffineTransform at;
161

    
162
        /** True when the point has been read once */
163
        private boolean done;
164

    
165
        /**
166
         * Creates a new PointIterator object.
167
         *
168
         * @param p
169
         *            The polygon
170
         * @param at
171
         *            The affine transform applied to coordinates during
172
         *            iteration
173
         */
174
        public PointIterator(AffineTransform at) {
175
            super(new GeneralPathX());
176
            if (at == null) {
177
                at = new AffineTransform();
178
            }
179

    
180
            this.at = at;
181
            done = false;
182
        }
183

    
184
        /**
185
         * Return the winding rule for determining the interior of the path.
186
         *
187
         * @return <code>WIND_EVEN_ODD</code> by default.
188
         */
189
        public int getWindingRule() {
190
            return PathIterator.WIND_EVEN_ODD;
191
        }
192

    
193
        /**
194
         * @see java.awt.geom.PathIterator#next()
195
         */
196
        public void next() {
197
            done = true;
198
        }
199

    
200
        /**
201
         * @see java.awt.geom.PathIterator#isDone()
202
         */
203
        public boolean isDone() {
204
            return done;
205
        }
206

    
207
        /**
208
         * @see java.awt.geom.PathIterator#currentSegment(double[])
209
         */
210
        public int currentSegment(double[] coords) {
211
            coords[0] = getX();
212
            coords[1] = getY();
213
            coords[2] = getZ();
214
            at.transform(coords, 0, coords, 0, 1);
215

    
216
            return PathIterator.SEG_MOVETO;
217
        }
218

    
219
        /*
220
         * (non-Javadoc)
221
         *
222
         * @see java.awt.geom.PathIterator#currentSegment(float[])
223
         */
224
        public int currentSegment(float[] coords) {
225
            coords[0] = (float) getX();
226
            coords[1] = (float) getY();
227
            coords[2] = (float) getZ();
228

    
229
            at.transform(coords, 0, coords, 0, 1);
230

    
231
            return PathIterator.SEG_MOVETO;
232
        }
233
    }
234

    
235

    
236
    /* (non-Javadoc)
237
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
238
     */
239
    public MultiPoint toPoints() throws GeometryException {
240
        MultiPoint multiPoint = new MultiPoint3DM();
241
        multiPoint.addPoint(this);
242
        return multiPoint;
243
    }
244

    
245
    /* (non-Javadoc)
246
     * @see org.gvsig.fmap.geom.Geometry#offset(double)
247
     */
248
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
249
        return JTSUtils.createGeometry(getJTS().buffer(distance));
250
    }
251

    
252
    public String toString() {
253
        StringBuilder builder = new StringBuilder();
254
        builder.append("POINT ZM (");
255
        for( int i=0; i<this.getDimension()-1; i++) {
256
            builder.append(this.getCoordinateAt(i));
257
            builder.append(" ");
258
        }
259
        builder.append(this.getCoordinateAt(this.getDimension()-1));
260
        builder.append(")");
261
        return builder.toString();
262
    }
263
}