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

History | View | Annotate | Download (6.72 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.aggregate;
24

    
25
import java.awt.Shape;
26
import java.awt.geom.AffineTransform;
27
import java.awt.geom.PathIterator;
28
import java.util.Collections;
29
import java.util.Iterator;
30

    
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.aggregate.MultiPoint;
33
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX;
34
import org.gvsig.fmap.geom.jts.gputils.GeneralPathXIterator;
35
import org.gvsig.fmap.geom.jts.primitive.point.PointJTS;
36
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
37
import org.gvsig.fmap.geom.jts.util.JTSUtils;
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.primitive.Primitive;
43

    
44

    
45
/**
46
 * @author fdiaz
47
 *
48
 */
49
public abstract class AbstractMultiPoint extends AbstractMultiPrimitive implements MultiPoint {
50

    
51
    /**
52
     *
53
     */
54
    private static final long serialVersionUID = 7056816718895043774L;
55

    
56
    /**
57
     * @param type
58
     * @param subtype
59
     */
60
    public AbstractMultiPoint(int subtype) {
61
        super(Geometry.TYPES.MULTIPOINT, subtype);
62
    }
63

    
64
    /* (non-Javadoc)
65
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
66
     */
67
    public com.vividsolutions.jts.geom.Geometry getJTS() {
68
        ArrayListCoordinateSequence coordinateSequence = new ArrayListCoordinateSequence();
69
        for (Iterator<Primitive> iterator = primitives.iterator(); iterator.hasNext();) {
70
            PointJTS point = (PointJTS) iterator.next();
71
            coordinateSequence.add(point.getJTSCoordinate());
72
        }
73
        return JTSUtils.createJTSMultiPoint(coordinateSequence);
74
    }
75

    
76
    /* (non-Javadoc)
77
     * @see org.gvsig.fmap.geom.aggregate.MultiPoint#addPoint(org.gvsig.fmap.geom.primitive.Point)
78
     */
79
    public void addPoint(Point point) {
80
        primitives.add(point);
81
    }
82

    
83
    /* (non-Javadoc)
84
     * @see org.gvsig.fmap.geom.aggregate.MultiPoint#getPointAt(int)
85
     */
86
    public Point getPointAt(int index) {
87
        return (Point)primitives.get(index);
88
    }
89

    
90
    /*
91
     * (non-Javadoc)
92
     *
93
     * @see org.gvsig.fmap.geom.Geometry#getShape(java.awt.geom.AffineTransform)
94
     */
95
    public Shape getShape(AffineTransform affineTransform) {
96
        return new DefaultGeneralPathX(getPathIterator(affineTransform),false,0);
97
    }
98

    
99
    /*
100
     * (non-Javadoc)
101
     *
102
     * @see org.gvsig.fmap.geom.Geometry#getShape()
103
     */
104
    public Shape getShape() {
105
        return new DefaultGeneralPathX(getPathIterator(null),false,0);
106
    }
107

    
108
    /*
109
     * (non-Javadoc)
110
     *
111
     * @see
112
     * org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
113
     * )
114
     */
115
    public PathIterator getPathIterator(AffineTransform at) {
116
        PointIterator pi = new PointIterator(at);
117
        return pi;
118
    }
119

    
120
    /*
121
     * (non-Javadoc)
122
     *
123
     * @see
124
     * org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
125
     * , double)
126
     */
127
    public PathIterator getPathIterator(AffineTransform at, double flatness) {
128
        return getPathIterator(at);
129
    }
130

    
131
    protected class PointIterator extends GeneralPathXIterator {
132

    
133
        /** Transform applied on the coordinates during iteration */
134
        private AffineTransform at;
135

    
136
        /** True when the point has been read once */
137
        private boolean done;
138
        private int index = 0;
139

    
140
        /**
141
         * Creates a new PointIterator object.
142
         *
143
         * @param p
144
         *            The polygon
145
         * @param at
146
         *            The affine transform applied to coordinates during
147
         *            iteration
148
         */
149
        public PointIterator(AffineTransform at) {
150
            super(new GeneralPathX());
151
            if (at == null) {
152
                at = new AffineTransform();
153
            }
154

    
155
            this.at = at;
156
            done = false;
157
        }
158

    
159
        /**
160
         * Return the winding rule for determining the interior of the path.
161
         *
162
         * @return <code>WIND_EVEN_ODD</code> by default.
163
         */
164
        public int getWindingRule() {
165
            return PathIterator.WIND_EVEN_ODD;
166
        }
167

    
168
        /**
169
         * @see java.awt.geom.PathIterator#next()
170
         */
171
        public void next() {
172
            done = (primitives.size() == index++);
173
        }
174

    
175
        /**
176
         * @see java.awt.geom.PathIterator#isDone()
177
         */
178
        public boolean isDone() {
179
            return done;
180
        }
181

    
182
        /**
183
         * @see java.awt.geom.PathIterator#currentSegment(double[])
184
         */
185
        public int currentSegment(double[] coords) {
186
            Point point = (Point) primitives.get(index);
187
            coords[0] = point.getX();
188
            coords[1] = point.getY();
189
            at.transform(coords, 0, coords, 0, 1);
190
            return PathIterator.SEG_MOVETO;
191
        }
192

    
193
        /*
194
         * (non-Javadoc)
195
         *
196
         * @see java.awt.geom.PathIterator#currentSegment(float[])
197
         */
198
        public int currentSegment(float[] coords) {
199
            Point point = (Point) primitives.get(index);
200
            coords[0] = (float)point.getX();
201
            coords[1] = (float)point.getY();
202
            at.transform(coords, 0, coords, 0, 1);
203
            return PathIterator.SEG_MOVETO;
204
        }
205
    }
206

    
207
    /* (non-Javadoc)
208
     * @see org.gvsig.fmap.geom.jts.GeometryJTS#flip()
209
     */
210
    public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException {
211
        Collections.reverse(primitives);
212
    }
213

    
214

    
215
    /* (non-Javadoc)
216
     * @see org.gvsig.fmap.geom.Geometry#transform(java.awt.geom.AffineTransform)
217
     */
218
    public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException {
219
        return JTSUtils.createGeometry(getJTS().buffer(distance));
220
    }
221
}