gvsig-vectorediting / org.gvsig.vectorediting / trunk / org.gvsig.vectorediting / org.gvsig.vectorediting.lib / org.gvsig.vectorediting.lib.prov / org.gvsig.vectorediting.lib.prov.splitline / src / main / java / org / gvsig / vectorediting / lib / prov / splitline / operation / SplineSplitLineOperation.java @ 575
History | View | Annotate | Download (3.41 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright ? 2007-2014 gvSIG Association
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.vectorediting.lib.prov.splitline.operation; |
26 |
|
27 |
import org.gvsig.fmap.geom.Geometry; |
28 |
import org.gvsig.fmap.geom.GeometryException; |
29 |
import org.gvsig.fmap.geom.GeometryLocator; |
30 |
import org.gvsig.fmap.geom.GeometryManager; |
31 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
32 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
33 |
import org.gvsig.fmap.geom.primitive.Curve; |
34 |
import org.gvsig.fmap.geom.primitive.Line; |
35 |
import org.gvsig.fmap.geom.primitive.Point; |
36 |
import org.gvsig.fmap.geom.primitive.Spline; |
37 |
import org.gvsig.tools.locator.LocatorException; |
38 |
|
39 |
|
40 |
/**
|
41 |
* @author llmarques
|
42 |
*
|
43 |
*/
|
44 |
public class SplineSplitLineOperation implements SplitLineOperation { |
45 |
|
46 |
public Curve[] split(Geometry geometry, Point projectedPoint) |
47 |
throws LocatorException,
|
48 |
GeometryOperationNotSupportedException, GeometryOperationException, GeometryException { |
49 |
|
50 |
Spline splineToSplit = (Spline) geometry; |
51 |
Line lineToSplit = (Line) ((Spline) geometry).toLines().getPrimitiveAt(0); |
52 |
|
53 |
int subtype = geometry.getGeometryType().getSubType();
|
54 |
|
55 |
GeometryManager geoManager = GeometryLocator.getGeometryManager(); |
56 |
|
57 |
Spline splittedLine1 = |
58 |
(Spline) GeometryLocator.getGeometryManager().create(Geometry.TYPES.SPLINE, subtype); |
59 |
|
60 |
int index = 0; |
61 |
Point originalVertex = splineToSplit.getVertex(index);
|
62 |
int pointer = 0; |
63 |
for (; pointer < lineToSplit.getNumVertices() - 1; pointer++) { |
64 |
|
65 |
Point vertex = lineToSplit.getVertex(pointer);
|
66 |
if(vertex.equals(originalVertex)){
|
67 |
splittedLine1.addVertex(vertex); |
68 |
index++; |
69 |
originalVertex = splineToSplit.getVertex(index); |
70 |
} |
71 |
|
72 |
Curve segment = geoManager.createLine(subtype); |
73 |
segment.setPoints(lineToSplit.getVertex(pointer), |
74 |
lineToSplit.getVertex(pointer + 1));
|
75 |
|
76 |
if (SplitLineOperationUtils.intersects(segment, projectedPoint)) {
|
77 |
splittedLine1.addVertex(projectedPoint); |
78 |
pointer++; |
79 |
break;
|
80 |
} |
81 |
} |
82 |
|
83 |
Spline splittedLine2 = |
84 |
(Spline) GeometryLocator.getGeometryManager().create(Geometry.TYPES.SPLINE, subtype); |
85 |
splittedLine2.addVertex(projectedPoint); |
86 |
|
87 |
for (; index < splineToSplit.getNumVertices(); index++) {
|
88 |
splittedLine2.addVertex(splineToSplit.getVertex(index)); |
89 |
} |
90 |
|
91 |
return new Curve[] { splittedLine1, splittedLine2 }; |
92 |
|
93 |
|
94 |
} |
95 |
|
96 |
} |