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 / Point2DM.java @ 42271

History | View | Annotate | Download (6.25 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.MultiPoint2DM;
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 Point2DM extends AbstractPoint {
47

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

    
53
    /**
54
   *
55
   */
56
    public Point2DM(Coordinate coordinates) {
57
        super(Geometry.SUBTYPES.GEOM2DM, coordinates);
58
    }
59

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

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

    
74
    public double getM() {
75
        return ((MCoordinate)this.coordinate).m;
76
    }
77

    
78
    /*
79
     * (non-Javadoc)
80
     *
81
     * @see org.gvsig.fmap.geom.Geometry#getDimension()
82
     */
83
    public int getDimension() {
84
        return 3;
85
    }
86

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

    
101
    /*
102
     * (non-Javadoc)
103
     *
104
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
105
     */
106
    public Geometry cloneGeometry() {
107
        return new Point2DM((MCoordinate) this.coordinate.clone());
108
    }
109

    
110
    /*
111
     * (non-Javadoc)
112
     *
113
     * @see org.gvsig.fmap.geom.primitive.Point#getCoordinateAt(int)
114
     */
115
    public double getCoordinateAt(int dimension) {
116
        if (dimension == 2) {
117
            return this.getM();
118
        }
119
        return super.getCoordinateAt(dimension);
120
    }
121

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

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

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

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

    
159
    public class PointIterator extends GeneralPathXIterator {
160
        /** Transform applied on the coordinates during iteration */
161
        private AffineTransform at;
162

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

    
166
        /**
167
         * Creates a new PointIterator object.
168
         *
169
         * @param p The polygon
170
         * @param at The affine transform applied to coordinates during 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
            at.transform(coords, 0, coords, 0, 1);
212

    
213
            return PathIterator.SEG_MOVETO;
214
        }
215

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

    
224
            return PathIterator.SEG_MOVETO;
225
        }
226
    }
227

    
228
    /* (non-Javadoc)
229
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
230
     */
231
    public MultiPoint toPoints() throws GeometryException {
232
        MultiPoint multiPoint = new MultiPoint2DM();
233
        multiPoint.addPoint(this);
234
        return multiPoint;
235
    }
236

    
237
}