svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.dal / org.gvsig.fmap.dal.file / org.gvsig.fmap.dal.file.shp / src / main / java / org / gvsig / fmap / dal / store / shp / utils / SHPReader3DM.java @ 42811
History | View | Annotate | Download (8.48 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2015 gvSIG Association
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.dal.store.shp.utils; |
24 |
|
25 |
import java.nio.ByteOrder; |
26 |
|
27 |
import org.gvsig.fmap.dal.exception.ReadException; |
28 |
import org.gvsig.fmap.dal.store.shp.SHPStoreParameters; |
29 |
import org.gvsig.fmap.geom.Geometry; |
30 |
import org.gvsig.fmap.geom.GeometryLocator; |
31 |
import org.gvsig.fmap.geom.GeometryManager; |
32 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
33 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
34 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
35 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
36 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
37 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
38 |
import org.gvsig.fmap.geom.primitive.Line; |
39 |
import org.gvsig.fmap.geom.primitive.Point; |
40 |
import org.gvsig.fmap.geom.primitive.Polygon; |
41 |
import org.gvsig.fmap.geom.primitive.Ring; |
42 |
import org.gvsig.utils.bigfile.BigByteBuffer2; |
43 |
|
44 |
|
45 |
/**
|
46 |
* @author fdiaz
|
47 |
*
|
48 |
*/
|
49 |
public class SHPReader3DM extends AbstractSHPReader { |
50 |
|
51 |
/**
|
52 |
*
|
53 |
*/
|
54 |
public SHPReader3DM(SHPStoreParameters params) {
|
55 |
super(params);
|
56 |
} |
57 |
|
58 |
/* (non-Javadoc)
|
59 |
* @see org.gvsig.fmap.dal.store.shp.utils.SHPReader#readPoint(org.gvsig.utils.bigfile.BigByteBuffer2)
|
60 |
*/
|
61 |
public Point readPoint(BigByteBuffer2 bb) throws CreateGeometryException { |
62 |
// bytes 1 to 4 are the type and have already been read.
|
63 |
// bytes 4 to 12 are the X coordinate
|
64 |
// bytes 13 to 20 are the Y coordinate
|
65 |
// bytes 21 to 28 are the Z coordinate
|
66 |
// bytes 29 to 36 are the M coordinate
|
67 |
GeometryManager gManager = GeometryLocator.getGeometryManager(); |
68 |
bb.order(ByteOrder.LITTLE_ENDIAN);
|
69 |
double x = bb.getDouble();
|
70 |
double y = bb.getDouble();
|
71 |
double z = bb.getDouble();
|
72 |
double m = bb.getDouble();
|
73 |
Point p = (Point) gManager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3DM); |
74 |
p.setX(x); |
75 |
p.setY(y); |
76 |
p.setCoordinateAt(Geometry.DIMENSIONS.Z, z); |
77 |
p.setCoordinateAt(p.getDimension()-1, m);
|
78 |
return p;
|
79 |
} |
80 |
|
81 |
/* (non-Javadoc)
|
82 |
* @see org.gvsig.fmap.dal.store.shp.utils.SHPReader#readPoLyline(org.gvsig.utils.bigfile.BigByteBuffer2)
|
83 |
*/
|
84 |
public Geometry readPoLyline(BigByteBuffer2 bb) throws CreateGeometryException, ReadException { |
85 |
|
86 |
GeometryManager gManager = GeometryLocator.getGeometryManager(); |
87 |
|
88 |
Point p = null; |
89 |
int numParts;
|
90 |
int numPoints;
|
91 |
int i;
|
92 |
int j;
|
93 |
|
94 |
bb.position(bb.position() + 32);
|
95 |
numParts = bb.getInt(); |
96 |
numPoints = bb.getInt(); |
97 |
|
98 |
int[] tempParts = new int[numParts]; |
99 |
|
100 |
MultiLine multiLine = null;
|
101 |
Line line = null; |
102 |
if (numParts > 1) { |
103 |
multiLine = (MultiLine) gManager.create(Geometry.TYPES.MULTILINE, Geometry.SUBTYPES.GEOM3DM); |
104 |
} |
105 |
|
106 |
for (i = 0; i < numParts; i++) { |
107 |
tempParts[i] = bb.getInt(); |
108 |
} |
109 |
|
110 |
j = 0;
|
111 |
|
112 |
for (i = 0; i < numPoints; i++) { |
113 |
p = (Point) gManager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3DM);
|
114 |
fillXY(p, bb); |
115 |
|
116 |
if (i == tempParts[j]) {
|
117 |
if(multiLine!=null && line != null){ |
118 |
multiLine.addCurve(line); |
119 |
} |
120 |
line = (Line) gManager.create(Geometry.TYPES.LINE, Geometry.SUBTYPES.GEOM3DM);
|
121 |
if (j < (numParts - 1)) { |
122 |
j++; |
123 |
} |
124 |
} |
125 |
line.addVertex(p); |
126 |
} |
127 |
if (multiLine != null) { |
128 |
multiLine.addCurve(line); |
129 |
fillZ(multiLine, bb); |
130 |
fillM(multiLine, bb); |
131 |
return multiLine;
|
132 |
} else {
|
133 |
fillZ(line, bb); |
134 |
fillM(line, bb); |
135 |
return line;
|
136 |
} |
137 |
} |
138 |
|
139 |
/* (non-Javadoc)
|
140 |
* @see org.gvsig.fmap.dal.store.shp.utils.SHPReader#readPoLygon(org.gvsig.utils.bigfile.BigByteBuffer2)
|
141 |
*/
|
142 |
public Geometry readPoLygon(BigByteBuffer2 bb) throws CreateGeometryException, GeometryOperationNotSupportedException, GeometryOperationException, ReadException { |
143 |
|
144 |
GeometryManager gManager = GeometryLocator.getGeometryManager(); |
145 |
|
146 |
Point p = null; |
147 |
int numParts;
|
148 |
int numPoints;
|
149 |
int i;
|
150 |
|
151 |
bb.position(bb.position() + 32);
|
152 |
numParts = bb.getInt(); |
153 |
numPoints = bb.getInt(); |
154 |
|
155 |
int[] tempParts = new int[numParts]; |
156 |
|
157 |
for (i = 0; i < numParts; i++) { |
158 |
tempParts[i] = bb.getInt(); |
159 |
} |
160 |
|
161 |
MultiPolygon multipolygon = null;
|
162 |
Polygon polygon = null; |
163 |
Ring ring = null;
|
164 |
|
165 |
int pointsCounter = 0; |
166 |
for(int part=0; part<numParts; part++){ |
167 |
ring = (Ring) gManager.create(Geometry.TYPES.RING, Geometry.SUBTYPES.GEOM3DM); |
168 |
int lastPoint = numPoints;
|
169 |
if(part<numParts-1){ |
170 |
lastPoint = tempParts[part+1];
|
171 |
} |
172 |
while(pointsCounter<lastPoint){
|
173 |
p = (Point) gManager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3DM);
|
174 |
fillXY(p, bb); |
175 |
ring.addVertex(p); |
176 |
pointsCounter++; |
177 |
} |
178 |
ring.closePrimitive(); |
179 |
checkNumVerticesOfRing(ring); |
180 |
if (ring.isCCW() && polygon!=null) { |
181 |
// Los anillos interiores deben ser CCW pero si encontramos un
|
182 |
// anillo interior que no est? envuelto en un pol?gono
|
183 |
// consideramos que es un pol?gono en s? y nos aseguramos de
|
184 |
// darle la vuelta (en el else)
|
185 |
//FIXME: Comprobar que este es el comportamiento deseado
|
186 |
polygon.addInteriorRing(ring); |
187 |
} else {
|
188 |
if(polygon!=null){ |
189 |
if(multipolygon==null){ |
190 |
multipolygon = (MultiPolygon) gManager.create(Geometry.TYPES.MULTIPOLYGON, Geometry.SUBTYPES.GEOM3DM); |
191 |
} |
192 |
multipolygon.addPrimitive(polygon); |
193 |
} |
194 |
polygon = (Polygon) gManager.create(Geometry.TYPES.POLYGON, Geometry.SUBTYPES.GEOM3DM);
|
195 |
polygon.ensureCapacity(ring.getNumVertices()); |
196 |
if(ring.isCCW()){
|
197 |
//To ensure CW orientation for polygons
|
198 |
for (int v = ring.getNumVertices()-1; v >=0; v--) { |
199 |
polygon.addVertex(ring.getVertex(v)); |
200 |
} |
201 |
} else {
|
202 |
for (int v = 0; v < ring.getNumVertices(); v++) { |
203 |
polygon.addVertex(ring.getVertex(v)); |
204 |
} |
205 |
} |
206 |
} |
207 |
} |
208 |
|
209 |
if (multipolygon != null) { |
210 |
multipolygon.addPrimitive(polygon); |
211 |
fillZ(multipolygon, bb); |
212 |
fillM(multipolygon, bb); |
213 |
return multipolygon;
|
214 |
} else {
|
215 |
fillZ(polygon, bb); |
216 |
fillM(polygon, bb); |
217 |
return polygon;
|
218 |
} |
219 |
} |
220 |
|
221 |
/* (non-Javadoc)
|
222 |
* @see org.gvsig.fmap.dal.store.shp.utils.SHPReader#readMultiPoint(org.gvsig.utils.bigfile.BigByteBuffer2)
|
223 |
*/
|
224 |
public Geometry readMultiPoint(BigByteBuffer2 bb) throws CreateGeometryException, ReadException { |
225 |
|
226 |
GeometryManager gManager = GeometryLocator.getGeometryManager(); |
227 |
|
228 |
int numPoints;
|
229 |
bb.position(bb.position() + 32);
|
230 |
numPoints = bb.getInt(); |
231 |
|
232 |
MultiPoint multipoint = gManager.createMultiPoint(Geometry.SUBTYPES.GEOM3DM); |
233 |
|
234 |
for (int i = 0; i < numPoints; i++) { |
235 |
Point point = (Point) gManager.create(Geometry.TYPES.POINT, Geometry.SUBTYPES.GEOM3DM); |
236 |
multipoint.addPoint(point); |
237 |
} |
238 |
|
239 |
fillZ(multipoint, bb); |
240 |
fillM(multipoint, bb); |
241 |
return multipoint;
|
242 |
} |
243 |
|
244 |
} |