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 / BaseLine3DM.java @ 42392

History | View | Annotate | Download (5.13 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 com.vividsolutions.jts.geom.CoordinateSequence;
30

    
31
import org.gvsig.fmap.geom.Geometry;
32
import org.gvsig.fmap.geom.GeometryException;
33
import org.gvsig.fmap.geom.aggregate.MultiLine;
34
import org.gvsig.fmap.geom.aggregate.MultiPoint;
35
import org.gvsig.fmap.geom.aggregate.MultiPolygon;
36
import org.gvsig.fmap.geom.jts.MCoordinate;
37
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3DM;
38
import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3DM;
39
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3DM;
40
import org.gvsig.fmap.geom.jts.primitive.point.Point3D;
41
import org.gvsig.fmap.geom.jts.primitive.point.Point3DM;
42
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3DM;
43
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence;
44
import org.gvsig.fmap.geom.jts.util.JTSUtils;
45
import org.gvsig.fmap.geom.jts.util.ReadOnlyCoordinates;
46
import org.gvsig.fmap.geom.primitive.Point;
47

    
48

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

    
55
    /**
56
     *
57
     */
58
    private static final long serialVersionUID = 1765763899814153661L;
59

    
60
    /**
61
     * @param polygon
62
     * @param coordinates
63
     */
64
    public BaseLine3DM(int type, Coordinate[] coordinates) {
65
        super(type, Geometry.SUBTYPES.GEOM3DM);
66
        initializeCoordinates(coordinates);
67
    }
68

    
69
    /**
70
     * @param coordinates
71
     */
72
    private void initializeCoordinates(Coordinate[] coordinates) {
73
        this.coordinates = new ArrayListCoordinateSequence(new ReadOnlyCoordinates(coordinates));
74
    }
75

    
76
    /**
77
     * @param polygon
78
     */
79
    public BaseLine3DM(int type) {
80
        super(type, Geometry.SUBTYPES.GEOM3DM);
81
        this.coordinates = new ArrayListCoordinateSequence(new ArrayList<Coordinate>());
82
    }
83

    
84
    /* (non-Javadoc)
85
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double)
86
     */
87
    public void addVertex(double x, double y) {
88
        this.addVertex(x, y, 0);
89
    }
90

    
91
    /* (non-Javadoc)
92
     * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double, double)
93
     */
94
    public void addVertex(double x, double y, double z) {
95
        Point3DM point = new Point3DM(x, y, z, 0);
96
        this.addVertex(point);
97
    }
98

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

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

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

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

    
149

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