root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / shp / write / SHPPoint.java @ 2196
History | View | Annotate | Download (4.48 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.FPoint2D; |
44 |
import com.iver.cit.gvsig.fmap.core.GeneralPathXIterator; |
45 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
46 |
import com.iver.cit.gvsig.fmap.core.IGeometry3D; |
47 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
48 |
|
49 |
import java.nio.ByteBuffer; |
50 |
import java.nio.MappedByteBuffer; |
51 |
|
52 |
|
53 |
/**
|
54 |
* DOCUMENT ME!
|
55 |
*
|
56 |
* @author Vicente Caballero Navarro
|
57 |
*/
|
58 |
public class SHPPoint implements SHPShape { |
59 |
private int m_type; |
60 |
private FPoint2D point;
|
61 |
private double z; |
62 |
|
63 |
/**
|
64 |
* Crea un nuevo SHPPoint.
|
65 |
*
|
66 |
* @param type DOCUMENT ME!
|
67 |
*
|
68 |
* @throws ShapefileException DOCUMENT ME!
|
69 |
*/
|
70 |
public SHPPoint(int type) throws ShapefileException { |
71 |
if ((type != FConstant.SHAPE_TYPE_POINT) &&
|
72 |
(type != FConstant.SHAPE_TYPE_POINTM) && |
73 |
(type != FConstant.SHAPE_TYPE_POINTZ)) { // 2d, 2d+m, 3d+m
|
74 |
throw new ShapefileException("No es un punto 1,11 ni 21"); |
75 |
} |
76 |
|
77 |
m_type = type; |
78 |
} |
79 |
|
80 |
/**
|
81 |
* Crea un nuevo SHPPoint.
|
82 |
*/
|
83 |
public SHPPoint() {
|
84 |
m_type = FConstant.SHAPE_TYPE_POINT; //2d
|
85 |
} |
86 |
|
87 |
/**
|
88 |
* @see com.iver.cit.gvsig.fmap.shp.SHPShape#getShapeType()
|
89 |
*/
|
90 |
public int getShapeType() { |
91 |
return m_type;
|
92 |
} |
93 |
|
94 |
/**
|
95 |
* @see com.iver.cit.gvsig.fmap.shp.SHPShape#read(MappedByteBuffer, int)
|
96 |
*/
|
97 |
public IGeometry read(MappedByteBuffer buffer, int type) { |
98 |
double x = buffer.getDouble();
|
99 |
double y = buffer.getDouble();
|
100 |
double z = Double.NaN; |
101 |
|
102 |
if (m_type == FConstant.SHAPE_TYPE_POINTM) {
|
103 |
buffer.getDouble(); |
104 |
} |
105 |
|
106 |
if (m_type == FConstant.SHAPE_TYPE_POINTZ) {
|
107 |
z = buffer.getDouble(); |
108 |
} |
109 |
|
110 |
return (IGeometry) new FPoint2D(x, y); |
111 |
} |
112 |
|
113 |
/**
|
114 |
* @see com.iver.cit.gvsig.fmap.shp.SHPShape#write(ByteBuffer, IGeometry)
|
115 |
*/
|
116 |
public void write(ByteBuffer buffer, IGeometry geometry) { |
117 |
//FPoint2D p2d = ((FPoint2D) geometry.getShape());
|
118 |
///obtainsPoints(geometry.getGeneralPathXIterator());
|
119 |
buffer.putDouble(point.getX()); |
120 |
buffer.putDouble(point.getY()); |
121 |
|
122 |
if (m_type == FConstant.SHAPE_TYPE_POINTZ) {
|
123 |
if (Double.isNaN(z)) { // nan means not defined |
124 |
buffer.putDouble(0.0);
|
125 |
} else {
|
126 |
buffer.putDouble(z); |
127 |
} |
128 |
} |
129 |
if ((m_type == FConstant.SHAPE_TYPE_POINTZ) ||
|
130 |
(m_type == FConstant.SHAPE_TYPE_POINTM)) { |
131 |
buffer.putDouble(-10E40); //M |
132 |
} |
133 |
|
134 |
} |
135 |
|
136 |
/**
|
137 |
* @see com.iver.cit.gvsig.fmap.shp.SHPShape#getLength(int)
|
138 |
*/
|
139 |
public int getLength(IGeometry fgeometry) { |
140 |
int length;
|
141 |
|
142 |
if (m_type == FConstant.SHAPE_TYPE_POINT) {
|
143 |
length = 20;
|
144 |
} else if (m_type == FConstant.SHAPE_TYPE_POINTM) { |
145 |
length = 28;
|
146 |
} else if (m_type == FConstant.SHAPE_TYPE_POINTZ) { |
147 |
length = 36;
|
148 |
} else {
|
149 |
throw new IllegalStateException("Expected ShapeType of Point, got" + |
150 |
m_type); |
151 |
} |
152 |
|
153 |
return length;
|
154 |
} |
155 |
|
156 |
/**
|
157 |
* @see com.iver.cit.gvsig.fmap.drivers.shp.write.SHPShape#obtainsPoints(com.iver.cit.gvsig.fmap.core.GeneralPathXIterator)
|
158 |
*/
|
159 |
public void obtainsPoints(IGeometry g) { |
160 |
if (FConstant.SHAPE_TYPE_POINTZ == m_type){
|
161 |
z=((IGeometry3D)g).getZs()[0];
|
162 |
} |
163 |
GeneralPathXIterator theIterator = g.getGeneralPathXIterator(); //polyLine.getPathIterator(null, flatness);
|
164 |
double[] theData = new double[6]; |
165 |
|
166 |
while (!theIterator.isDone()) {
|
167 |
//while not done
|
168 |
int theType = theIterator.currentSegment(theData);
|
169 |
|
170 |
point = new FPoint2D(theData[0], theData[1]); |
171 |
|
172 |
theIterator.next(); |
173 |
} //end while loop
|
174 |
} |
175 |
} |