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.extendline / src / main / java / org / gvsig / vectorediting / lib / prov / extendline / operation / CurveExtendLineOperation.java @ 325

History | View | Annotate | Download (3.13 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright ? 2007-2015 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.extendline.operation;
26

    
27
import org.gvsig.fmap.dal.exception.DataException;
28
import org.gvsig.fmap.dal.feature.FeatureSelection;
29
import org.gvsig.fmap.geom.GeometryLocator;
30
import org.gvsig.fmap.geom.GeometryManager;
31
import org.gvsig.fmap.geom.exception.CreateGeometryException;
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.Point;
36

    
37
/**
38
 * @author llmarques
39
 *
40
 */
41
public class CurveExtendLineOperation implements ExtendLineOperation {
42

    
43
    public Curve extendLine(Curve lineToExtend, Point insertedPoint,
44
        FeatureSelection boundaryObjects)
45
        throws GeometryOperationNotSupportedException,
46
        GeometryOperationException, DataException, CreateGeometryException {
47

    
48
        GeometryManager geoManager = GeometryLocator.getGeometryManager();
49
        int subtype = lineToExtend.getGeometryType().getSubType();
50
        Curve extendedLine = geoManager.createLine(subtype);
51

    
52
        Point startVertex = lineToExtend.getVertex(0);
53
        Point endVertex =
54
            lineToExtend.getVertex(lineToExtend.getNumVertices() - 1);
55

    
56
        Point startIntersectionPoint = null;
57
        Point endIntersectionPoint = null;
58
        if (insertedPoint.distance(startVertex) < insertedPoint
59
            .distance(endVertex)) {
60
            startIntersectionPoint =
61
                ExtendLineOperationUtils.curveIntersection(lineToExtend,
62
                    ExtendLineOperationUtils.START_SIDE, boundaryObjects);
63

    
64
        } else {
65
            endIntersectionPoint =
66
                ExtendLineOperationUtils.curveIntersection(lineToExtend,
67
                    ExtendLineOperationUtils.END_SIDE, boundaryObjects);
68
        }
69

    
70
        if (startIntersectionPoint != null) {
71
            extendedLine.addVertex(startIntersectionPoint);
72
        }
73

    
74
        for (int i = 0; i < lineToExtend.getNumVertices(); i++) {
75
            extendedLine.addVertex(lineToExtend.getVertex(i));
76
        }
77

    
78
        if (endIntersectionPoint != null) {
79
            extendedLine.addVertex(endIntersectionPoint);
80
        }
81

    
82
        return extendedLine;
83
    }
84
}