Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_geometries / src / org / gvsig / fmap / geom / aggregate / MultiPoint2D.java @ 21425

History | View | Annotate | Download (6.73 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41
package org.gvsig.fmap.geom.aggregate;
42

    
43
import java.awt.Rectangle;
44
import java.awt.geom.AffineTransform;
45
import java.awt.geom.Rectangle2D;
46

    
47
import org.cresques.cts.IProjection;
48
import org.gvsig.fmap.geom.Geometry;
49
import org.gvsig.fmap.geom.GeometryManager;
50
import org.gvsig.fmap.geom.handler.AbstractHandler;
51
import org.gvsig.fmap.geom.primitive.DefaultEnvelope;
52
import org.gvsig.fmap.geom.primitive.Envelope;
53
import org.gvsig.fmap.geom.primitive.FShape;
54
import org.gvsig.fmap.geom.primitive.Point2D;
55
import org.gvsig.fmap.geom.type.GeometryType;
56

    
57
/**
58
 * Multipunto 2D.
59
 *
60
 * @author Vicente Caballero Navarro
61
 */
62
public class MultiPoint2D extends BaseMultiPrimitive implements MultiPoint {
63

    
64
        private static final long serialVersionUID = 1L;
65

    
66
        private static GeometryType geomType = GeometryManager.getInstance()
67
        .registerGeometryType(MultiPoint2D.class);
68
        public static int CODE = geomType.getType();
69

    
70
        public MultiPoint2D(IProjection projection, Point2D[] points) {
71
                this(null, projection, points);
72
        }
73

    
74
        public MultiPoint2D(Point2D[] points) {
75
                this(null, null, points);
76
        }
77

    
78
        public MultiPoint2D(IProjection projection) {
79
                this(null, projection, null);
80
        }
81

    
82
        public MultiPoint2D(String id, IProjection projection, Point2D[] points) {
83
                super(id, projection, points);
84
        }
85

    
86
        public MultiPoint2D(String id, IProjection projection) {
87
                this(id, projection, null);
88
        }
89

    
90
        public MultiPoint2D(double[] x, double[] y) {
91
                this(null, null, x, y);
92
        }
93

    
94
        /**
95
         * Crea un nuevo MultiPoint2D.
96
         *
97
         * @param x
98
         *            DOCUMENT ME!
99
         * @param y
100
         *            DOCUMENT ME!
101
         */
102
        public MultiPoint2D(String id, IProjection projection, double[] x,
103
                        double[] y) {
104
                super(id, projection);
105
                geometries = new Point2D[x.length];
106
                for (int i = 0; i < x.length; i++) {
107
                        geometries[i] = new Point2D(id, projection, x[i], y[i]);
108
                }
109
        }
110

    
111
        /*
112
         * (non-Javadoc)
113
         *
114
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#cloneGeometry()
115
         */
116
        public Geometry cloneGeometry() {
117
                Point2D[] aux = new Point2D[getNumgeometries()];
118
                for (int i = 0; i < getNumgeometries(); i++) {
119
                        aux[i] = (Point2D) geometries[i].cloneGeometry().getInternalShape();
120
                }
121
                return new MultiPoint2D(id, projection, aux);
122
        }
123

    
124
        /*
125
         * (non-Javadoc)
126
         *
127
         * @see com.iver.cit.gvsig.fmap.core.FGeometryCollection#getBounds()
128
         */
129
        public Rectangle getBounds() {
130
                Rectangle r = null;
131
                if (getNumgeometries() > 0) {
132
                        r = geometries[0].getBounds();
133
                }
134
                for (int i = 1; i < getNumgeometries(); i++) {
135
                        java.awt.geom.Point2D p = geometries[i]
136
                                        .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
137
                        r.add(p.getX(), p.getY());
138
                }
139
                return r;
140
        }
141

    
142
        /*
143
         * (non-Javadoc)
144
         *
145
         * @see com.iver.cit.gvsig.fmap.core.IGeometry#getBounds2D()
146
         */
147
        public Rectangle2D getBounds2D() {
148
                Rectangle2D r = null;
149
                if (getNumgeometries() > 0) {
150
                        java.awt.geom.Point2D p = geometries[0]
151
                                        .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
152

    
153
                        r = new Rectangle2D.Double(p.getX(), p.getY(), 0.001, 0.001);
154
                }
155
                for (int i = 1; i < getNumgeometries(); i++) {
156
                        java.awt.geom.Point2D p = geometries[i]
157
                                        .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
158
                        r.add(p.getX(), p.getY());
159
                }
160
                return r;
161
        }
162

    
163
        /*
164
         * (non-Javadoc)
165
         *
166
         * @see com.iver.cit.gvsig.fmap.core.FShape#getShapeType()
167
         */
168
        public int getShapeType() {
169
                return FShape.MULTIPOINT;
170
        }
171

    
172
        /*
173
         * (non-Javadoc)
174
         *
175
         * @see com.iver.cit.gvsig.fmap.core.FShape#cloneFShape()
176
         */
177
        public FShape cloneFShape() {
178
                Point2D[] aux = new Point2D[getNumgeometries()];
179
                for (int i = 0; i < getNumgeometries(); i++) {
180
                        aux[i] = (Point2D) geometries[i].cloneGeometry().getInternalShape();
181
                }
182
                return (FShape) new MultiPoint2D(id, projection, aux);
183
        }
184

    
185
        /**
186
         * @return the numbre of points
187
         * @deprecated use getPrimitivesNumber
188
         */
189
        public int getNumgeometries() {
190
                return getPrimitivesNumber();
191
        }
192

    
193
        /**
194
         * @return the numbre of points
195
         * @deprecated use getPrimitivesNumber
196
         */
197
        public int getNumPoints() {
198
                return getPrimitivesNumber();
199
        }
200

    
201
        public Point2D getPoint(int i) {
202
                return (Point2D) geometries[i].getInternalShape();
203
        }
204

    
205
        /**
206
         * DOCUMENT ME!
207
         *
208
         * @author Vicente Caballero Navarro
209
         */
210
        class PointHandler extends AbstractHandler {
211
                /**
212
                 * Crea un nuevo PointHandler.
213
                 *
214
                 * @param x
215
                 *            DOCUMENT ME!
216
                 * @param y
217
                 *            DOCUMENT ME!
218
                 */
219
                public PointHandler(int i, Point2D p) {
220
                        point = new java.awt.geom.Point2D.Double(p.getX(), p.getY());
221
                        index = i;
222
                }
223

    
224
                /**
225
                 * DOCUMENT ME!
226
                 *
227
                 * @param x
228
                 *            DOCUMENT ME!
229
                 * @param y
230
                 *            DOCUMENT ME!
231
                 *
232
                 * @return DOCUMENT ME!
233
                 */
234
                public void move(double x, double y) {
235
                        java.awt.geom.Point2D p = geometries[index]
236
                                        .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
237

    
238
                        point.setLocation(p.getX() + x, p.getY() + y);
239
                }
240

    
241
                /**
242
                 * @see org.gvsig.fmap.geom.handler.Handler#set(double, double)
243
                 */
244
                public void set(double x, double y) {
245
                        point.setLocation(x, y);
246
                }
247

    
248
        }
249

    
250
        public void transform(AffineTransform at) {
251
                for (int i = 0; i < getNumgeometries(); i++) {
252
                        geometries[i].transform(at);
253
                }
254

    
255
        }
256

    
257
        public Envelope getEnvelope() {
258
                Envelope r = null;
259
                if (getNumgeometries() > 0) {
260
                        java.awt.geom.Point2D p = geometries[0]
261
                                        .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
262

    
263
                        r = new DefaultEnvelope(2,new double[]{p.getX(), p.getY()},new double[]{ p.getX()+0.001, p.getY()+0.001});
264
                }
265
                for (int i = 1; i < getNumgeometries(); i++) {
266
                        java.awt.geom.Point2D p = geometries[i]
267
                                        .getHandlers(Geometry.SELECTHANDLER)[0].getPoint();
268
                        r.add(new DefaultEnvelope(2,new double[]{p.getX(), p.getY()},new double[]{ p.getX()+0.001, p.getY()+0.001}));
269
                }
270
                return r;
271
        }
272

    
273
}