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 @ 42283
History | View | Annotate | Download (5.42 KB)
1 | 42260 | fdiaz | /* 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 | 42283 | fdiaz | import java.util.ArrayList; |
26 | 42269 | fdiaz | import java.util.Iterator; |
27 | |||
28 | 42260 | fdiaz | import com.vividsolutions.jts.geom.Coordinate; |
29 | |||
30 | import org.gvsig.fmap.geom.Geometry; |
||
31 | 42269 | fdiaz | 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.MultiPoint2DM; |
||
37 | import org.gvsig.fmap.geom.jts.aggregate.MultiPoint3D; |
||
38 | import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D; |
||
39 | 42267 | fdiaz | import org.gvsig.fmap.geom.jts.gputils.DefaultGeneralPathX; |
40 | 42283 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.Point2D; |
41 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.Point2DM; |
42 | 42260 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.Point3D; |
43 | import org.gvsig.fmap.geom.jts.primitive.point.Point3DM; |
||
44 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D; |
45 | 42267 | fdiaz | import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
46 | import org.gvsig.fmap.geom.jts.util.ReadOnlyCoordinates; |
||
47 | import org.gvsig.fmap.geom.primitive.GeneralPathX; |
||
48 | 42270 | fdiaz | import org.gvsig.fmap.geom.primitive.Line; |
49 | 42260 | fdiaz | import org.gvsig.fmap.geom.primitive.Point; |
50 | |||
51 | |||
52 | |||
53 | /**
|
||
54 | * @author fdiaz
|
||
55 | *
|
||
56 | */
|
||
57 | 42270 | fdiaz | public abstract class BaseLine3D extends AbstractLine { |
58 | 42260 | fdiaz | |
59 | /**
|
||
60 | *
|
||
61 | */
|
||
62 | private static final long serialVersionUID = -1886715977687661564L; |
||
63 | |||
64 | /**
|
||
65 | * @param subtype
|
||
66 | */
|
||
67 | 42270 | fdiaz | protected BaseLine3D() {
|
68 | 42260 | fdiaz | super(Geometry.SUBTYPES.GEOM3D);
|
69 | 42283 | fdiaz | this.coordinates = new ArrayListCoordinateSequence(new ArrayList<Coordinate>()); |
70 | 42260 | fdiaz | } |
71 | |||
72 | /**
|
||
73 | 42283 | fdiaz | * @param polygon
|
74 | */
|
||
75 | public BaseLine3D(int type) { |
||
76 | super(type, Geometry.SUBTYPES.GEOM3D);
|
||
77 | this.coordinates = new ArrayListCoordinateSequence(new ArrayList<Coordinate>()); |
||
78 | } |
||
79 | |||
80 | /**
|
||
81 | 42260 | fdiaz | *
|
82 | */
|
||
83 | 42270 | fdiaz | public BaseLine3D(Coordinate[] coordinates) { |
84 | 42260 | fdiaz | this();
|
85 | this.coordinates = new ArrayListCoordinateSequence(new ReadOnlyCoordinates(coordinates)); |
||
86 | 42267 | fdiaz | if(coordinates.length<1){ |
87 | anyVertex = new Point3D(0,0,0); |
||
88 | } else {
|
||
89 | anyVertex = new Point3D(coordinates[0].x, coordinates[0].y, coordinates[0].z); |
||
90 | } |
||
91 | 42260 | fdiaz | } |
92 | |||
93 | |||
94 | /* (non-Javadoc)
|
||
95 | * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double)
|
||
96 | */
|
||
97 | public void addVertex(double x, double y) { |
||
98 | 42267 | fdiaz | this.addVertex(new Point3D(x, y, 0)); |
99 | 42260 | fdiaz | } |
100 | |||
101 | /* (non-Javadoc)
|
||
102 | * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#addVertex(double, double, double)
|
||
103 | */
|
||
104 | public void addVertex(double x, double y, double z) { |
||
105 | 42267 | fdiaz | this.addVertex(new Point3D(x, y, z)); |
106 | 42260 | fdiaz | } |
107 | |||
108 | /* (non-Javadoc)
|
||
109 | * @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#fixPoint(org.gvsig.fmap.geom.primitive.Point)
|
||
110 | */
|
||
111 | @Override
|
||
112 | protected Point fixPoint(Point point) { |
||
113 | if (point instanceof Point3D) { |
||
114 | return point;
|
||
115 | } else if (point instanceof Point3DM) { |
||
116 | return new Point3D(point.getX(), point.getY(), ((Point3DM) point).getM()); |
||
117 | } else {
|
||
118 | return new Point3D(point.getX(), point.getY(), 0); |
||
119 | } |
||
120 | } |
||
121 | 42267 | fdiaz | |
122 | 42269 | fdiaz | /* (non-Javadoc)
|
123 | * @see org.gvsig.fmap.geom.primitive.Line#toPoints()
|
||
124 | */
|
||
125 | public MultiPoint toPoints() throws GeometryException { |
||
126 | MultiPoint multiPoint = new MultiPoint3D();
|
||
127 | 42271 | fdiaz | multiPoint.ensureCapacity(coordinates.size()); |
128 | for (Iterator<Coordinate> iterator = coordinates.iterator(); iterator.hasNext();) { |
||
129 | 42269 | fdiaz | Coordinate coordinate = (Coordinate) iterator.next(); |
130 | multiPoint.addPoint(new Point3D(coordinate));
|
||
131 | } |
||
132 | return multiPoint;
|
||
133 | } |
||
134 | |||
135 | /* (non-Javadoc)
|
||
136 | * @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
||
137 | */
|
||
138 | public MultiLine toLines() throws GeometryException { |
||
139 | MultiLine multiLine = new MultiLine3D();
|
||
140 | multiLine.addPrimitive(this);
|
||
141 | return multiLine;
|
||
142 | } |
||
143 | |||
144 | /* (non-Javadoc)
|
||
145 | * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
||
146 | */
|
||
147 | public MultiPolygon toPolygons() throws GeometryException { |
||
148 | MultiPolygon multiPolygon = new MultiPolygon3D();
|
||
149 | Polygon3D polygon = new Polygon3D(coordinates.toCoordinateArray());
|
||
150 | multiPolygon.addPrimitive(polygon); |
||
151 | return multiPolygon;
|
||
152 | } |
||
153 | 42283 | fdiaz | |
154 | |||
155 | /* (non-Javadoc)
|
||
156 | * @see org.gvsig.fmap.geom.primitive.OrientablePrimitive#getVertex(int)
|
||
157 | */
|
||
158 | public Point getVertex(int index) { |
||
159 | Point3D vertex = new Point3D(this.coordinates.get(index)); |
||
160 | anyVertex = vertex; |
||
161 | return vertex;
|
||
162 | } |
||
163 | 42260 | fdiaz | } |