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 / CurveSplitLineOperation.java @ 575
History | View | Annotate | Download (3.08 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.tools.locator.LocatorException; |
37 |
|
38 |
|
39 |
/**
|
40 |
* @author llmarques
|
41 |
*
|
42 |
*/
|
43 |
public class CurveSplitLineOperation implements SplitLineOperation { |
44 |
|
45 |
public Curve[] split(Geometry geometry, Point projectedPoint) |
46 |
throws LocatorException,
|
47 |
GeometryOperationNotSupportedException, GeometryOperationException, GeometryException { |
48 |
|
49 |
Curve lineToSplit = (Curve) geometry; |
50 |
if(!(lineToSplit instanceof Line)){ |
51 |
lineToSplit = (Curve) lineToSplit.toLines().getPrimitiveAt(0);
|
52 |
} |
53 |
|
54 |
int subtype = geometry.getGeometryType().getSubType();
|
55 |
|
56 |
GeometryManager geoManager = GeometryLocator.getGeometryManager(); |
57 |
|
58 |
Curve splittedLine1 = |
59 |
GeometryLocator.getGeometryManager().createLine(subtype); |
60 |
|
61 |
int pointer = 0; |
62 |
for (; pointer < lineToSplit.getNumVertices() - 1; pointer++) { |
63 |
|
64 |
splittedLine1.addVertex(lineToSplit.getVertex(pointer)); |
65 |
|
66 |
Curve segment = geoManager.createLine(subtype); |
67 |
segment.setPoints(lineToSplit.getVertex(pointer), |
68 |
lineToSplit.getVertex(pointer + 1));
|
69 |
|
70 |
if (SplitLineOperationUtils.intersects(segment, projectedPoint)) {
|
71 |
splittedLine1.addVertex(projectedPoint); |
72 |
pointer++; |
73 |
break;
|
74 |
} |
75 |
} |
76 |
|
77 |
Curve splittedLine2 = |
78 |
GeometryLocator.getGeometryManager().createLine(subtype); |
79 |
splittedLine2.addVertex(projectedPoint); |
80 |
|
81 |
for (; pointer < lineToSplit.getNumVertices(); pointer++) {
|
82 |
splittedLine2.addVertex(lineToSplit.getVertex(pointer)); |
83 |
} |
84 |
|
85 |
return new Curve[] { splittedLine1, splittedLine2 }; |
86 |
|
87 |
|
88 |
} |
89 |
|
90 |
} |