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 @ 2616
History | View | Annotate | Download (3.42 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 |
@Override
|
47 |
public Curve[] split(Geometry geometry, Point projectedPoint) |
48 |
throws LocatorException,
|
49 |
GeometryOperationNotSupportedException, GeometryOperationException, GeometryException { |
50 |
|
51 |
Spline splineToSplit = (Spline) geometry; |
52 |
Line lineToSplit = (Line) ((Spline) geometry).toLines().getPrimitiveAt(0); |
53 |
|
54 |
int subtype = geometry.getGeometryType().getSubType();
|
55 |
|
56 |
GeometryManager geoManager = GeometryLocator.getGeometryManager(); |
57 |
|
58 |
Spline splittedLine1 = |
59 |
(Spline) GeometryLocator.getGeometryManager().create(Geometry.TYPES.SPLINE, subtype); |
60 |
|
61 |
int index = 0; |
62 |
Point originalVertex = splineToSplit.getVertex(index);
|
63 |
int pointer = 0; |
64 |
for (; pointer < lineToSplit.getNumVertices() - 1; pointer++) { |
65 |
|
66 |
Point vertex = lineToSplit.getVertex(pointer);
|
67 |
if(vertex.equals(originalVertex)){
|
68 |
splittedLine1.addVertex(vertex); |
69 |
index++; |
70 |
originalVertex = splineToSplit.getVertex(index); |
71 |
} |
72 |
|
73 |
Curve segment = geoManager.createLine(subtype); |
74 |
segment.setPoints(lineToSplit.getVertex(pointer), |
75 |
lineToSplit.getVertex(pointer + 1));
|
76 |
|
77 |
if (SplitLineOperationUtils.intersects(segment, projectedPoint)) {
|
78 |
splittedLine1.addVertex(projectedPoint); |
79 |
pointer++; |
80 |
break;
|
81 |
} |
82 |
} |
83 |
|
84 |
Spline splittedLine2 = |
85 |
(Spline) GeometryLocator.getGeometryManager().create(Geometry.TYPES.SPLINE, subtype); |
86 |
splittedLine2.addVertex(projectedPoint); |
87 |
|
88 |
for (; index < splineToSplit.getNumVertices(); index++) {
|
89 |
splittedLine2.addVertex(splineToSplit.getVertex(index)); |
90 |
} |
91 |
|
92 |
return new Curve[] { splittedLine1, splittedLine2 }; |
93 |
|
94 |
|
95 |
} |
96 |
|
97 |
} |