Revision 575 org.gvsig.vectorediting/trunk/org.gvsig.vectorediting/org.gvsig.vectorediting.lib/org.gvsig.vectorediting.lib.prov/org.gvsig.vectorediting.lib.prov.split/src/main/java/org/gvsig/vectorediting/lib/prov/split/operation/CurveSplitOperation.java
CurveSplitOperation.java | ||
---|---|---|
25 | 25 |
package org.gvsig.vectorediting.lib.prov.split.operation; |
26 | 26 |
|
27 | 27 |
import org.gvsig.fmap.geom.Geometry; |
28 |
import org.gvsig.fmap.geom.GeometryException; |
|
28 | 29 |
import org.gvsig.fmap.geom.GeometryLocator; |
29 | 30 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
30 | 31 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
31 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
|
32 | 32 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
33 | 33 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
34 | 34 |
import org.gvsig.fmap.geom.primitive.Curve; |
35 |
import org.gvsig.fmap.geom.primitive.Line; |
|
35 | 36 |
import org.gvsig.fmap.geom.primitive.Point; |
36 | 37 |
|
37 | 38 |
/** |
... | ... | |
42 | 43 |
|
43 | 44 |
/* |
44 | 45 |
* Strategy: |
45 |
*
|
|
46 |
* |
|
46 | 47 |
* 1. Get intersection points. |
47 | 48 |
* 2. Get difference between geometry and splitter. If splitter does not |
48 | 49 |
* touch geometry return original geometry. |
... | ... | |
57 | 58 |
*/ |
58 | 59 |
public Geometry split(Geometry geometryToBeSplitted, Geometry splitter) |
59 | 60 |
throws GeometryOperationNotSupportedException, |
60 |
GeometryOperationException, CreateGeometryException {
|
|
61 |
GeometryOperationException, GeometryException { |
|
61 | 62 |
|
62 |
Curve curveToBeSplitted = (Curve) geometryToBeSplitted; |
|
63 |
Curve curveToBeSplitted = (Curve) geometryToBeSplitted.cloneGeometry();
|
|
63 | 64 |
|
64 | 65 |
Geometry intersection = geometryToBeSplitted.intersection(splitter); |
65 | 66 |
MultiCurve multicurveSplitted = null; |
... | ... | |
77 | 78 |
if (difference == null) { |
78 | 79 |
return geometryToBeSplitted; |
79 | 80 |
} |
81 |
if(!(curveToBeSplitted instanceof Line)){ |
|
82 |
curveToBeSplitted = (Curve) curveToBeSplitted.toLines().getPrimitiveAt(0); |
|
83 |
} |
|
80 | 84 |
|
81 | 85 |
if ((!firstVertex.equals(curveToBeSplitted.getVertex(0)) && !lastVertex |
82 | 86 |
.equals(curveToBeSplitted.getVertex(0))) |
... | ... | |
107 | 111 |
} |
108 | 112 |
} |
109 | 113 |
} |
110 |
|
|
114 |
|
|
111 | 115 |
if(multicurveSplitted == null){ |
112 | 116 |
return geometryToBeSplitted.difference(splitter); |
113 | 117 |
} |
114 |
|
|
118 |
|
|
115 | 119 |
return multicurveSplitted; |
116 | 120 |
} |
117 | 121 |
|
118 | 122 |
private boolean isClosed(Curve curveToBeSplitted) { |
119 |
|
|
123 |
|
|
120 | 124 |
Point firstPoint = curveToBeSplitted.getVertex(0); |
121 | 125 |
Point lastPoint = |
122 | 126 |
curveToBeSplitted.getVertex(curveToBeSplitted.getNumVertices()-1); |
123 |
|
|
127 |
|
|
124 | 128 |
if (firstPoint.equals(lastPoint)) { |
125 | 129 |
return true; |
126 | 130 |
} |
Also available in: Unified diff