Statistics
| Revision:

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 @ 2616

History | View | Annotate | Download (3.26 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.aggregate.MultiLine;
32
import org.gvsig.fmap.geom.operation.GeometryOperationException;
33
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
34
import org.gvsig.fmap.geom.primitive.Curve;
35
import org.gvsig.fmap.geom.primitive.Line;
36
import org.gvsig.fmap.geom.primitive.Point;
37
import org.gvsig.tools.locator.LocatorException;
38

    
39

    
40
/**
41
 * @author llmarques
42
 *
43
 */
44
public class CurveSplitLineOperation implements SplitLineOperation {
45

    
46
    @Override
47
    public Curve[] split(Geometry geometry, Point projectedPoint)
48
        throws LocatorException,
49
        GeometryOperationNotSupportedException, GeometryOperationException, GeometryException {
50

    
51
        Curve lineToSplit = (Curve) geometry;
52
        if(!(lineToSplit instanceof Line)){
53
            MultiLine lines = lineToSplit.toLines();
54
            if(lines != null && lines.getPrimitivesNumber()>0){
55
                lineToSplit = (Curve) lines.getPrimitiveAt(0);
56
            }
57
        }
58

    
59
        int subtype = geometry.getGeometryType().getSubType();
60

    
61
        GeometryManager geoManager = GeometryLocator.getGeometryManager();
62

    
63
        Curve splittedLine1 =
64
            GeometryLocator.getGeometryManager().createLine(subtype);
65

    
66
        int pointer = 0;
67
        for (; pointer < lineToSplit.getNumVertices() - 1; pointer++) {
68

    
69
            splittedLine1.addVertex(lineToSplit.getVertex(pointer));
70

    
71
            Curve segment = geoManager.createLine(subtype);
72
            segment.setPoints(lineToSplit.getVertex(pointer),
73
                lineToSplit.getVertex(pointer + 1));
74

    
75
            if (SplitLineOperationUtils.intersects(segment, projectedPoint)) {
76
                splittedLine1.addVertex(projectedPoint);
77
                pointer++;
78
                break;
79
            }
80
        }
81

    
82
        Curve splittedLine2 =
83
            GeometryLocator.getGeometryManager().createLine(subtype);
84
        splittedLine2.addVertex(projectedPoint);
85

    
86
        for (; pointer < lineToSplit.getNumVertices(); pointer++) {
87
            splittedLine2.addVertex(lineToSplit.getVertex(pointer));
88
        }
89

    
90
        return new Curve[] { splittedLine1, splittedLine2 };
91

    
92

    
93
    }
94

    
95
}