Revision 40423
branches/v2_0_0_prep/libraries/libFMap_dalfile/src/org/gvsig/fmap/dal/store/shp/utils/SHPMultiLine.java | ||
---|---|---|
46 | 46 |
import java.util.ArrayList; |
47 | 47 |
import java.util.List; |
48 | 48 |
|
49 |
import org.slf4j.Logger; |
|
50 |
import org.slf4j.LoggerFactory; |
|
51 |
|
|
52 | 49 |
import org.gvsig.fmap.geom.Geometry; |
50 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
51 |
import org.gvsig.fmap.geom.GeometryManager; |
|
53 | 52 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
54 | 53 |
import org.gvsig.fmap.geom.Geometry.TYPES; |
55 |
import org.gvsig.fmap.geom.GeometryLocator; |
|
56 |
import org.gvsig.fmap.geom.GeometryManager; |
|
57 | 54 |
import org.gvsig.fmap.geom.aggregate.MultiPrimitive; |
58 | 55 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
56 |
import org.gvsig.fmap.geom.primitive.Circle; |
|
59 | 57 |
import org.gvsig.fmap.geom.primitive.Curve; |
60 | 58 |
import org.gvsig.fmap.geom.primitive.Envelope; |
61 | 59 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
62 | 60 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
63 | 61 |
import org.gvsig.fmap.geom.primitive.Point; |
64 | 62 |
import org.gvsig.fmap.geom.primitive.Primitive; |
63 |
import org.slf4j.Logger; |
|
64 |
import org.slf4j.LoggerFactory; |
|
65 | 65 |
|
66 | 66 |
|
67 | 67 |
/** |
... | ... | |
270 | 270 |
* @see com.iver.cit.gvsig.fmap.shp.SHPShape#obtainsPoints(com.iver.cit.gvsig.fmap.core.GeneralPathXIterator) |
271 | 271 |
*/ |
272 | 272 |
public void obtainsPoints(Geometry g) { |
273 |
boolean is3D=false; |
|
274 |
if ((SHP.POLYLINE3D == m_type) || (SHP.POLYGON3D == m_type)){ |
|
275 |
OrientablePrimitive orientablePrimitive = (OrientablePrimitive)g; |
|
276 |
zs = new double[orientablePrimitive.getNumVertices()]; |
|
277 |
for (int i=0 ; i<zs.length ; i++){ |
|
278 |
zs[i] = orientablePrimitive.getCoordinateAt(i, 2); |
|
279 |
} |
|
280 |
is3D=true; |
|
281 |
} |
|
282 | 273 |
ArrayList arrayPoints = new ArrayList(); |
283 | 274 |
ArrayList arrayParts = new ArrayList(); |
284 | 275 |
ArrayList arrayZs = new ArrayList(); |
285 | 276 |
|
286 |
if (g.getGeometryType().isTypeOf(Geometry.TYPES.AGGREGATE)){ |
|
277 |
boolean is3D = false; |
|
278 |
if ((SHP.POLYLINE3D == m_type) || (SHP.POLYGON3D == m_type)) { |
|
279 |
if (g.getGeometryType().isTypeOf(Geometry.TYPES.AGGREGATE)) { |
|
280 |
MultiPrimitive multiPrimitive = (MultiPrimitive)g; |
|
281 |
int countVertex = 0; |
|
282 |
for (int i = 0; i < multiPrimitive.getPrimitivesNumber(); i++) { |
|
283 |
OrientablePrimitive orientablePrimitive = (OrientablePrimitive)multiPrimitive.getPrimitiveAt(i); |
|
284 |
countVertex += orientablePrimitive.getNumVertices(); |
|
285 |
} |
|
286 |
|
|
287 |
zs = new double[countVertex]; |
|
288 |
int indexZS = 0; |
|
289 |
for (int nPrimitive = 0; nPrimitive < multiPrimitive.getPrimitivesNumber(); nPrimitive++) { |
|
290 |
OrientablePrimitive orientablePrimitive = (OrientablePrimitive)multiPrimitive.getPrimitiveAt(nPrimitive); |
|
291 |
for (int nVertex = 0; nVertex < orientablePrimitive.getNumVertices(); nVertex++) { |
|
292 |
zs[indexZS] = orientablePrimitive.getCoordinateAt(nVertex, 2); |
|
293 |
} |
|
294 |
} |
|
295 |
} else { |
|
296 |
OrientablePrimitive orientablePrimitive = (OrientablePrimitive)g; |
|
297 |
zs = new double[orientablePrimitive.getNumVertices()]; |
|
298 |
for (int i = 0; i < zs.length; i++) { |
|
299 |
zs[i] = orientablePrimitive.getCoordinateAt(i, 2); |
|
300 |
} |
|
301 |
} |
|
302 |
is3D = true; |
|
303 |
} |
|
304 |
|
|
305 |
|
|
306 |
if (g.getGeometryType().isTypeOf(Geometry.TYPES.AGGREGATE)) { |
|
287 | 307 |
MultiPrimitive multiPrimitive = (MultiPrimitive)g; |
288 | 308 |
int index = 0; |
289 |
for (int i=0 ; i<multiPrimitive.getPrimitivesNumber() ; i++){ |
|
290 |
index = obtainsPoints(multiPrimitive.getPrimitiveAt(i), arrayPoints, arrayParts, arrayZs, is3D, index); |
|
309 |
for (int i = 0; i < multiPrimitive.getPrimitivesNumber(); i++) { |
|
310 |
index = obtainsPoints( |
|
311 |
multiPrimitive.getPrimitiveAt(i), |
|
312 |
arrayPoints, |
|
313 |
arrayParts, |
|
314 |
arrayZs, |
|
315 |
is3D, |
|
316 |
index); |
|
291 | 317 |
} |
292 | 318 |
}else{ |
293 | 319 |
obtainsPoints((Primitive)g, arrayPoints, arrayParts, arrayZs, is3D, 0); |
... | ... | |
298 | 324 |
for (int i = 0; i < integers.length; i++) { |
299 | 325 |
parts[i] = integers[i].intValue(); |
300 | 326 |
} |
301 |
if (arrayPoints==null){
|
|
327 |
if (arrayPoints == null) {
|
|
302 | 328 |
points = new Point[0]; |
303 | 329 |
return; |
304 | 330 |
} |
305 | 331 |
points = (Point[]) arrayPoints.toArray(new Point[0]); |
306 |
if (is3D){ |
|
332 |
|
|
333 |
if (is3D) { |
|
307 | 334 |
Double[] doubleZs = (Double[])arrayZs.toArray(new Double[0]); |
308 | 335 |
zs = new double[doubleZs.length]; |
309 |
for (int i=0;i<doubleZs.length;i++){
|
|
310 |
zs[i]=doubleZs[i].doubleValue();
|
|
336 |
for (int i = 0; i < doubleZs.length; i++){
|
|
337 |
zs[i] = doubleZs[i].doubleValue();
|
|
311 | 338 |
} |
312 | 339 |
} |
313 | 340 |
} |
314 | 341 |
|
315 |
private int obtainsPoints(Primitive primitive, List arrayPoints, List arrayParts, List arrayZs, boolean is3D, int index) {
|
|
316 |
PathIterator theIterator = primitive.getPathIterator(null, geomManager.getFlatness());
|
|
342 |
private int obtainsPoints(Primitive primitive, List arrayPoints, List arrayParts, List arrayZs, boolean is3D, int index) { |
|
343 |
PathIterator theIterator = primitive.getPathIterator(null, geomManager.getFlatness()); |
|
317 | 344 |
double[] theData = new double[6]; |
318 | 345 |
java.awt.geom.Point2D pFirst = null; |
319 |
int pos=0;
|
|
346 |
int pos = 0;
|
|
320 | 347 |
|
321 | 348 |
boolean first = true; |
322 | 349 |
|
... | ... | |
328 | 355 |
if (first) { |
329 | 356 |
first = false; |
330 | 357 |
} else { |
331 |
if (m_type==SHP.POLYGON2D ||
|
|
332 |
m_type==SHP.POLYGON3D ||
|
|
333 |
m_type==SHP.POLYGONM){
|
|
358 |
if (m_type == SHP.POLYGON2D ||
|
|
359 |
m_type == SHP.POLYGON3D ||
|
|
360 |
m_type == SHP.POLYGONM) {
|
|
334 | 361 |
try { |
335 | 362 |
Point point = geomManager.createPoint(pFirst.getX(), pFirst.getY(), SUBTYPES.GEOM2D); |
336 |
if (!arrayPoints.get(arrayPoints.size()-1).equals(point)){ |
|
363 |
if (!arrayPoints.get(arrayPoints.size()-1).equals(point)) {
|
|
337 | 364 |
arrayPoints.add(point); |
338 |
if (is3D){ |
|
365 |
if (is3D) {
|
|
339 | 366 |
arrayZs.add(firstZ); |
340 | 367 |
} |
341 | 368 |
} |
... | ... | |
351 | 378 |
} catch (CreateGeometryException e1) { |
352 | 379 |
logger.error("Error creating a point", e1); |
353 | 380 |
} |
354 |
if (is3D){ |
|
355 |
firstZ=new Double(zs[pos]); |
|
356 |
arrayZs.add(new Double(zs[pos])); |
|
381 |
if (is3D) { |
|
382 |
Double z = 0D; |
|
383 |
if(pos < zs.length) |
|
384 |
z = new Double(zs[pos]); |
|
385 |
firstZ = z; |
|
386 |
arrayZs.add(z); |
|
357 | 387 |
pos++; |
358 | 388 |
} |
359 | 389 |
break; |
... | ... | |
365 | 395 |
logger.error("Error creating a point", e); |
366 | 396 |
} |
367 | 397 |
if (is3D){ |
368 |
arrayZs.add(new Double(zs[pos])); |
|
398 |
Double z = 0D; |
|
399 |
if(pos < zs.length) |
|
400 |
z = new Double(zs[pos]); |
|
401 |
arrayZs.add(z); |
|
369 | 402 |
pos++; |
370 | 403 |
} |
371 | 404 |
break; |
... | ... | |
382 | 415 |
|
383 | 416 |
case PathIterator.SEG_CLOSE: |
384 | 417 |
try{ |
385 |
Point point=geomManager.createPoint(pFirst.getX(), pFirst.getY(), SUBTYPES.GEOM2D);
|
|
386 |
if (!arrayPoints.get(arrayPoints.size()-1).equals(point)){ |
|
418 |
Point point = geomManager.createPoint(pFirst.getX(), pFirst.getY(), SUBTYPES.GEOM2D);
|
|
419 |
if (!arrayPoints.get(arrayPoints.size()-1).equals(point)) {
|
|
387 | 420 |
arrayPoints.add(point); |
388 |
if (is3D){ |
|
421 |
if (is3D) {
|
|
389 | 422 |
arrayZs.add(firstZ); |
390 | 423 |
} |
424 |
index++; |
|
391 | 425 |
} |
392 | 426 |
} catch (CreateGeometryException e) { |
393 | 427 |
logger.error("Error creating a point", e); |
394 | 428 |
} |
395 | 429 |
break; |
396 | 430 |
} //end switch |
397 |
index++; |
|
431 |
if(theType != PathIterator.SEG_CLOSE) |
|
432 |
index++; |
|
398 | 433 |
theIterator.next(); |
399 | 434 |
} |
400 | 435 |
return index; |
Also available in: Unified diff