Statistics
| Revision:

svn-gvsig-desktop / branches / Mobile_Compatible_Hito_1 / libFMap_mobile_shp_driver / src-file / org / gvsig / data / datastores / vectorial / file / shp / utils / SHPPoint.java @ 21927

History | View | Annotate | Download (4.32 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.data.datastores.vectorial.file.shp.utils;
42

    
43
import java.awt.geom.PathIterator;
44
import java.nio.ByteBuffer;
45
import java.nio.MappedByteBuffer;
46

    
47
import org.gvsig.datasources.common.IByteBuffer;
48
import org.gvsig.fmap.geom.Geometry;
49
import org.gvsig.fmap.geom.primitive.AbstractPrimitive;
50
import org.gvsig.fmap.geom.primitive.Point2D;
51

    
52
/**
53
 * DOCUMENT ME!
54
 * 
55
 * @author Vicente Caballero Navarro
56
 */
57
public class SHPPoint implements SHPShape {
58
        private int m_type;
59

    
60
        private Point2D point;
61

    
62
        private double z;
63

    
64
        /**
65
         * Crea un nuevo SHPPoint.
66
         * 
67
         * @param type
68
         *            DOCUMENT ME!
69
         * 
70
         * @throws ShapefileException
71
         *             DOCUMENT ME!
72
         */
73
        public SHPPoint(int type) {
74
                if ((type != SHP.POINT2D) && (type != SHP.POINTM)
75
                                && (type != SHP.POINT3D)) { // 2d, 2d+m, 3d+m
76
                // throw new ShapefileException("No es un punto 1,11 ni 21");
77
                }
78

    
79
                m_type = type;
80
        }
81

    
82
        /**
83
         * Crea un nuevo SHPPoint.
84
         */
85
        public SHPPoint() {
86
                m_type = SHP.POINT2D; // 2d
87
        }
88

    
89
        /**
90
         * @see com.iver.cit.gvsig.fmap.shp.SHPShape#getShapeType()
91
         */
92
        public int getShapeType() {
93
                return m_type;
94
        }
95

    
96
        /**
97
         * @see com.iver.cit.gvsig.fmap.shp.SHPShape#read(MappedByteBuffer, int)
98
         */
99
        public Geometry read(MappedByteBuffer buffer, int type) {
100
                double x = buffer.getDouble();
101
                double y = buffer.getDouble();
102
                double z = Double.NaN;
103

    
104
                if (m_type == SHP.POINTM) {
105
                        buffer.getDouble();
106
                }
107

    
108
                if (m_type == SHP.POINT3D) {
109
                        z = buffer.getDouble();
110
                }
111

    
112
                return (Geometry) new Point2D(x, y);
113
        }
114

    
115
        /**
116
         * @see com.iver.cit.gvsig.fmap.shp.SHPShape#write(ByteBuffer, IGeometry)
117
         */
118
        public void write(IByteBuffer buffer, Geometry geometry) {
119
                // FPoint2D p2d = ((FPoint2D) geometry.getShape());
120
                // /obtainsPoints(geometry.getGeneralPathXIterator());
121
                buffer.putDouble(point.getX());
122
                buffer.putDouble(point.getY());
123

    
124
                if (m_type == SHP.POINT3D) {
125
                        if (Double.isNaN(z)) { // nan means not defined
126
                                buffer.putDouble(0.0);
127
                        } else {
128
                                buffer.putDouble(z);
129
                        }
130
                }
131
                if ((m_type == SHP.POINT3D) || (m_type == SHP.POINTM)) {
132
                        buffer.putDouble(-10E40); // M
133
                }
134

    
135
        }
136

    
137
        /**
138
         * @see com.iver.cit.gvsig.fmap.shp.SHPShape#getLength(int)
139
         */
140
        public int getLength(Geometry fgeometry) {
141
                int length;
142

    
143
                if (m_type == SHP.POINT2D) {
144
                        length = 20;
145
                } else if (m_type == SHP.POINTM) {
146
                        length = 28;
147
                } else if (m_type == SHP.POINT3D) {
148
                        length = 36;
149
                } else {
150
                        throw new IllegalStateException("Expected ShapeType of Point, got"
151
                                        + m_type);
152
                }
153

    
154
                return length;
155
        }
156

    
157
        /**
158
         * @see com.iver.cit.gvsig.fmap.drivers.shp.write.SHPShape#obtainsPoints(com.iver.cit.gvsig.fmap.core.GeneralPathXIterator)
159
         */
160
        public void obtainsPoints(Geometry g) {
161
                if (SHP.POINT3D == m_type) {
162
                        z = ((AbstractPrimitive) g).getZs()[0];
163
                }
164
                PathIterator theIterator = g.getPathIterator(null); // polyLine.getPathIterator(null,
165
                                                                                                                        // flatness);
166
                double[] theData = new double[6];
167

    
168
                while (!theIterator.isDone()) {
169
                        // while not done
170
                        int theType = theIterator.currentSegment(theData);
171

    
172
                        point = new Point2D(theData[0], theData[1]);
173

    
174
                        theIterator.next();
175
                } // end while loop
176
        }
177
        // public void setFlatness(double flatness) {
178
        // // this.flatness=flatness;
179
        // }
180
}