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

History | View | Annotate | Download (6.32 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.primitive.GeneralPathX;
40
import org.gvsig.fmap.geom.type.GeometryType;
41

    
42
/**
43
 * @author fdiaz
44
 *
45
 */
46
public class Point3DM extends AbstractPoint {
47

    
48
    /**
49
     *
50
     */
51
    private static final long serialVersionUID = 5749444180040735731L;
52

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

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

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

    
74
    public double getZ() {
75
        return this.coordinate.z;
76
    }
77

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

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

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

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

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

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

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

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

    
155
    public class PointIterator extends GeneralPathXIterator {
156

    
157
        /** Transform applied on the coordinates during iteration */
158
        private AffineTransform at;
159

    
160
        /** True when the point has been read once */
161
        private boolean done;
162

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

    
178
            this.at = at;
179
            done = false;
180
        }
181

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

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

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

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

    
214
            return PathIterator.SEG_MOVETO;
215
        }
216

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

    
227
            at.transform(coords, 0, coords, 0, 1);
228

    
229
            return PathIterator.SEG_MOVETO;
230
        }
231
    }
232

    
233

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