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

History | View | Annotate | Download (4.7 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.Geometry;
30
import org.gvsig.fmap.geom.GeometryLocator;
31
import org.gvsig.fmap.geom.GeometryManager;
32
import org.gvsig.fmap.geom.exception.CreateGeometryException;
33
import org.gvsig.fmap.geom.operation.GeometryOperationException;
34
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
35
import org.gvsig.fmap.geom.primitive.Curve;
36
import org.gvsig.fmap.geom.primitive.Point;
37

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

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

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

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

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

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

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

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

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

    
83
        return extendedLine;
84
    }
85

    
86
    @Override
87
    public Curve extendLine(Curve lineToExtend, Point insertedPoint, Geometry boundaryObject) throws GeometryOperationNotSupportedException, GeometryOperationException, DataException, CreateGeometryException {
88
        GeometryManager geoManager = GeometryLocator.getGeometryManager();
89
        int subtype = lineToExtend.getGeometryType().getSubType();
90
        Curve extendedLine = geoManager.createLine(subtype);
91

    
92
        Point startVertex = lineToExtend.getVertex(0);
93
        Point endVertex =
94
            lineToExtend.getVertex(lineToExtend.getNumVertices() - 1);
95

    
96
        Point startIntersectionPoint = null;
97
        Point endIntersectionPoint = null;
98
        if (insertedPoint.distance(startVertex) < insertedPoint
99
            .distance(endVertex)) {
100
            startIntersectionPoint =
101
                ExtendLineOperationUtils.curveIntersection(lineToExtend,
102
                    ExtendLineOperationUtils.START_SIDE, boundaryObject);
103

    
104
        } else {
105
            endIntersectionPoint =
106
                ExtendLineOperationUtils.curveIntersection(lineToExtend,
107
                    ExtendLineOperationUtils.END_SIDE, boundaryObject);
108
        }
109

    
110
        if (startIntersectionPoint != null) {
111
            extendedLine.addVertex(startIntersectionPoint);
112
        }
113

    
114
        for (int i = 0; i < lineToExtend.getNumVertices(); i++) {
115
            extendedLine.addVertex(lineToExtend.getVertex(i));
116
        }
117

    
118
        if (endIntersectionPoint != null) {
119
            extendedLine.addVertex(endIntersectionPoint);
120
        }
121

    
122
        return extendedLine;
123
    }
124
    
125
    
126
}