Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / primitive / curve / line / Line2D.java @ 42269

History | View | Annotate | Download (4.92 KB)

1
/* gvSIG. Desktop Geographic Information System.
2
 *
3
 * Copyright ? 2007-2015 gvSIG Association
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18
 * MA  02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us
21
 * at info AT gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.fmap.geom.jts.primitive.curve.line;
24

    
25
import java.util.Iterator;
26

    
27
import com.vividsolutions.jts.geom.Coordinate;
28

    
29
import org.gvsig.fmap.geom.Geometry;
30
import org.gvsig.fmap.geom.GeometryException;
31
import org.gvsig.fmap.geom.aggregate.MultiLine;
32
import org.gvsig.fmap.geom.aggregate.MultiPoint;
33
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
34
import org.gvsig.fmap.geom.jts.aggregate.MultiLine2D;
35
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint2D;
36
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon2D;
37
import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX;
38
import org.gvsig.fmap.geom.jts.primitive.point.Point2D;
39
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2D;
40
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
41
import org.gvsig.fmap.geom.jts.util.ReadOnlyCoordinates;
42
import org.gvsig.fmap.geom.primitive.GeneralPathX;
43
import org.gvsig.fmap.geom.primitive.Point;
44

    
45
/**
46
 * @author fdiaz
47
 *
48
 */
49
public class Line2D extends AbstractLine {
50

    
51
    /**
52
     *
53
     */
54
    private static final long serialVersionUID = -4703049397260763325L;
55

    
56
    /**
57
     * @param subtype
58
     */
59
    protected Line2D() {
60
        super(Geometry.SUBTYPES.GEOM2D);
61
    }
62

    
63
    /**
64
    *
65
    */
66
    public Line2D(Coordinate[] coordinates) {
67
        this();
68
        this.coordinates = new ArrayListCoordinateSequence(new ReadOnlyCoordinates(coordinates));
69
        if (coordinates.length < 1) {
70
            anyVertex = new Point2D(0, 0);
71
        } else {
72
            anyVertex = new Point2D(coordinates[0].x, coordinates[0].y);
73
        }
74
    }
75

    
76
    /*
77
     * (non-Javadoc)
78
     *
79
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double,
80
     * double)
81
     */
82
    public void addVertex(double x, double y) {
83
        this.addVertex(new Point2D(x, y));
84
    }
85

    
86
    /*
87
     * (non-Javadoc)
88
     *
89
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double,
90
     * double, double)
91
     */
92
    public void addVertex(double x, double y, double z) {
93
        String message = "Can't add x,y,z coordinate to Line2D.";
94
        notifyDeprecated(message);
95
        throw new UnsupportedOperationException(message);
96
    }
97

    
98
    /*
99
     * (non-Javadoc)
100
     *
101
     * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
102
     */
103
    public Geometry cloneGeometry() {
104
        return new Line2D((Coordinate[]) coordinates.clone());
105
    }
106

    
107
    /*
108
     * (non-Javadoc)
109
     *
110
     * @see
111
     * org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org
112
     * .gvsig.fmap.geom.primitive.Point)
113
     */
114
    @Override
115
    protected Point fixPoint(Point point) {
116
        if (point instanceof Point2D) {
117
            return point;
118
        } else {
119
            return new Point2D(point.getX(), point.getY());
120
        }
121
    }
122

    
123
    /*
124
     * (non-Javadoc)
125
     *
126
     * @see org.gvsig.fmap.geom.Geometry#getGeneralPath()
127
     */
128
    public GeneralPathX getGeneralPath() {
129
        return new DefaultGeneralPathX(new LineIterator(null), false, 0);
130
    }
131

    
132
    /* (non-Javadoc)
133
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
134
     */
135
    public MultiPoint toPoints() throws GeometryException {
136
        MultiPoint multiPoint = new MultiPoint2D();
137
        for (Iterator iterator = coordinates.iterator(); iterator.hasNext();) {
138
            Coordinate coordinate = (Coordinate) iterator.next();
139
            multiPoint.addPoint(new Point2D(coordinate));
140
        }
141
        return multiPoint;
142
    }
143

    
144
    /* (non-Javadoc)
145
     * @see org.gvsig.fmap.geom.primitive.Line#toLines()
146
     */
147
    public MultiLine toLines() throws GeometryException {
148
        MultiLine multiLine = new MultiLine2D();
149
        multiLine.addPrimitive(this);
150
        return multiLine;
151
    }
152

    
153
    /* (non-Javadoc)
154
     * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
155
     */
156
    public MultiPolygon toPolygons() throws GeometryException {
157
        MultiPolygon multiPolygon = new MultiPolygon2D();
158
        Polygon2D polygon = new Polygon2D(coordinates.toCoordinateArray());
159
        multiPolygon.addPrimitive(polygon);
160
        return multiPolygon;
161
    }
162
}