root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / shp / write / SHPMultiPoint.java @ 24154
History | View | Annotate | Download (6.59 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 java.awt.geom.PathIterator; |
44 |
import java.awt.geom.Point2D; |
45 |
import java.awt.geom.Rectangle2D; |
46 |
import java.nio.ByteBuffer; |
47 |
import java.nio.MappedByteBuffer; |
48 |
import java.util.ArrayList; |
49 |
|
50 |
import com.iver.cit.gvsig.fmap.core.FMultiPoint2D; |
51 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
52 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
53 |
import com.iver.cit.gvsig.fmap.core.IGeometry3D; |
54 |
import com.iver.cit.gvsig.fmap.core.IGeometryM; |
55 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
56 |
import com.iver.cit.gvsig.fmap.drivers.shp.SHP; |
57 |
|
58 |
|
59 |
/**
|
60 |
* Elemento shape de tipo multipunto.
|
61 |
*
|
62 |
* @author Vicente Caballero Navarro
|
63 |
*/
|
64 |
public class SHPMultiPoint implements SHPShape { |
65 |
private int m_type; |
66 |
private int numpoints; |
67 |
private Point2D[] points; |
68 |
private double[] zs; |
69 |
|
70 |
/**
|
71 |
* Crea un nuevo SHPMultiPoint.
|
72 |
*/
|
73 |
public SHPMultiPoint() {
|
74 |
m_type = FConstant.SHAPE_TYPE_MULTIPOINT; |
75 |
} |
76 |
|
77 |
/**
|
78 |
* Crea un nuevo SHPMultiPoint.
|
79 |
*
|
80 |
* @param type Tipo de multipunto.
|
81 |
*
|
82 |
* @throws ShapefileException
|
83 |
*/
|
84 |
public SHPMultiPoint(int type) throws ShapefileException { |
85 |
if ((type != FConstant.SHAPE_TYPE_MULTIPOINT) &&
|
86 |
(type != FConstant.SHAPE_TYPE_MULTIPOINTM) && |
87 |
(type != FConstant.SHAPE_TYPE_MULTIPOINTZ)) { |
88 |
throw new ShapefileException("No es de tipo 8, 18, o 28"); |
89 |
} |
90 |
|
91 |
m_type = type; |
92 |
} |
93 |
|
94 |
/**
|
95 |
* Devuelve el tipo de multipoint en concreto.
|
96 |
*
|
97 |
* @return Tipo de multipoint.
|
98 |
*/
|
99 |
public int getShapeType() { |
100 |
return m_type;
|
101 |
} |
102 |
|
103 |
/**
|
104 |
* @see com.iver.cit.gvsig.fmap.shp.SHPShape#read(MappedByteBuffer, int)
|
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 |
* @see com.iver.cit.gvsig.fmap.shp.SHPShape#write(ByteBuffer, IGeometry)
|
134 |
*/
|
135 |
public void write(ByteBuffer buffer, IGeometry geometry) { |
136 |
// FMultiPoint2D mp = (FMultiPoint2D) geometry.getShape();
|
137 |
int p = buffer.position();
|
138 |
|
139 |
Rectangle2D box = geometry.getBounds2D();
|
140 |
buffer.putDouble(box.getMinX()); |
141 |
buffer.putDouble(box.getMinY()); |
142 |
buffer.putDouble(box.getMaxX()); |
143 |
buffer.putDouble(box.getMaxY()); |
144 |
///obtainsPoints(geometry.getGeneralPathXIterator());
|
145 |
buffer.putInt(numpoints); |
146 |
|
147 |
for (int t = 0, tt = numpoints; t < tt; t++) { |
148 |
Point2D point = points[t];
|
149 |
buffer.putDouble(point.getX()); |
150 |
buffer.putDouble(point.getY()); |
151 |
} |
152 |
|
153 |
if (m_type == FConstant.SHAPE_TYPE_MULTIPOINTZ) {
|
154 |
double[] zExtreame = SHP.getZMinMax(zs); |
155 |
if (Double.isNaN(zExtreame[0])) { |
156 |
buffer.putDouble(0.0);
|
157 |
buffer.putDouble(0.0);
|
158 |
} else {
|
159 |
buffer.putDouble(zExtreame[0]);
|
160 |
buffer.putDouble(zExtreame[1]);
|
161 |
} |
162 |
for (int t = 0; t < numpoints; t++) { |
163 |
double z = zs[t];
|
164 |
if (Double.isNaN(z)) { |
165 |
buffer.putDouble(0.0);
|
166 |
} else {
|
167 |
buffer.putDouble(z); |
168 |
} |
169 |
} |
170 |
} |
171 |
if (m_type == FConstant.SHAPE_TYPE_MULTIPOINTM){
|
172 |
buffer.putDouble(-10E40);
|
173 |
buffer.putDouble(-10E40);
|
174 |
double[] ms = ((IGeometryM)geometry).getMs(); |
175 |
for (int t = 0; t < numpoints; t++) { |
176 |
buffer.putDouble(ms[t]); |
177 |
} |
178 |
} |
179 |
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* @see com.iver.cit.gvsig.fmap.shp.SHPShape#getLength(com.iver.cit.gvsig.core.BasicShape.FGeometry)
|
184 |
*/
|
185 |
public int getLength(IGeometry fgeometry) { |
186 |
//FMultiPoint2D mp = (FMultiPoint2D) fgeometry.getShape();
|
187 |
///obtainsPoints(fgeometry.getGeneralPathXIterator());
|
188 |
|
189 |
int length;
|
190 |
|
191 |
if (m_type == FConstant.SHAPE_TYPE_MULTIPOINT) {
|
192 |
// two doubles per coord (16 * numgeoms) + 40 for header
|
193 |
length = (numpoints * 16) + 40; |
194 |
} else if (m_type == FConstant.SHAPE_TYPE_MULTIPOINTM) { |
195 |
// add the additional MMin, MMax for 16, then 8 per measure
|
196 |
length = (numpoints * 16) + 40 + 16 + (8 * numpoints); |
197 |
} else if (m_type == FConstant.SHAPE_TYPE_MULTIPOINTZ) { |
198 |
// add the additional ZMin,ZMax, plus 8 per Z
|
199 |
length = (numpoints * 16) + 40 + 16 + (8 * numpoints); |
200 |
} else {
|
201 |
throw new IllegalStateException("Expected ShapeType of Arc, got " + |
202 |
m_type); |
203 |
} |
204 |
|
205 |
return length;
|
206 |
} |
207 |
|
208 |
/**
|
209 |
* @see com.iver.cit.gvsig.fmap.drivers.shp.write.SHPShape#obtainsPoints(com.iver.cit.gvsig.fmap.core.GeneralPathXIterator)
|
210 |
*/
|
211 |
public void obtainsPoints(IGeometry g) { |
212 |
if (FConstant.SHAPE_TYPE_MULTIPOINTZ == m_type){
|
213 |
zs=((IGeometry3D)g).getZs(); |
214 |
} |
215 |
PathIterator theIterator = g.getPathIterator(null); //polyLine.getPathIterator(null, flatness); |
216 |
double[] theData = new double[6]; |
217 |
ArrayList ps=new ArrayList(); |
218 |
while (!theIterator.isDone()) {
|
219 |
//while not done
|
220 |
int theType = theIterator.currentSegment(theData);
|
221 |
|
222 |
ps.add(new Point2D.Double(theData[0], theData[1])); |
223 |
theIterator.next(); |
224 |
} //end while loop
|
225 |
points=(Point2D[])ps.toArray(new Point2D.Double[0]); |
226 |
numpoints=points.length; |
227 |
} |
228 |
// public void setFlatness(double flatness) {
|
229 |
// //this.flatness=flatness;
|
230 |
// }
|
231 |
} |