Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_dataFile / src / org / gvsig / fmap / data / feature / file / shp / utils / SHPPoint.java @ 22373

History | View | Annotate | Download (4.42 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.data.feature.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.fmap.geom.Geometry;
48
import org.gvsig.fmap.geom.primitive.AbstractPrimitive;
49
import org.gvsig.fmap.geom.primitive.Point2D;
50

    
51

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

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

    
76
                m_type = type;
77
        }
78

    
79
        /**
80
         * Crea un nuevo SHPPoint.
81
         */
82
        public SHPPoint() {
83
                m_type = SHP.POINT2D; //2d
84
        }
85

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

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

    
101
                if (m_type == SHP.POINTM) {
102
                        buffer.getDouble();
103
                }
104

    
105
                if (m_type == SHP.POINT3D) {
106
                        z = buffer.getDouble();
107
                }
108

    
109
                return (Geometry) new Point2D(x, y);
110
        }
111

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

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

    
133
        }
134

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

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

    
152
                return length;
153
        }
154

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

    
165
                while (!theIterator.isDone()) {
166
                        //while not done
167
                        int theType = theIterator.currentSegment(theData);
168

    
169
                        point = new Point2D(theData[0], theData[1]);
170

    
171
                        theIterator.next();
172
                } //end while loop
173
        }
174
//        public void setFlatness(double flatness) {
175
//        //        this.flatness=flatness;
176
//        }
177
}