Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / shp / write / SHPMultiPoint.java @ 1137

History | View | Annotate | Download (5.89 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 com.iver.cit.gvsig.fmap.drivers.shp.write;
42

    
43
import com.iver.cit.gvsig.fmap.core.FMultiPoint2D;
44
import com.iver.cit.gvsig.fmap.core.FPoint2D;
45
import com.iver.cit.gvsig.fmap.core.GeneralPathXIterator;
46
import com.iver.cit.gvsig.fmap.core.IGeometry;
47
import com.iver.cit.gvsig.fmap.core.v02.FConstant;
48

    
49
import java.awt.geom.Rectangle2D;
50

    
51
import java.nio.ByteBuffer;
52
import java.nio.MappedByteBuffer;
53

    
54

    
55
/**
56
 * DOCUMENT ME!
57
 *
58
 * @author Vicente Caballero Navarro
59
 */
60
public class SHPMultiPoint implements SHPShape {
61
        private int m_type;
62
        private int numpoints;
63
        private FPoint2D[] points;
64

    
65
        /**
66
         * Crea un nuevo SHPMultiPoint.
67
         */
68
        public SHPMultiPoint() {
69
                m_type = FConstant.SHAPE_TYPE_MULTIPOINT;
70
        }
71

    
72
        /**
73
         * Crea un nuevo SHPMultiPoint.
74
         *
75
         * @param type DOCUMENT ME!
76
         *
77
         * @throws ShapefileException DOCUMENT ME!
78
         */
79
        public SHPMultiPoint(int type) throws ShapefileException {
80
                if ((type != FConstant.SHAPE_TYPE_MULTIPOINT) &&
81
                                (type != FConstant.SHAPE_TYPE_MULTIPOINTM) &&
82
                                (type != FConstant.SHAPE_TYPE_MULTIPOINTZ)) {
83
                        throw new ShapefileException("No es de tipo 8, 18, o 28");
84
                }
85

    
86
                m_type = type;
87
        }
88

    
89
        /**
90
         * DOCUMENT ME!
91
         *
92
         * @return DOCUMENT ME!
93
         */
94
        public int getShapeType() {
95
                return m_type;
96
        }
97

    
98
        /**
99
         * DOCUMENT ME!
100
         *
101
         * @param buffer DOCUMENT ME!
102
         * @param type DOCUMENT ME!
103
         *
104
         * @return DOCUMENT ME!
105
         */
106
        public IGeometry read(MappedByteBuffer buffer, int type) {
107
                double minX = buffer.getDouble();
108
                double minY = buffer.getDouble();
109
                double maxX = buffer.getDouble();
110
                double maxY = buffer.getDouble();
111
                Rectangle2D rec = new Rectangle2D.Double(minX, minY, maxX - minX,
112
                                maxY - maxY);
113
                int numpoints = buffer.getInt();
114
                FPoint2D[] p = new FPoint2D[numpoints];
115

    
116
                for (int t = 0; t < numpoints; t++) {
117
                        double x = buffer.getDouble();
118
                        double y = buffer.getDouble();
119
                        p[t] = new FPoint2D(x, y);
120
                }
121

    
122
                /*   if (m_type == FConstant.SHAPE_TYPE_MULTIPOINTZ) {
123
                   buffer.position(buffer.position() + (2 * 8));
124
                   for (int t = 0; t < numpoints; t++) {
125
                       p[t].z = buffer.getDouble(); //z
126
                   }
127
                   }
128
                 */
129
                return (IGeometry) new FMultiPoint2D(p);
130
        }
131

    
132
        /**
133
         * DOCUMENT ME!
134
         *
135
         * @param buffer DOCUMENT ME!
136
         * @param geometry DOCUMENT ME!
137
         */
138
        public void write(ByteBuffer buffer, IGeometry geometry) {
139
                // FMultiPoint2D mp = (FMultiPoint2D) geometry.getShape();
140
                int p = buffer.position();
141

    
142
                Rectangle2D box = geometry.getBounds2D();
143
                buffer.putDouble(box.getMinX());
144
                buffer.putDouble(box.getMinY());
145
                buffer.putDouble(box.getMaxX());
146
                buffer.putDouble(box.getMaxY());
147
                ///obtainsPoints(geometry.getGeneralPathXIterator());
148
                buffer.putInt(numpoints);
149

    
150
                for (int t = 0, tt = numpoints; t < tt; t++) {
151
                        FPoint2D point = points[t];
152
                        buffer.putDouble(point.getX());
153
                        buffer.putDouble(point.getY());
154
                }
155

    
156
                /*  if (m_type == FConstant.SHAPE_TYPE_MULTIPOINTZ) {
157
                   double[] zExtreame = JTSUtilities.zMinMax(mp.getPoints());
158
                   if (Double.isNaN(zExtreame[0])) {
159
                       buffer.putDouble(0.0);
160
                       buffer.putDouble(0.0);
161
                   } else {
162
                       buffer.putDouble(zExtreame[0]);
163
                       buffer.putDouble(zExtreame[1]);
164
                   }
165
                   for (int t = 0; t < mp.getNum(); t++) {
166
                       FPoint point = mp.getPoint(t);
167
                       double z = point.z;
168
                       if (Double.isNaN(z)) {
169
                           buffer.putDouble(0.0);
170
                       } else {
171
                           buffer.putDouble(z);
172
                       }
173
                   }
174
                   }
175
                   if ((m_type == FConstant.SHAPE_TYPE_MULTIPOINTM) ||
176
                           (m_type == FConstant.SHAPE_TYPE_MULTIPOINTZ)) {
177
                       buffer.putDouble(-10E40);
178
                       buffer.putDouble(-10E40);
179
                       for (int t = 0; t < mp.getNum(); t++) {
180
                           buffer.putDouble(-10E40);
181
                       }
182
                   }
183
                 */
184
        }
185

    
186
        /**
187
         * @see com.iver.cit.gvsig.fmap.shp.SHPShape#getLength(com.iver.cit.gvsig.core.BasicShape.FGeometry)
188
         */
189
        public int getLength(IGeometry fgeometry) {
190
                //FMultiPoint2D mp = (FMultiPoint2D) fgeometry.getShape();
191
                ///obtainsPoints(fgeometry.getGeneralPathXIterator());
192

    
193
                int length;
194

    
195
                if (m_type == FConstant.SHAPE_TYPE_MULTIPOINT) {
196
                        // two doubles per coord (16 * numgeoms) + 40 for header
197
                        length = (numpoints * 16) + 40;
198
                } else if (m_type == FConstant.SHAPE_TYPE_MULTIPOINTM) {
199
                        // add the additional MMin, MMax for 16, then 8 per measure
200
                        length = (numpoints * 16) + 40 + 16 + (8 * numpoints);
201
                } else if (m_type == FConstant.SHAPE_TYPE_MULTIPOINTZ) {
202
                        // add the additional ZMin,ZMax, plus 8 per Z 
203
                        length = (numpoints * 16) + 40 + 16 + (8 * numpoints) + 16 +
204
                                (8 * numpoints);
205
                } else {
206
                        throw new IllegalStateException("Expected ShapeType of Arc, got " +
207
                                m_type);
208
                }
209

    
210
                return length;
211
        }
212

    
213
        /**
214
         * @see com.iver.cit.gvsig.fmap.drivers.shp.write.SHPShape#obtainsPoints(com.iver.cit.gvsig.fmap.core.GeneralPathXIterator)
215
         */
216
        public void obtainsPoints(GeneralPathXIterator iter) {
217
        }
218
}