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 / BaseLine2D.java @ 44612

History | View | Annotate | Download (5.31 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.ArrayList;
26
import java.util.Iterator;
27

    
28
import com.vividsolutions.jts.geom.Coordinate;
29
import java.awt.Shape;
30
import java.awt.geom.AffineTransform;
31

    
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.fmap.geom.GeometryException;
34
import org.gvsig.fmap.geom.aggregate.MultiLine;
35
import org.gvsig.fmap.geom.aggregate.MultiPoint;
36
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
37
import org.gvsig.fmap.geom.jts.aggregate.MultiLine2D;
38
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint2D;
39
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon2D;
40
import org.gvsig.fmap.geom.jts.primitive.point.Point2D;
41
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon2D;
42
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
43
import org.gvsig.fmap.geom.jts.util.ReadOnlyCoordinates;
44
import org.gvsig.fmap.geom.operation.GeometryOperationException;
45
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
46
import org.gvsig.fmap.geom.primitive.Point;
47

    
48
/**
49
 * @author fdiaz
50
 *
51
 */
52
public abstract class BaseLine2D extends AbstractLine {
53

    
54
    /**
55
     *
56
     */
57
    private static final long serialVersionUID = -4703049397260763325L;
58

    
59
    /**
60
     * @param polygon
61
     */
62
    public BaseLine2D(int type) {
63
        super(type, Geometry.SUBTYPES.GEOM2D);
64
        this.coordinates = new ArrayListCoordinateSequence(new ArrayList<Coordinate>());
65
    }
66

    
67
    /**
68
     * @param polygon
69
     * @param coordinates
70
     */
71
    public BaseLine2D(int type, Coordinate[] coordinates) {
72
        super(type, Geometry.SUBTYPES.GEOM2D);
73
        initializeCoordinates(coordinates);
74
    }
75

    
76
    public BaseLine2D(int type, ArrayListCoordinateSequence coordinates) {
77
        super(type, Geometry.SUBTYPES.GEOM2D);
78
        this.coordinates = coordinates;
79
    }
80

    
81
    /**
82
     * @param coordinates
83
     */
84
    private void initializeCoordinates(Coordinate[] coordinates) {
85
        this.coordinates = new ArrayListCoordinateSequence(new ReadOnlyCoordinates(coordinates));
86
    }
87

    
88
    /*
89
     * (non-Javadoc)
90
     *
91
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double,
92
     * double)
93
     */
94
    public void addVertex(double x, double y) {
95
        this.addVertex(new Point2D(x, y));
96
    }
97

    
98
    /*
99
     * (non-Javadoc)
100
     *
101
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double,
102
     * double, double)
103
     */
104
    public void addVertex(double x, double y, double z) {
105
        String message = "Can't add x,y,z coordinate to Line2D.";
106
        notifyDeprecated(message);
107
        throw new UnsupportedOperationException(message);
108
    }
109

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

    
127
    /* (non-Javadoc)
128
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
129
     */
130
    public MultiPoint toPoints() throws GeometryException {
131
        MultiPoint multiPoint = new MultiPoint2D();
132
        multiPoint.ensureCapacity(coordinates.size());
133
        for (Iterator<Coordinate> iterator = coordinates.iterator(); iterator.hasNext();) {
134
            Coordinate coordinate = (Coordinate) iterator.next();
135
            multiPoint.addPoint(new Point2D(this.getProjection(), coordinate));
136
        }
137
        return multiPoint;
138
    }
139

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

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

    
159

    
160
    /* (non-Javadoc)
161
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getVertex(int)
162
     */
163
    public Point getVertex(int index) {
164
        Point2D vertex = new Point2D(this.getProjection(), this.coordinates.get(index));
165
        return vertex;
166
    }
167
}