Revision 496
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/SplitEditingProvider.java | ||
---|---|---|
213 | 213 |
|
214 | 214 |
if (intersection == null |
215 | 215 |
|| (!intersection.getGeometryType().isTypeOf(POINT) |
216 |
&& !intersection.getGeometryType().isTypeOf(MULTIPOINT)
|
|
217 |
&& !intersection.getGeometryType().isTypeOf(CURVE)
|
|
218 |
&& !intersection.getGeometryType().isTypeOf(MULTICURVE))) {
|
|
216 |
&& !intersection.getGeometryType().isTypeOf(MULTIPOINT) |
|
217 |
&& !intersection.getGeometryType().isTypeOf(CURVE) |
|
218 |
&& !intersection.getGeometryType().isTypeOf(MULTICURVE))) { |
|
219 | 219 |
throw new VectorEditingException(); |
220 | 220 |
} |
221 | 221 |
} |
... | ... | |
225 | 225 |
return false; |
226 | 226 |
} |
227 | 227 |
} |
228 |
|
|
228 |
|
|
229 | 229 |
public Geometry finish() throws FinishServiceException { |
230 | 230 |
return null; |
231 | 231 |
} |
... | ... | |
311 | 311 |
} |
312 | 312 |
} |
313 | 313 |
|
314 |
// Not splitted geometries should be saved as multigeometry |
|
315 |
copyAlfanumericDataAndInsert(multiNoSplitted, |
|
316 |
feature); |
|
314 |
if(multiNoSplitted.getPrimitivesNumber() > 0){ |
|
315 |
// Not splitted geometries should be saved as multigeometry |
|
316 |
copyAlfanumericDataAndInsert(multiNoSplitted, |
|
317 |
feature); |
|
318 |
} |
|
317 | 319 |
} |
318 | 320 |
|
319 | 321 |
editingProviderServices.deleteFeatureFromFeatureStore( |
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 | ||
---|---|---|
78 | 78 |
return geometryToBeSplitted; |
79 | 79 |
} |
80 | 80 |
|
81 |
if (!firstVertex.equals(curveToBeSplitted.getVertex(0)) |
|
82 |
&& !lastVertex.equals(curveToBeSplitted.getVertex(0))) { |
|
81 |
if ((!firstVertex.equals(curveToBeSplitted.getVertex(0)) && !lastVertex |
|
82 |
.equals(curveToBeSplitted.getVertex(0))) |
|
83 |
&& isClosed(curveToBeSplitted)) { |
|
83 | 84 |
|
84 | 85 |
Curve firstCurve = difference.getCurveAt(0); |
85 | 86 |
Curve lastCurve = |
... | ... | |
104 | 105 |
for (int i = 1; i < difference.getPrimitivesNumber() - 1; i++) { |
105 | 106 |
multicurveSplitted.addCurve(difference.getCurveAt(i)); |
106 | 107 |
} |
107 |
} else { |
|
108 |
multicurveSplitted = difference; |
|
109 | 108 |
} |
110 | 109 |
} |
110 |
|
|
111 |
if(multicurveSplitted == null){ |
|
112 |
return geometryToBeSplitted.difference(splitter); |
|
113 |
} |
|
114 |
|
|
111 | 115 |
return multicurveSplitted; |
112 | 116 |
} |
117 |
|
|
118 |
private boolean isClosed(Curve curveToBeSplitted) { |
|
119 |
|
|
120 |
Point firstPoint = curveToBeSplitted.getVertex(0); |
|
121 |
Point lastPoint = |
|
122 |
curveToBeSplitted.getVertex(curveToBeSplitted.getNumVertices()-1); |
|
123 |
|
|
124 |
if (firstPoint.equals(lastPoint)) { |
|
125 |
return true; |
|
126 |
} |
|
127 |
return false; |
|
128 |
} |
|
113 | 129 |
} |
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/ArcSplitOperation.java | ||
---|---|---|
71 | 71 |
|
72 | 72 |
Arc arcToBeSplitted = (Arc) geometryToBeSplitted; |
73 | 73 |
|
74 |
MultiPoint intersections = |
|
75 |
(MultiPoint) arcToBeSplitted.intersection(splitter); |
|
74 |
Geometry intersections = arcToBeSplitted.intersection(splitter); |
|
76 | 75 |
|
77 | 76 |
if (intersections == null) { |
78 | 77 |
return geometryToBeSplitted; |
79 |
} |
|
78 |
} else if (intersections instanceof Point) { |
|
79 |
|
|
80 |
if(isClosed(arcToBeSplitted)){ // Closed arcs can be splitted by one point |
|
81 |
return arcToBeSplitted; |
|
82 |
} else { |
|
83 |
return arcToBeSplitted.difference(splitter); |
|
84 |
} |
|
85 |
|
|
86 |
|
|
87 |
} else if (intersections instanceof MultiPoint) { |
|
80 | 88 |
|
81 |
// Arc#getCenterPoint can return null if two points of arc are the same |
|
82 |
Point tmpCenter = arcToBeSplitted.getCenterPoint(); |
|
83 |
if (tmpCenter == null) { |
|
84 |
// If center is null, we use this "trick". Get center of arc |
|
85 |
// envelope. |
|
86 |
tmpCenter = |
|
87 |
SplitOperationUtils.createPoint(arcToBeSplitted.getEnvelope() |
|
88 |
.getCenter(0), arcToBeSplitted.getEnvelope().getCenter(1), |
|
89 |
subtype); |
|
90 |
} |
|
91 |
final Point center = tmpCenter; |
|
89 |
// Two or more intersection points |
|
90 |
MultiPoint multiIntersection = (MultiPoint) intersections; |
|
92 | 91 |
|
93 |
double radius = center.distance(arcToBeSplitted.getEndPoint()); |
|
92 |
// Arc#getCenterPoint can return null if two points of arc are the |
|
93 |
// same |
|
94 |
Point tmpCenter = arcToBeSplitted.getCenterPoint(); |
|
95 |
if (tmpCenter == null) { |
|
96 |
// If center is null, we use this "trick". Get center of arc |
|
97 |
// envelope. |
|
98 |
tmpCenter = |
|
99 |
SplitOperationUtils.createPoint(arcToBeSplitted |
|
100 |
.getEnvelope().getCenter(0), arcToBeSplitted |
|
101 |
.getEnvelope().getCenter(1), subtype); |
|
102 |
} |
|
103 |
final Point center = tmpCenter; |
|
94 | 104 |
|
95 |
// Order intersection points by angle to create arcs correctly |
|
96 |
List<Point> orderedIntersectionPoints = new ArrayList<Point>(); |
|
97 |
for (int i = 0; i < intersections.getPrimitivesNumber(); i++) { |
|
98 |
orderedIntersectionPoints.add(intersections.getPointAt(i)); |
|
99 |
} |
|
105 |
double radius = center.distance(arcToBeSplitted.getEndPoint()); |
|
100 | 106 |
|
101 |
// Sort by angle |
|
102 |
Collections.sort(orderedIntersectionPoints, new Comparator<Point>() { |
|
107 |
// Order intersection points by angle to create arcs correctly |
|
108 |
List<Point> orderedIntersectionPoints = new ArrayList<Point>(); |
|
109 |
for (int i = 0; i < multiIntersection.getPrimitivesNumber(); i++) { |
|
110 |
orderedIntersectionPoints.add(multiIntersection.getPointAt(i)); |
|
111 |
} |
|
103 | 112 |
|
104 |
public int compare(Point p1, Point p2) { |
|
105 |
double angle1 = 0; |
|
106 |
double angle2 = 0; |
|
107 |
try { |
|
108 |
angle1 = SplitOperationUtils.getAngle(center, p1); |
|
109 |
angle2 = SplitOperationUtils.getAngle(center, p2); |
|
110 |
} catch (BaseException e) { |
|
111 |
logger.warn("Problems getting angle between center and" |
|
112 |
+ " one intersection point"); |
|
113 |
return 0; |
|
113 |
// Sort by angle |
|
114 |
Collections.sort(orderedIntersectionPoints, |
|
115 |
new Comparator<Point>() { |
|
116 |
|
|
117 |
public int compare(Point p1, Point p2) { |
|
118 |
double angle1 = 0; |
|
119 |
double angle2 = 0; |
|
120 |
try { |
|
121 |
angle1 = SplitOperationUtils.getAngle(center, p1); |
|
122 |
angle2 = SplitOperationUtils.getAngle(center, p2); |
|
123 |
} catch (BaseException e) { |
|
124 |
logger |
|
125 |
.warn("Problems getting angle between center and" |
|
126 |
+ " one intersection point"); |
|
127 |
return 0; |
|
128 |
} |
|
129 |
return Double.compare(angle1, angle2); |
|
130 |
} |
|
131 |
}); |
|
132 |
|
|
133 |
MultiCurve splittedArcs = geoManager.createMultiCurve(subtype); |
|
134 |
|
|
135 |
for (int i = 0; i < orderedIntersectionPoints.size(); i++) { |
|
136 |
Point intersecctionPoint = orderedIntersectionPoints.get(i); |
|
137 |
Point nextIntersecctionPoint; |
|
138 |
|
|
139 |
if (i + 1 >= orderedIntersectionPoints.size()) { |
|
140 |
nextIntersecctionPoint = orderedIntersectionPoints.get(0); |
|
141 |
} else { |
|
142 |
nextIntersecctionPoint = |
|
143 |
orderedIntersectionPoints.get(i + 1); |
|
114 | 144 |
} |
115 |
return Double.compare(angle1, angle2); |
|
116 |
} |
|
117 |
}); |
|
118 | 145 |
|
119 |
MultiCurve splittedArcs = geoManager.createMultiCurve(subtype); |
|
146 |
double angle1 = |
|
147 |
SplitOperationUtils.getAngle(center, intersecctionPoint); |
|
148 |
double angle2 = |
|
149 |
SplitOperationUtils |
|
150 |
.getAngle(center, nextIntersecctionPoint); |
|
120 | 151 |
|
121 |
for (int i = 0; i < orderedIntersectionPoints.size(); i++) { |
|
122 |
Point intersecctionPoint = orderedIntersectionPoints.get(i); |
|
123 |
Point nextIntersecctionPoint; |
|
152 |
Arc arc = (Arc) geoManager.create(Geometry.TYPES.ARC, subtype); |
|
124 | 153 |
|
125 |
if (i + 1 >= orderedIntersectionPoints.size()) { |
|
126 |
nextIntersecctionPoint = orderedIntersectionPoints.get(0); |
|
127 |
} else { |
|
128 |
nextIntersecctionPoint = orderedIntersectionPoints.get(i + 1); |
|
154 |
arc.setPointsStartEnd(center, radius, angle1, angle2); |
|
155 |
splittedArcs.addCurve(arc); |
|
129 | 156 |
} |
130 | 157 |
|
131 |
double angle1 =
|
|
132 |
SplitOperationUtils.getAngle(center, intersecctionPoint);
|
|
133 |
double angle2 =
|
|
134 |
SplitOperationUtils.getAngle(center, nextIntersecctionPoint);
|
|
158 |
return splittedArcs;
|
|
159 |
}
|
|
160 |
return arcToBeSplitted;
|
|
161 |
}
|
|
135 | 162 |
|
136 |
Arc arc = (Arc) geoManager.create(Geometry.TYPES.ARC, subtype); |
|
137 |
|
|
138 |
arc.setPointsStartEnd(center, radius, angle1, angle2); |
|
139 |
splittedArcs.addCurve(arc); |
|
163 |
private boolean isClosed(Arc arc) { |
|
164 |
|
|
165 |
Point initPoint = arc.getInitPoint(); |
|
166 |
Point endPoint = arc.getEndPoint(); |
|
167 |
Point centerPoint = arc.getCenterPoint(); |
|
168 |
|
|
169 |
if(initPoint.equals(endPoint) || centerPoint == null){ |
|
170 |
return true; |
|
140 | 171 |
} |
141 |
|
|
142 |
return splittedArcs; |
|
172 |
return false; |
|
143 | 173 |
} |
144 | 174 |
} |
Also available in: Unified diff