Revision 42478 trunk/org.gvsig.desktop/org.gvsig.desktop.compat.cdc/org.gvsig.fmap.geometry/org.gvsig.fmap.geometry.jts/src/main/java/org/gvsig/fmap/geom/jts/operation/fromwkb/WKBParser3.java
WKBParser3.java | ||
---|---|---|
42 | 42 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
43 | 43 |
import org.gvsig.fmap.geom.primitive.Point; |
44 | 44 |
import org.gvsig.fmap.geom.primitive.Primitive; |
45 |
import org.gvsig.fmap.geom.primitive.Ring; |
|
45 | 46 |
import org.gvsig.fmap.geom.type.GeometryType; |
47 |
|
|
46 | 48 |
import org.slf4j.Logger; |
47 | 49 |
import org.slf4j.LoggerFactory; |
48 | 50 |
|
49 | 51 |
import com.vividsolutions.jts.io.WKBConstants; |
52 |
|
|
50 | 53 |
import org.gvsig.fmap.geom.primitive.Line; |
51 | 54 |
import org.gvsig.fmap.geom.primitive.Polygon; |
52 | 55 |
|
... | ... | |
100 | 103 |
* have neither call by reference nor multiple return values.) |
101 | 104 |
* |
102 | 105 |
* @param value |
103 |
* @return
|
|
106 |
* @return |
|
104 | 107 |
* @throws CreateGeometryException |
105 | 108 |
*/ |
106 | 109 |
public synchronized Geometry parse(byte[] value) throws CreateGeometryException { |
... | ... | |
113 | 116 |
* Parse a geometry starting at offset. |
114 | 117 |
* |
115 | 118 |
* @param data |
116 |
* @return
|
|
119 |
* @return |
|
117 | 120 |
* @throws CreateGeometryException |
118 | 121 |
*/ |
119 | 122 |
protected Geometry parseGeometry(ByteBuffer data) throws CreateGeometryException { |
... | ... | |
207 | 210 |
*/ |
208 | 211 |
private int getSubType(boolean haveZ, boolean haveM) { |
209 | 212 |
int subtype; |
210 |
|
|
213 |
|
|
211 | 214 |
if( haveZ ) { |
212 | 215 |
if( haveM ) { |
213 | 216 |
subtype = Geometry.SUBTYPES.GEOM3DM; |
... | ... | |
250 | 253 |
int subType = getSubType(gHaveZ, gHaveM); |
251 | 254 |
MultiPrimitive multipolygon = geomManager.createMultiPolygon(subType); |
252 | 255 |
|
253 |
Point point; |
|
254 | 256 |
for (int i = 0; i < count; i++) { |
255 | 257 |
Polygon polygon = geomManager.createPolygon(subType); |
256 | 258 |
parseTypeAndSRID(data); |
... | ... | |
260 | 262 |
if( nring==0 ) { |
261 | 263 |
ring = polygon; |
262 | 264 |
} else { |
263 |
ring = geomManager.createLine(subType);
|
|
265 |
ring = (Ring) geomManager.create(Geometry.TYPES.RING,subType);
|
|
264 | 266 |
} |
265 |
double[][] points = parsePointsAsDoubleArray(data, gHaveZ, gHaveM);
|
|
267 |
Point[] points = parsePointsAsPointsArray(data, gHaveZ, gHaveM);
|
|
266 | 268 |
|
267 |
ring.ensureCapacity(points.length); |
|
269 |
ring.ensureCapacity(points.length);
|
|
268 | 270 |
int lastPoint = points.length - 1; |
269 |
for (int k = 0; k < lastPoint; k++) { |
|
270 |
point = geomManager.createPoint(points[k][0], points[k][1], subType); |
|
271 |
if (gHaveZ) { |
|
272 |
point.setCoordinateAt(Geometry.DIMENSIONS.Z, points[0][2]); |
|
273 |
} |
|
274 |
if (gHaveM) { |
|
275 |
point.setCoordinateAt(point.getDimension()-1, points[0][3]); |
|
276 |
} |
|
277 |
ring.addVertex(point); |
|
271 |
for (int k = 0; k <= lastPoint; k++) { |
|
272 |
ring.addVertex(points[k]); |
|
278 | 273 |
} |
279 | 274 |
if( nring!=0 ) { |
280 |
polygon.addInteriorRing((Line) ring);
|
|
275 |
polygon.addInteriorRing((Ring)ring);
|
|
281 | 276 |
} |
282 | 277 |
} |
283 | 278 |
multipolygon.addPrimitive(polygon); |
... | ... | |
285 | 280 |
return multipolygon; |
286 | 281 |
} |
287 | 282 |
|
288 |
private double[][] parsePointsAsDoubleArray(ByteBuffer data, boolean haveZ,
|
|
289 |
boolean haveM) throws CreateGeometryException {
|
|
290 |
int count = data.getInt();
|
|
291 |
double points[][] = null;
|
|
292 |
int subtype = getSubType(haveZ, haveM);
|
|
283 |
private Point[] parsePointsAsPointsArray(ByteBuffer data, boolean haveZ,
|
|
284 |
boolean haveM) throws CreateGeometryException { |
|
285 |
int count = data.getInt(); |
|
286 |
Point points[] = new Point[count];
|
|
287 |
int subtype = getSubType(haveZ, haveM); |
|
293 | 288 |
|
289 |
for (int i = 0; i < count; i++) { |
|
290 |
points[i] = geomManager.createPoint(data.getDouble(), data.getDouble(), subtype); |
|
294 | 291 |
switch (subtype) { |
295 |
case Geometry.SUBTYPES.GEOM2D: |
|
296 |
points = new double[count][2]; |
|
297 |
break; |
|
298 | 292 |
case Geometry.SUBTYPES.GEOM3D: |
293 |
points[i].setCoordinateAt(Geometry.DIMENSIONS.Z, data.getDouble()); // z |
|
294 |
break; |
|
299 | 295 |
case Geometry.SUBTYPES.GEOM2DM: |
300 |
points = new double[count][3];
|
|
296 |
points[i].setCoordinateAt(points[i].getDimension()-1, data.getDouble()); // m
|
|
301 | 297 |
break; |
302 | 298 |
case Geometry.SUBTYPES.GEOM3DM: |
303 |
points = new double[count][4]; |
|
299 |
points[i].setCoordinateAt(Geometry.DIMENSIONS.Z, data.getDouble()); // z |
|
300 |
points[i].setCoordinateAt(points[i].getDimension()-1, data.getDouble()); // m |
|
304 | 301 |
break; |
305 | 302 |
default: |
306 | 303 |
break; |
307 | 304 |
} |
308 |
|
|
309 |
for (int i = 0; i < count; i++) { |
|
310 |
points[i][0] = data.getDouble(); // x |
|
311 |
points[i][1] = data.getDouble(); // y |
|
312 |
switch (subtype) { |
|
313 |
case Geometry.SUBTYPES.GEOM3D: |
|
314 |
case Geometry.SUBTYPES.GEOM2DM: |
|
315 |
points[i][2] = data.getDouble(); // z or m |
|
316 |
break; |
|
317 |
case Geometry.SUBTYPES.GEOM3DM: |
|
318 |
points[i][2] = data.getDouble(); // z |
|
319 |
points[i][3] = data.getDouble(); // m |
|
320 |
break; |
|
321 |
default: |
|
322 |
break; |
|
323 |
} |
|
324 |
//TODO: Remove when M be supported |
|
325 |
if (haveZ && haveM) { |
|
326 |
data.getDouble(); |
|
327 |
} |
|
328 |
} |
|
329 |
return points; |
|
330 | 305 |
} |
306 |
return points; |
|
307 |
} |
|
331 | 308 |
|
332 | 309 |
private MultiPrimitive parseCollection(ByteBuffer data) throws CreateGeometryException { |
333 | 310 |
int count = data.getInt(); |
... | ... | |
387 | 364 |
fillLinearRing(data, polygon, haveZ, haveM); |
388 | 365 |
|
389 | 366 |
for (int i = 1; i < count; i++) { |
390 |
Line ring = geomManager.createLine(subType);
|
|
367 |
Ring ring = (Ring) geomManager.create(Geometry.TYPES.RING, subType);
|
|
391 | 368 |
fillLinearRing(data, ring, haveZ, haveM); |
392 | 369 |
polygon.addInteriorRing(ring); |
393 | 370 |
} |
394 | 371 |
return polygon; |
395 | 372 |
} |
396 | 373 |
|
397 |
private void fillLinearRing(ByteBuffer data, OrientablePrimitive orientablePrimitive, boolean haveZ, boolean haveM) throws CreateGeometryException { |
|
374 |
private void fillLinearRing(ByteBuffer data, OrientablePrimitive ring, boolean haveZ, boolean haveM) |
|
375 |
throws CreateGeometryException { |
|
398 | 376 |
Point[] points = parsePointArray(data, haveZ, haveM); |
399 |
|
|
400 |
orientablePrimitive.ensureCapacity(points.length); |
|
401 | 377 |
int lastPoint = points.length - 1; |
402 |
for (int i = 0; i < lastPoint; i++) { |
|
403 |
orientablePrimitive.addVertex(points[i]); |
|
378 |
ring.ensureCapacity(points.length); |
|
379 |
for (int i = 0; i <= lastPoint; i++) { |
|
380 |
ring.addVertex(points[i]); |
|
404 | 381 |
} |
405 | 382 |
} |
406 | 383 |
|
Also available in: Unified diff