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 / Point2D.java @ 42441

History | View | Annotate | Download (6.28 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.aggregate.MultiPoint2D;
35
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX;
36
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator;
37
import org.gvsig.fmap.geom.jts.primitive.curve.circumference.Circumference2D;
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.type.GeometryType;
43

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

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

    
55
    /**
56
     *
57
     */
58
    public Point2D(Coordinate coordinates) {
59
        super(Geometry.SUBTYPES.GEOM2D, coordinates);
60

    
61
    }
62

    
63
    /**
64
     *
65
     */
66
    public Point2D() {
67
        this(new Coordinate(0, 0));
68
    }
69

    
70
    /**
71
    *
72
    */
73
    public Point2D(double x, double y) {
74
        this(new Coordinate(x, y));
75
    }
76

    
77
    /*
78
     * (non-Javadoc)
79
     *
80
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
81
     */
82
    public Geometry cloneGeometry() {
83
        return new Point2D((Coordinate) this.coordinate.clone());
84
    }
85

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

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

    
108
    /*
109
     * (non-Javadoc)
110
     *
111
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#is3D()
112
     */
113
    public boolean is3D() {
114
        return false;
115
    }
116

    
117
    /* (non-Javadoc)
118
     * @see org.gvsig.fmap.geom.jts.primitive.point.PointJTS#setJTSCoordinate(com.vividsolutions.jts.geom.Coordinate)
119
     */
120
    public void setJTSCoordinate(Coordinate coordinate) {
121
        this.coordinate = coordinate;
122
    }
123

    
124
    /*
125
     * (non-Javadoc)
126
     *
127
     * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
128
     */
129
    public GeneralPathX getGeneralPath() {
130
        return new DefaultGeneralPathX(new PointIterator(null),false,0);
131
    }
132

    
133
    /*
134
     * (non-Javadoc)
135
     *
136
     * @see
137
     * org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
138
     * )
139
     */
140
    public PathIterator getPathIterator(AffineTransform at) {
141
        PointIterator pi = new PointIterator(at);
142
        return pi;
143
    }
144

    
145

    
146
    public class PointIterator extends GeneralPathXIterator {
147
        /** Transform applied on the coordinates during iteration */
148
        private AffineTransform at;
149

    
150
        /** True when the point has been read once */
151
        private boolean done;
152

    
153
        /**
154
         * Creates a new PointIterator object.
155
         *
156
         * @param p The polygon
157
         * @param at The affine transform applied to coordinates during iteration
158
         */
159
        public PointIterator(AffineTransform at) {
160
            super(new GeneralPathX());
161
            if (at == null) {
162
                at = new AffineTransform();
163
            }
164

    
165
            this.at = at;
166
            done = false;
167
        }
168

    
169
        /**
170
         * Return the winding rule for determining the interior of the path.
171
         *
172
         * @return <code>WIND_EVEN_ODD</code> by default.
173
         */
174
        public int getWindingRule() {
175
            return PathIterator.WIND_EVEN_ODD;
176
        }
177

    
178
        /**
179
         * @see java.awt.geom.PathIterator#next()
180
         */
181
        public void next() {
182
            done = true;
183
        }
184

    
185
        /**
186
         * @see java.awt.geom.PathIterator#isDone()
187
         */
188
        public boolean isDone() {
189
            return done;
190
        }
191

    
192
        /**
193
         * @see java.awt.geom.PathIterator#currentSegment(double[])
194
         */
195
        public int currentSegment(double[] coords) {
196
            coords[0] = getX();
197
            coords[1] = getY();
198
            at.transform(coords, 0, coords, 0, 1);
199

    
200
            return PathIterator.SEG_MOVETO;
201
        }
202

    
203
        /* (non-Javadoc)
204
         * @see java.awt.geom.PathIterator#currentSegment(float[])
205
         */
206
        public int currentSegment(float[] coords) {
207
            coords[0] = (float) getX();
208
            coords[1] = (float) getY();
209
            at.transform(coords, 0, coords, 0, 1);
210

    
211
            return PathIterator.SEG_MOVETO;
212
        }
213
    }
214

    
215
    /* (non-Javadoc)
216
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
217
     */
218
    public MultiPoint toPoints() throws GeometryException {
219
        MultiPoint multiPoint = new MultiPoint2D();
220
        multiPoint.addPoint(this);
221
        return multiPoint;
222
    }
223

    
224
    /* (non-Javadoc)
225
     * @see org.gvsig.fmap.geom.Geometry#offset(double)
226
     */
227
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
228
        return new Circumference2D((Point)this.cloneGeometry(), distance);
229
    }
230

    
231
}