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 / BaseLine3D.java @ 42326

History | View | Annotate | Download (5.14 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

    
30
import org.gvsig.fmap.geom.Geometry;
31
import org.gvsig.fmap.geom.GeometryException;
32
import org.gvsig.fmap.geom.aggregate.MultiLine;
33
import org.gvsig.fmap.geom.aggregate.MultiPoint;
34
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
35
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D;
36
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3D;
37
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D;
38
import org.gvsig.fmap.geom.jts.primitive.point.Point3D;
39
import org.gvsig.fmap.geom.jts.primitive.point.Point3DM;
40
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D;
41
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
42
import org.gvsig.fmap.geom.jts.util.ReadOnlyCoordinates;
43
import org.gvsig.fmap.geom.primitive.Point;
44

    
45

    
46

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

    
53
    /**
54
     *
55
     */
56
    private static final long serialVersionUID = -1886715977687661564L;
57

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

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

    
75
    /**
76
     * @param coordinates
77
     */
78
    private void initializeCoordinates(Coordinate[] coordinates) {
79
        this.coordinates = new ArrayListCoordinateSequence(new ReadOnlyCoordinates(coordinates));
80
        if(coordinates.length<1){
81
            anyVertex = new Point3D(0,0,0);
82
        } else {
83
            anyVertex = new Point3D(coordinates[0].x, coordinates[0].y, coordinates[0].z);
84
        }
85
    }
86

    
87

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

    
95
    /* (non-Javadoc)
96
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double, double)
97
     */
98
    public void addVertex(double x, double y, double z) {
99
        this.addVertex(new Point3D(x, y, z));
100
    }
101

    
102
    /* (non-Javadoc)
103
     * @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org.gvsig.fmap.geom.primitive.Point)
104
     */
105
    @Override
106
    protected Point fixPoint(Point point) {
107
        if (point instanceof Point3D) {
108
            return point;
109
        } else if (point instanceof Point3DM) {
110
            return new Point3D(point.getX(), point.getY(), ((Point3DM) point).getM());
111
        } else {
112
            return new Point3D(point.getX(), point.getY(), 0);
113
        }
114
    }
115

    
116
    /* (non-Javadoc)
117
     * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
118
     */
119
    public MultiPoint toPoints() throws GeometryException {
120
        MultiPoint multiPoint = new MultiPoint3D();
121
        multiPoint.ensureCapacity(coordinates.size());
122
        for (Iterator<Coordinate> iterator = coordinates.iterator(); iterator.hasNext();) {
123
            Coordinate coordinate = (Coordinate) iterator.next();
124
            multiPoint.addPoint(new Point3D(coordinate));
125
        }
126
        return multiPoint;
127
    }
128

    
129
    /* (non-Javadoc)
130
     * @see org.gvsig.fmap.geom.primitive.Line#toLines()
131
     */
132
    public MultiLine toLines() throws GeometryException {
133
        MultiLine multiLine = new MultiLine3D();
134
        multiLine.addPrimitive(this);
135
        return multiLine;
136
    }
137

    
138
    /* (non-Javadoc)
139
     * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
140
     */
141
    public MultiPolygon toPolygons() throws GeometryException {
142
        MultiPolygon multiPolygon = new MultiPolygon3D();
143
        Polygon3D polygon = new Polygon3D(coordinates.toCoordinateArray());
144
        multiPolygon.addPrimitive(polygon);
145
        return multiPolygon;
146
    }
147

    
148

    
149
    /* (non-Javadoc)
150
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getVertex(int)
151
     */
152
    public Point getVertex(int index) {
153
        Point3D vertex = new Point3D(this.coordinates.get(index));
154
        anyVertex = vertex;
155
        return vertex;
156
    }
157
}
158